Skip to content

Additional QuantityArray constructions #178

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
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

icweaver
Copy link

@icweaver icweaver commented May 31, 2025

Closes #166

To-do

@icweaver icweaver changed the title Additional QuantityArray constructions Additional QuantityArray constructions May 31, 2025
@icweaver icweaver marked this pull request as draft May 31, 2025 00:08
Copy link
Contributor

github-actions bot commented May 31, 2025

Benchmark Results (Julia v1.10)

Time benchmarks
main b27ec64... main / b27ec64...
Quantity/creation/Quantity(x) 2.79 ± 0.001 ns 2.79 ± 0.009 ns 1 ± 0.0032
Quantity/creation/Quantity(x, length=y) 3.41 ± 0.01 ns 3.41 ± 0.01 ns 1 ± 0.0042
Quantity/with_numbers/*real 3.1 ± 0.01 ns 3.11 ± 0.001 ns 1 ± 0.0032
Quantity/with_numbers/^int 8.37 ± 2.5 ns 8.05 ± 2.2 ns 1.04 ± 0.42
Quantity/with_numbers/^int * real 8.05 ± 2.2 ns 8.37 ± 1.9 ns 0.963 ± 0.34
Quantity/with_quantity/+y 4.04 ± 0.01 ns 4.04 ± 0.001 ns 1 ± 0.0025
Quantity/with_quantity//y 3.11 ± 0.01 ns 3.11 ± 0.01 ns 1 ± 0.0046
Quantity/with_self/dimension 2.79 ± 0.01 ns 3.11 ± 0.01 ns 0.9 ± 0.0043
Quantity/with_self/inv 3.11 ± 0.001 ns 3.11 ± 0 ns 1 ± 0.00032
Quantity/with_self/ustrip 2.79 ± 0.01 ns 2.79 ± 0.01 ns 1 ± 0.0051
QuantityArray/broadcasting/multi_array_of_quantities 0.14 ± 0.0027 ms 0.14 ± 0.0032 ms 0.999 ± 0.03
QuantityArray/broadcasting/multi_normal_array 0.0528 ± 0.0026 ms 0.0528 ± 0.003 ms 1 ± 0.076
QuantityArray/broadcasting/multi_quantity_array 0.158 ± 0.0017 ms 0.157 ± 0.00089 ms 1.01 ± 0.012
QuantityArray/broadcasting/x^2_array_of_quantities 22.5 ± 1.4 μs 22.4 ± 1.3 μs 1.01 ± 0.084
QuantityArray/broadcasting/x^2_normal_array 4.06 ± 0.67 μs 4.05 ± 0.74 μs 1 ± 0.25
QuantityArray/broadcasting/x^2_quantity_array 7.01 ± 0.27 μs 6.95 ± 0.32 μs 1.01 ± 0.061
QuantityArray/broadcasting/x^4_array_of_quantities 0.0845 ± 0.0006 ms 0.0816 ± 0.00083 ms 1.04 ± 0.013
QuantityArray/broadcasting/x^4_normal_array 0.0496 ± 0.0031 ms 0.0498 ± 0.00017 ms 0.997 ± 0.061
QuantityArray/broadcasting/x^4_quantity_array 0.0499 ± 0.00018 ms 0.0529 ± 0.0029 ms 0.943 ± 0.053
time_to_load 0.183 ± 0.001 s 0.19 ± 0.0012 s 0.965 ± 0.0081
Memory benchmarks
main b27ec64... main / b27ec64...
Quantity/creation/Quantity(x) 0 allocs: 0 B 0 allocs: 0 B
Quantity/creation/Quantity(x, length=y) 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/*real 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/^int 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/^int * real 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_quantity/+y 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_quantity//y 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/dimension 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/inv 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/ustrip 0 allocs: 0 B 0 allocs: 0 B
QuantityArray/broadcasting/multi_array_of_quantities 2 allocs: 0.382 MB 2 allocs: 0.382 MB 1
QuantityArray/broadcasting/multi_normal_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
QuantityArray/broadcasting/multi_quantity_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
QuantityArray/broadcasting/x^2_array_of_quantities 2 allocs: 0.382 MB 2 allocs: 0.382 MB 1
QuantityArray/broadcasting/x^2_normal_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
QuantityArray/broadcasting/x^2_quantity_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
QuantityArray/broadcasting/x^4_array_of_quantities 2 allocs: 0.382 MB 2 allocs: 0.382 MB 1
QuantityArray/broadcasting/x^4_normal_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
QuantityArray/broadcasting/x^4_quantity_array 2 allocs: 0.0763 MB 2 allocs: 0.0763 MB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

Copy link
Contributor

github-actions bot commented May 31, 2025

Benchmark Results (Julia v1)

Time benchmarks
main b27ec64... main / b27ec64...
Quantity/creation/Quantity(x) 3.1 ± 0.01 ns 2.8 ± 0.92 ns 1.11 ± 0.36
Quantity/creation/Quantity(x, length=y) 3.73 ± 0.01 ns 3.43 ± 0.01 ns 1.09 ± 0.0043
Quantity/with_numbers/*real 2.79 ± 0.001 ns 3.41 ± 0.01 ns 0.82 ± 0.0024
Quantity/with_numbers/^int 8.68 ± 2.2 ns 8.98 ± 2.2 ns 0.966 ± 0.34
Quantity/with_numbers/^int * real 9.29 ± 2.2 ns 9.29 ± 2.2 ns 1 ± 0.33
Quantity/with_quantity/+y 4.35 ± 0.01 ns 4.04 ± 0.01 ns 1.08 ± 0.0036
Quantity/with_quantity//y 3.42 ± 0.01 ns 3.11 ± 0.001 ns 1.1 ± 0.0032
Quantity/with_self/dimension 3.11 ± 0.001 ns 3.1 ± 0.01 ns 1 ± 0.0033
Quantity/with_self/inv 3.11 ± 0.01 ns 3.41 ± 0.01 ns 0.912 ± 0.004
Quantity/with_self/ustrip 4.02 ± 0.001 ns 2.79 ± 0.01 ns 1.44 ± 0.0052
QuantityArray/broadcasting/multi_array_of_quantities 0.0906 ± 0.0011 ms 0.0908 ± 0.0012 ms 0.998 ± 0.018
QuantityArray/broadcasting/multi_normal_array 0.0498 ± 0.00028 ms 0.0498 ± 0.00025 ms 1 ± 0.0076
QuantityArray/broadcasting/multi_quantity_array 0.0622 ± 0.0091 ms 0.0592 ± 0.00038 ms 1.05 ± 0.15
QuantityArray/broadcasting/x^2_array_of_quantities 13.5 ± 3.3 μs 15 ± 2.8 μs 0.901 ± 0.28
QuantityArray/broadcasting/x^2_normal_array 2.31 ± 1.6 μs 2.37 ± 2.2 μs 0.975 ± 1.1
QuantityArray/broadcasting/x^2_quantity_array 3.5 ± 0.21 μs 6.5 ± 0.081 μs 0.538 ± 0.033
QuantityArray/broadcasting/x^4_array_of_quantities 0.0845 ± 0.00076 ms 0.0875 ± 0.0011 ms 0.966 ± 0.015
QuantityArray/broadcasting/x^4_normal_array 0.0497 ± 0.00021 ms 0.0497 ± 0.00017 ms 0.999 ± 0.0054
QuantityArray/broadcasting/x^4_quantity_array 0.0468 ± 0.00022 ms 0.0499 ± 0.0002 ms 0.938 ± 0.0058
time_to_load 0.204 ± 0.0011 s 0.214 ± 0.0008 s 0.953 ± 0.0062
Memory benchmarks
main b27ec64... main / b27ec64...
Quantity/creation/Quantity(x) 0 allocs: 0 B 0 allocs: 0 B
Quantity/creation/Quantity(x, length=y) 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/*real 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/^int 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_numbers/^int * real 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_quantity/+y 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_quantity//y 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/dimension 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/inv 0 allocs: 0 B 0 allocs: 0 B
Quantity/with_self/ustrip 0 allocs: 0 B 0 allocs: 0 B
QuantityArray/broadcasting/multi_array_of_quantities 3 allocs: 0.382 MB 3 allocs: 0.382 MB 1
QuantityArray/broadcasting/multi_normal_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
QuantityArray/broadcasting/multi_quantity_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
QuantityArray/broadcasting/x^2_array_of_quantities 3 allocs: 0.382 MB 3 allocs: 0.382 MB 1
QuantityArray/broadcasting/x^2_normal_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
QuantityArray/broadcasting/x^2_quantity_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
QuantityArray/broadcasting/x^4_array_of_quantities 3 allocs: 0.382 MB 3 allocs: 0.382 MB 1
QuantityArray/broadcasting/x^4_normal_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
QuantityArray/broadcasting/x^4_quantity_array 3 allocs: 0.0764 MB 3 allocs: 0.0764 MB 1
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

@icweaver icweaver marked this pull request as ready for review June 3, 2025 20:36
@icweaver
Copy link
Author

icweaver commented Jun 3, 2025

Hi @MilesCranmer, this PR should be ready for your review now. Two follow-up questions I had were:

  1. Do we also want to add methods for creating QuantityArrays from generators? I just went with the types defined in ABSTRACT_QUANTITY_TYPES for now
    const ABSTRACT_QUANTITY_TYPES = (
    (AbstractQuantity, Number, Quantity),
    (AbstractGenericQuantity, Any, GenericQuantity),
    (AbstractRealQuantity, Real, RealQuantity)
    )
  2. Did you also want the assorted examples docs for QuantityArray updated, or would you prefer just keeping the explicit QuantityArray(<blah>) constructions there as-is?

@icweaver
Copy link
Author

icweaver commented Jul 10, 2025

Sweet, looks like this is working nicely with the new Makie PR:

julia> using CairoMakie, DynamicQuantities

julia> x = [6, 7, 8]us"cm"
3-element QuantityArray(::Vector{Float64}, ::Quantity{Float64, SymbolicDimensions{FixedRational{Int32, 25200}}}):
 6.0 cm
 7.0 cm
 8.0 cm

julia> y = (4:6)u"kg"
3-element QuantityArray(::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, ::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}):
 4.0 kg
 5.0 kg
 6.0 kg

julia> scatter(x, y)
display

@icweaver
Copy link
Author

  1. Did you also want the assorted examples docs for QuantityArray updated, or would you prefer just keeping the explicit QuantityArray() constructions there as-is?

Actually, think I found a good balance, just pushed. Does this look alright to you?

Copy link
Member

@MilesCranmer MilesCranmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for this and sorry for the delay. I only had a couple requests

@MilesCranmer
Copy link
Member

Also re: your question, I think creating from generators is probably too much for now.

icweaver and others added 5 commits July 14, 2025 11:16
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@icweaver
Copy link
Author

Thanks Miles! Sorry for the mix-up with the README and generated index file; I think things have been straightened out now.

In the process, I think I noticed that the HTML table of contents does not work as intended on my end at least, I think due to the case-sensitivity of the section headers. I'd be happy to open up a separate PR for this and maybe exploring the preprocessing step you mentioned for README code blocks if you think that would be useful

@MilesCranmer
Copy link
Member

Sure! Sounds great, thanks

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.62%. Comparing base (b209b7c) to head (12b20d2).

Files with missing lines Patch % Lines
src/math.jl 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
- Coverage   99.21%   95.62%   -3.60%     
==========================================
  Files          21       20       -1     
  Lines        1273     1211      -62     
==========================================
- Hits         1263     1158     -105     
- Misses         10       53      +43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@icweaver
Copy link
Author

icweaver commented Jul 15, 2025

Added a to-do for the method ambiguities picked up by Aqua

Note to self, related reading:

@icweaver
Copy link
Author

Hi @MilesCranmer, definitely not the most elegant, but I think the remaining method ambiguities have been addressed now and that this PR is ready for another review

@icweaver icweaver requested a review from MilesCranmer August 2, 2025 18:46
@MilesCranmer
Copy link
Member

Sorry is the Dates extension new? I don’t think I noticed that before. Could you put the Dates.jl extension in a separate PR please? Sorry for not mentioning earlier, I didn’t notice

Copy link

codecov bot commented Aug 2, 2025

Codecov Report

❌ Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@b209b7c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/math.jl 25.00% 6 Missing ⚠️
ext/DynamicQuantitiesLinearAlgebraExt.jl 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #178   +/-   ##
=======================================
  Coverage        ?   94.99%           
=======================================
  Files           ?       20           
  Lines           ?     1219           
  Branches        ?        0           
=======================================
  Hits            ?     1158           
  Misses          ?       61           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Documenter = "1"

[sources]
DynamicQuantities = {path = ".."}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DynamicQuantities doesn’t need to be specified here. (Also ideally this would go in a separate PR if possible, since it’s unrelated to the QuantityArray stuff)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep, that snuck in by mistake, my bad. Looking forward to it being included in Abhro's PR =]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MilesCranmer
Copy link
Member

Hm I think the test coverage CI should fail, I think the repo change means codecov isn’t aware of the current coverage

@icweaver
Copy link
Author

icweaver commented Aug 2, 2025

Sorry is the Dates extension new? I don’t think I noticed that before. Could you put the Dates.jl extension in a separate PR please? Sorry for not mentioning earlier, I didn’t notice

Yep, I introduced it in 096ca12 while playing method ambiguity whac-a-mole with Aqua. sg, will split into its own PR

Updated: Started #181

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 this pull request may close these issues.

QuantityArray convenience
2 participants