- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
ones
should call oneunit
#23544
ones
should call oneunit
#23544
Conversation
Overload for `ones` might not be necessary if JuliaLang/julia#23544 is accepted.
test/arrayops.jl
Outdated
val::Int16 | ||
end | ||
Base.one(::Type{OnesUsesOneunit}) = OnesUsesOneunit(1).val | ||
Base.zero(::Type{OnesUsesOneunit}) = OnesUsesOneunit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of defining your own type here, just use the Furlong
type from tests/dimensionful.jl
, which is there precisely to add tests for dimension bugs.
According to docstring, `ones` creates an array of `T`, hence it should call `oneunit` rather than `one`. See JuliaLang#16116 and JuliaLang#20268.
3f33207
to
6fdbda3
Compare
Thanks for the pointer to |
I'm not entirely sure about this. What's the algebraic / logical motivation for |
Is there any benefit to having Conducting a quick search reveals that most uses of |
To me Obviously, there is scope for confusion between |
I'm suspicious of the |
In practice, creating a multidimensional array with units is useful in Physics for any number of cases. Currently, it fails because we are creating an array of one type and filling it with another: julia> ones(Furlong{1, Int64}, 2, 3, 4)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Furlong{1,Int64}
This may have arisen from a call to the constructor Furlong{1,Int64}(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] fill!(::Array{Furlong{1,Int64},3}, ::Int64) at ./multidimensional.jl:788
[2] ones(::Type{T} where T, ::Int64, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./array.jl:265 |
Could you give a specific case you have in mind? |
It could be a constant potential, for instance. |
What advantage is there over |
Fair enough. But then why not just deprecate |
|
Looks to me like the conclusion is this PR is not needed, and that |
According to docstring,
ones
creates an array ofT
, hence it should calloneunit
rather thanone
. See #16116 and #20268.This PR requests makes the following call successful:
Another option would be to add
oneunits
to Base?