Skip to content

QuantityArray convenience #166

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

Open
icweaver opened this issue Mar 9, 2025 · 3 comments · May be fixed by #178
Open

QuantityArray convenience #166

icweaver opened this issue Mar 9, 2025 · 3 comments · May be fixed by #178

Comments

@icweaver
Copy link

icweaver commented Mar 9, 2025

Hey again Miles. Sort of following up to your comment on Discourse, were you thinking of just having an extra method or two like:

Base.:*(A::AbstractArray, q::UnionAbstractQuantity) = QuantityArray(A, q)
Base.:*(q::UnionAbstractQuantity, A::AbstractArray) = A * q

so that things like this will work?

julia> (0:1.5:10)u"km"
7-element QuantityArray(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, ::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}):
    0.0 m
 1500.0 m
 3000.0 m
 4500.0 m
 6000.0 m
 7500.0 m
 9000.0 m

julia> u"km" * [3, 4, 5]
3-element QuantityArray(::Vector{Float64}, ::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}):
 3000.0 m
 4000.0 m
 5000.0 m

julia> [3, 4, 5] * u"km"
3-element QuantityArray(::Vector{Float64}, ::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}):
 3000.0 m
 4000.0 m
 5000.0 m

julia> [3, 4, 5] .* u"km" # Maintain original behavior
3-element Vector{Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}}:
 3000.0 m
 4000.0 m
 5000.0 m

Happy to get a quick PR going with some docs and tests if so!

@icweaver
Copy link
Author

Hi @MilesCranmer, after putting up #165, I was wondering if this might also be good for making plots internally?

I see that this would break a lot of the unit tests that assume that the return type is still a vector of quantities though. Should I update those too, or is this an indicator that I probably shouldn't be doing it this way 😅

@MilesCranmer
Copy link
Member

Hey, sorry I missed your original post!

Yes I think this would be useful. Which unit tests would break? I think those could be updated perhaps

@icweaver icweaver linked a pull request May 31, 2025 that will close this issue
1 task
@icweaver
Copy link
Author

No worries! Okie doke, here's a quick pass at it for your review 👍🏾 #178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants