-
Notifications
You must be signed in to change notification settings - Fork 113
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
Way to ustrip an array efficiently #717
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
The easiest would be to add efficient methods for ranges (they can just call the broadcasting methods). Then, There is a proposal to apply the reinterpreting behavior to all In the discussion I also wondered whether it should be called
This is what I would expect when broadcasting, so I would not change it. |
I see, there are many different decisions and concerns that go into this issue! I also didn't find a straightforward builtin way to add units cheaply (that compiles to manual reinterpret for arrays + simple computation for ranges)... I guess will just go with julia> using Unitful, FlexiMaps, Accessors
# for arrays – lazy map (view of the original), effectively similar to reinterpret:
julia> mapview((@o _ * u"km"), [1, 2, 3])
3-element FlexiMaps.MappedArray{Quantity{Int64, 𝐋, Unitful.FreeUnits{(km,), 𝐋, nothing}}, 1, Base.Fix2{typeof(*), Unitful.FreeUnits{(km,), 𝐋, nothing}}, Vector{Int64}}:
1 km
2 km
3 km
julia> mapview(ustrip, [1,2,3]u"km")
3-element FlexiMaps.MappedArray{Int64, 1, typeof(ustrip), Vector{Quantity{Int64, 𝐋, Unitful.FreeUnits{(km,), 𝐋, nothing}}}}:
1
2
3
# for ranges – performs straightforward arithmetics:
julia> mapview((@o _ * u"km"), 1:3)
1 km:1 km:3 km
julia> mapview(ustrip, 1:3)
1:1:3 but would be nice to have something builtin. |
Looks like there is no single way to "ustrip all values in an array, as efficiently as possible".
ustrip(x)
: efficient forArray
(reinterprets), not efficient forrange
(materializes); also, deprecatedustrip.(x)
: efficient forrange
ofQuantities
(keeps a range), not efficient forrange
of regular numbers or forArray
(materializes/copies)Would be great to have such a way!
The text was updated successfully, but these errors were encountered: