-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disambiguate the meaning of one
#16116
Comments
Agreed, the multiplicative identity must always be unitless. |
I believe this change would break empty julia> Dates.Hour(5):Dates.Hour(1)
5 hours:1 hour:4 hours The last step of the range is calculated via |
I guess |
The trouble is that there are (at least) two meanings of |
See also Keno/SIUnits.jl#18 |
Maybe |
Also, |
This goes well beyond dates, so I'm adding a "decision" label here. I'm as guilty as anyone of being inconsistent about my use of With respect to |
This is actually really interesting - which is worse, a method error on I imagine it would be bad if we had I almost think of |
This might be a bit too far from the existing meaning, but |
I've been skimming over the packages that use @mbauman, |
How about |
Unfortunately they seem slightly ugly - I think keeping
is
This is a bit odd-ball, but I was meaning to play with (in a yet-to-exist |
I agree with the ugliness...but I worry that we need some kind of deprecation strategy since the return type of |
Quite true, though I would tend to say that following the behavior of the docstring is a bugfix (which has an effect on others), not a deprecation. A possible multi-cycle approach would be to introduce |
What are examples of types whose multiplicative identity isn't / shouldn't be One example that springs to mind is with matrices. |
|
@cstjean I think unit packages struggle with this, for an example I made up: So what should |
I have to confess I'm still struggling with what these two
So to sum up, IMHO I have the feeling we should agree on the doctrings of the generic functions first before bikeshedding their names... |
This is really interesting. Here's how I understand the points others made above:
If That covers most cases, but if
|
Folks have made some very good points.
So maybe the plan is to simply enhance the docstring for
The implication is that nothing resembling One advantage of this is that it becomes just a docstring change. |
(EDITED) Though worth pointing out that under this proposal, |
This isn't coming to a conclusion. I'll going to split it apart into separate issues/proposals and people can use thumbs-up/thumbs-down to vote. EDIT: note that you can vote on each separate comment; if you dislike one proposal but would be fine with either of the other two, you can give two thumbs up and one thumbs down. Topic 1: the behavior of
|
Proposal 1: Advantages:
Disadvantages:
|
Proposal 2: Advantages:
Disadvantages:
|
Proposal 3: Advantages:
Disadvantages:
|
Topic 2: defining the "additive generator," variously called There is considerable consensus that, if this function is defined at all,
|
Proposal 1: don't define a function for this, |
Proposal 2: call this function |
Proposal 3: call this function |
Proposal 4: call this function |
I'm not putting up a vote for functions that strip units and/or magnitudes for unitful quantities. Reason: that's not something that Base julia has to decide, authors of packages that handle units should feel free to decide that for themselves (or perhaps among other authors of unit-handling packages, if they want to seek a standard). |
Proposal 5: Advantages:
Disadvantages:
|
It should be noted that the Proposals 1 are incompatible. |
Regarding issue 1 proposal 2, I wouldn't get too caught up in the distinction between measurement precision and numerical precision. In the context of this discussion, I think it's numerical precision that matters. The numeric type underlying a Unitful quantity should follow the same promotion rules as the numeric types in Base. Otherwise, there wouldn't be a clean way to work with lower numerical-precision, unitful numbers, for which there are certainly applications. Given that, multiplying by |
|
Constructors can also "misbehave" - think |
@timholy Topic 2/Proposal 5: the multiplicative identity and generators should not be mixed, as reflected by everyone's voting. But I think you picked up on an earlier suggestion by me. Here's the proposal to use multiple dispatch which I think is compatible with every other suggestion: Proposal 5':
This would allow the unification of algebraic code for types with several operations, by allowing the user to specify the operation, and allows authors clear definitions without bikeshedding new function names. It is not breaking. |
This last possibility is about disambiguating scalar |
Just to flash an idea I've been pondering for a while... Topic 1/Proposal 4: Define |
@felixrehren, I agree that we could unify @andyferris I think having a special symbol By constrast, consider function assign_grade(rawgrade, studentname, curvefactor = one(rawgrade), behavior::Dict, feeling_generous::Bool)
multiplier = curvefactor
if behavior[studentname] == :good
multiplier *= 2
end
if feeling_generous
multiplier *= 3
end
rawgrade * multiplier
end Often the whole point of |
Well, I think I might be (clumsily) trying to make a similar point, especially with regards to your last sentence. I would say, given In your example I would suggest something like On the other hand, using such a |
A dimensionless |
Closed by #20268 |
According to docstring, `ones` creates an array of `T`, hence it should call `oneunit` rather than `one`. See JuliaLang#16116 and JuliaLang#20268.
It seems that this is incorrect:
The documentation of
one
says "Get the multiplicative identity element for the type of x". So the correct return would be Int64(1), since thenone(Dates.Second) * Dates.Second(5) == Dates.Second(5)
as expected. The current behaviour results in aMethodError
which is not desirable.If I did not miss something obvious, I could make a pull request.
The text was updated successfully, but these errors were encountered: