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 4 commits into
base: main
Choose a base branch
from

Conversation

icweaver
Copy link

@icweaver icweaver commented May 31, 2025

Closes #166

To-do

  • docs

@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 2c27270... main / 2c27270...
Quantity/creation/Quantity(x) 3.71 ± 0.92 ns 2.79 ± 0.009 ns 1.33 ± 0.33
Quantity/creation/Quantity(x, length=y) 3.41 ± 0.01 ns 3.41 ± 0.01 ns 1 ± 0.0042
Quantity/with_numbers/*real 3.11 ± 0.001 ns 3.11 ± 0.01 ns 1 ± 0.0032
Quantity/with_numbers/^int 8.37 ± 2.5 ns 8.37 ± 2.5 ns 1 ± 0.42
Quantity/with_numbers/^int * real 8.05 ± 2.2 ns 8.05 ± 2.2 ns 1 ± 0.38
Quantity/with_quantity/+y 4.04 ± 0.001 ns 4.04 ± 0.001 ns 1 ± 0.00035
Quantity/with_quantity//y 3.11 ± 0.01 ns 3.11 ± 0.001 ns 1 ± 0.0032
Quantity/with_self/dimension 2.79 ± 0.009 ns 2.79 ± 0.009 ns 1 ± 0.0046
Quantity/with_self/inv 3.11 ± 0.01 ns 3.11 ± 0.001 ns 1 ± 0.0032
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.0014 ms 0.14 ± 0.0016 ms 1 ± 0.015
QuantityArray/broadcasting/multi_normal_array 0.0528 ± 0.003 ms 0.0527 ± 0.003 ms 1 ± 0.081
QuantityArray/broadcasting/multi_quantity_array 0.157 ± 0.00096 ms 0.157 ± 0.0009 ms 1 ± 0.0084
QuantityArray/broadcasting/x^2_array_of_quantities 23.8 ± 1.6 μs 23.9 ± 1.8 μs 0.996 ± 0.099
QuantityArray/broadcasting/x^2_normal_array 4.91 ± 0.63 μs 4.89 ± 0.68 μs 1 ± 0.19
QuantityArray/broadcasting/x^2_quantity_array 6.97 ± 0.35 μs 6.95 ± 0.36 μs 1 ± 0.073
QuantityArray/broadcasting/x^4_array_of_quantities 0.0847 ± 0.00061 ms 0.0847 ± 0.00054 ms 1 ± 0.0097
QuantityArray/broadcasting/x^4_normal_array 0.0469 ± 0.0031 ms 0.0496 ± 0.0031 ms 0.945 ± 0.086
QuantityArray/broadcasting/x^4_quantity_array 0.05 ± 0.0002 ms 0.0499 ± 0.00019 ms 1 ± 0.0055
time_to_load 0.189 ± 0.0015 s 0.188 ± 0.00089 s 1 ± 0.0094
Memory benchmarks
main 2c27270... main / 2c27270...
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 2c27270... main / 2c27270...
Quantity/creation/Quantity(x) 3.1 ± 0.01 ns 3.1 ± 0.01 ns 1 ± 0.0046
Quantity/creation/Quantity(x, length=y) 3.73 ± 0.01 ns 3.73 ± 0.01 ns 1 ± 0.0038
Quantity/with_numbers/*real 3.1 ± 0.01 ns 3.1 ± 0.01 ns 1 ± 0.0046
Quantity/with_numbers/^int 8.98 ± 2.2 ns 8.98 ± 2.2 ns 1 ± 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.001 ns 4.35 ± 0.001 ns 1 ± 0.00033
Quantity/with_quantity//y 3.42 ± 0.011 ns 3.42 ± 0.01 ns 1 ± 0.0044
Quantity/with_self/dimension 2.79 ± 0.001 ns 2.79 ± 0.009 ns 1 ± 0.0032
Quantity/with_self/inv 3.11 ± 0.01 ns 3.11 ± 0.01 ns 1 ± 0.0046
Quantity/with_self/ustrip 2.79 ± 0.01 ns 2.79 ± 0.01 ns 1 ± 0.0051
QuantityArray/broadcasting/multi_array_of_quantities 0.0904 ± 0.00082 ms 0.0907 ± 0.0055 ms 0.997 ± 0.061
QuantityArray/broadcasting/multi_normal_array 0.0498 ± 0.00035 ms 0.0498 ± 0.00025 ms 1 ± 0.0087
QuantityArray/broadcasting/multi_quantity_array 0.0592 ± 0.00034 ms 0.0591 ± 0.0062 ms 1 ± 0.1
QuantityArray/broadcasting/x^2_array_of_quantities 12.9 ± 2 μs 13.8 ± 2.1 μs 0.94 ± 0.2
QuantityArray/broadcasting/x^2_normal_array 2.27 ± 1.1 μs 2.06 ± 1.4 μs 1.1 ± 0.92
QuantityArray/broadcasting/x^2_quantity_array 3.48 ± 0.13 μs 3.46 ± 0.13 μs 1.01 ± 0.054
QuantityArray/broadcasting/x^4_array_of_quantities 0.0842 ± 0.00083 ms 0.0845 ± 0.0008 ms 0.996 ± 0.014
QuantityArray/broadcasting/x^4_normal_array 0.0466 ± 0.0002 ms 0.0466 ± 0.00015 ms 1 ± 0.0054
QuantityArray/broadcasting/x^4_quantity_array 0.0499 ± 0.00025 ms 0.0499 ± 0.00016 ms 1 ± 0.0059
time_to_load 0.198 ± 0.0046 s 0.2 ± 0.00089 s 0.991 ± 0.024
Memory benchmarks
main 2c27270... main / 2c27270...
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?

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
1 participant