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 2 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 2feea5c... main / 2feea5c...
Quantity/creation/Quantity(x) 3.1 ± 0.01 ns 3.41 ± 0.01 ns 0.911 ± 0.004
Quantity/creation/Quantity(x, length=y) 3.11 ± 0.001 ns 3.11 ± 0.001 ns 1 ± 0.00046
Quantity/with_numbers/*real 3.1 ± 0.01 ns 3.1 ± 0.01 ns 1 ± 0.0046
Quantity/with_numbers/^int 8.05 ± 1.6 ns 7.43 ± 1.6 ns 1.08 ± 0.31
Quantity/with_numbers/^int * real 7.75 ± 1.6 ns 8.05 ± 1.6 ns 0.963 ± 0.27
Quantity/with_quantity/+y 4.04 ± 0.001 ns 4.04 ± 0.001 ns 1 ± 0.00035
Quantity/with_quantity//y 3.42 ± 0.011 ns 3.42 ± 0.011 ns 1 ± 0.0046
Quantity/with_self/dimension 3.1 ± 0.01 ns 3.1 ± 0.01 ns 1 ± 0.0046
Quantity/with_self/inv 3.42 ± 0.011 ns 3.11 ± 0.01 ns 1.1 ± 0.005
Quantity/with_self/ustrip 3.1 ± 0.01 ns 2.79 ± 0.01 ns 1.11 ± 0.0053
QuantityArray/broadcasting/multi_array_of_quantities 0.142 ± 0.0025 ms 0.145 ± 0.003 ms 0.978 ± 0.027
QuantityArray/broadcasting/multi_normal_array 0.0467 ± 0.00022 ms 0.0467 ± 0.0002 ms 1 ± 0.0064
QuantityArray/broadcasting/multi_quantity_array 0.155 ± 0.0015 ms 0.158 ± 0.00069 ms 0.981 ± 0.011
QuantityArray/broadcasting/x^2_array_of_quantities 24.9 ± 2.9 μs 24.9 ± 2.2 μs 0.998 ± 0.14
QuantityArray/broadcasting/x^2_normal_array 4.89 ± 0.92 μs 4.97 ± 0.94 μs 0.984 ± 0.26
QuantityArray/broadcasting/x^2_quantity_array 6.97 ± 0.32 μs 6.9 ± 0.31 μs 1.01 ± 0.065
QuantityArray/broadcasting/x^4_array_of_quantities 0.0789 ± 0.00084 ms 0.0788 ± 0.00058 ms 1 ± 0.013
QuantityArray/broadcasting/x^4_normal_array 0.0436 ± 0.00015 ms 0.0437 ± 0.00021 ms 0.997 ± 0.0059
QuantityArray/broadcasting/x^4_quantity_array 0.0437 ± 0.00017 ms 0.0438 ± 0.0002 ms 0.999 ± 0.006
time_to_load 0.192 ± 0.0028 s 0.189 ± 0.00093 s 1.01 ± 0.016
Memory benchmarks
main 2feea5c... main / 2feea5c...
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 2feea5c... main / 2feea5c...
Quantity/creation/Quantity(x) 3.13 ± 0.01 ns 3.1 ± 0.01 ns 1.01 ± 0.0046
Quantity/creation/Quantity(x, length=y) 3.43 ± 0.01 ns 3.43 ± 0.011 ns 1 ± 0.0043
Quantity/with_numbers/*real 3.11 ± 0.01 ns 3.11 ± 0.001 ns 1 ± 0.0032
Quantity/with_numbers/^int 8.37 ± 1.6 ns 8.37 ± 1.6 ns 1 ± 0.26
Quantity/with_numbers/^int * real 8.98 ± 1.6 ns 8.98 ± 1.6 ns 1 ± 0.25
Quantity/with_quantity/+y 4.35 ± 0.009 ns 4.35 ± 0.01 ns 1 ± 0.0031
Quantity/with_quantity//y 3.11 ± 0.001 ns 3.11 ± 0.001 ns 1 ± 0.00046
Quantity/with_self/dimension 3.1 ± 0.01 ns 3.1 ± 0.01 ns 1 ± 0.0046
Quantity/with_self/inv 3.11 ± 0.001 ns 3.11 ± 0.001 ns 1 ± 0.00046
Quantity/with_self/ustrip 2.79 ± 0.01 ns 2.79 ± 0.01 ns 1 ± 0.0051
QuantityArray/broadcasting/multi_array_of_quantities 0.0877 ± 0.0099 ms 0.0876 ± 0.00088 ms 1 ± 0.11
QuantityArray/broadcasting/multi_normal_array 0.0478 ± 0.0022 ms 0.0496 ± 0.0021 ms 0.962 ± 0.06
QuantityArray/broadcasting/multi_quantity_array 0.053 ± 0.00021 ms 0.053 ± 0.0002 ms 0.999 ± 0.0055
QuantityArray/broadcasting/x^2_array_of_quantities 14.8 ± 4.9 μs 14.9 ± 5.4 μs 0.991 ± 0.49
QuantityArray/broadcasting/x^2_normal_array 2.71 ± 2.8 μs 2.52 ± 2.6 μs 1.07 ± 1.6
QuantityArray/broadcasting/x^2_quantity_array 3.65 ± 0.61 μs 6.51 ± 0.13 μs 0.56 ± 0.094
QuantityArray/broadcasting/x^4_array_of_quantities 0.0814 ± 0.00062 ms 0.0815 ± 0.0011 ms 0.999 ± 0.016
QuantityArray/broadcasting/x^4_normal_array 0.0466 ± 0.00015 ms 0.0466 ± 0.00013 ms 1 ± 0.0043
QuantityArray/broadcasting/x^4_quantity_array 0.0467 ± 0.003 ms 0.0467 ± 0.00015 ms 0.999 ± 0.065
time_to_load 0.203 ± 0.0028 s 0.203 ± 0.0011 s 1 ± 0.015
Memory benchmarks
main 2feea5c... main / 2feea5c...
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?

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