Skip to content

Fix dimension for empty wrapped quantity arrays - #226

Open
MilesCranmerBot wants to merge 4 commits into
JuliaPhysics:mainfrom
MilesCranmerBot:fix/issue-224-empty-quantityarray-dimension
Open

Fix dimension for empty wrapped quantity arrays#226
MilesCranmerBot wants to merge 4 commits into
JuliaPhysics:mainfrom
MilesCranmerBot:fix/issue-224-empty-quantityarray-dimension

Conversation

@MilesCranmerBot

Copy link
Copy Markdown
Contributor

Fixes #224.

This updates the generic quantity-array dimension method so an empty array wrapper can inherit dimensions from a quantity-bearing parent, instead of falling through to first. Direct empty QuantityArray values keep using their stored dimensions.

Verification:

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1.10)

Time benchmarks
main 8c4fde2... main / 8c4fde2...
Quantity/creation/Quantity(x) 3.13 ± 0.01 ns 3.13 ± 0.01 ns 1 ± 0.0045
Quantity/creation/Quantity(x, length=y) 3.49 ± 0.01 ns 3.49 ± 0.01 ns 1 ± 0.0041
Quantity/with_numbers/*real 4.18 ± 0.01 ns 3.14 ± 0.01 ns 1.33 ± 0.0053
Quantity/with_numbers/^int 8.39 ± 2.4 ns 8.39 ± 2.4 ns 1 ± 0.41
Quantity/with_numbers/^int * real 8.39 ± 2.8 ns 8.39 ± 2.8 ns 1 ± 0.47
Quantity/with_quantity/+y 4.13 ± 0.08 ns 4.16 ± 0.08 ns 0.993 ± 0.027
Quantity/with_quantity//y 3.5 ± 0.01 ns 3.5 ± 0.01 ns 1 ± 0.004
Quantity/with_self/dimension 3.13 ± 0.01 ns 3.13 ± 0.01 ns 1 ± 0.0045
Quantity/with_self/inv 3.48 ± 0.01 ns 3.48 ± 0.01 ns 1 ± 0.0041
Quantity/with_self/ustrip 3.13 ± 0.001 ns 3.13 ± 0.001 ns 1 ± 0.00045
QuantityArray/broadcasting/multi_array_of_quantities 0.151 ± 0.01 ms 0.151 ± 0.011 ms 0.999 ± 0.1
QuantityArray/broadcasting/multi_normal_array 0.0597 ± 0.0034 ms 0.063 ± 0.0035 ms 0.948 ± 0.075
QuantityArray/broadcasting/multi_quantity_array 0.173 ± 0.0017 ms 0.173 ± 0.0023 ms 1 ± 0.017
QuantityArray/broadcasting/x^2_array_of_quantities 25.6 ± 1.9 μs 25.5 ± 2.1 μs 1.01 ± 0.11
QuantityArray/broadcasting/x^2_normal_array 3.9 ± 0.39 μs 3.93 ± 0.43 μs 0.993 ± 0.15
QuantityArray/broadcasting/x^2_quantity_array 8.24 ± 0.33 μs 8.25 ± 0.34 μs 0.999 ± 0.057
QuantityArray/broadcasting/x^4_array_of_quantities 0.0871 ± 0.0015 ms 0.0868 ± 0.0015 ms 1 ± 0.024
QuantityArray/broadcasting/x^4_normal_array 0.0531 ± 0.0035 ms 0.0561 ± 0.00023 ms 0.946 ± 0.062
QuantityArray/broadcasting/x^4_quantity_array 0.053 ± 0.0035 ms 0.0562 ± 0.0034 ms 0.942 ± 0.083
time_to_load 0.208 ± 0.00042 s 0.209 ± 0.0012 s 0.996 ± 0.0062
Memory benchmarks
main 8c4fde2... main / 8c4fde2...
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

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
main 8c4fde2... main / 8c4fde2...
Quantity/creation/Quantity(x) 3.41 ± 0.01 ns 3.1 ± 0.01 ns 1.1 ± 0.0048
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.41 ± 0.01 ns 0.909 ± 0.004
Quantity/with_numbers/^int 12.1 ± 1 ns 12.1 ± 0.98 ns 1 ± 0.12
Quantity/with_numbers/^int * real 11.9 ± 0.99 ns 11.8 ± 0.95 ns 1.01 ± 0.12
Quantity/with_quantity/+y 4.04 ± 0.001 ns 4.04 ± 0.001 ns 1 ± 0.00035
Quantity/with_quantity//y 3.41 ± 0.01 ns 3.1 ± 0.01 ns 1.1 ± 0.0048
Quantity/with_self/dimension 2.79 ± 0.01 ns 3.1 ± 0.01 ns 0.9 ± 0.0043
Quantity/with_self/inv 3.11 ± 0.01 ns 3.41 ± 0.01 ns 0.912 ± 0.004
Quantity/with_self/ustrip 2.79 ± 0.01 ns 2.79 ± 0.01 ns 1 ± 0.0051
QuantityArray/broadcasting/multi_array_of_quantities 0.11 ± 0.0055 ms 0.113 ± 0.0065 ms 0.974 ± 0.075
QuantityArray/broadcasting/multi_normal_array 0.0471 ± 0.00023 ms 0.0471 ± 0.00023 ms 1 ± 0.0069
QuantityArray/broadcasting/multi_quantity_array 0.0501 ± 0.00058 ms 0.0501 ± 0.00042 ms 1 ± 0.014
QuantityArray/broadcasting/x^2_array_of_quantities 27.1 ± 11 μs 27.4 ± 10 μs 0.986 ± 0.54
QuantityArray/broadcasting/x^2_normal_array 2.58 ± 3.2 μs 2.77 ± 4.5 μs 0.928 ± 1.9
QuantityArray/broadcasting/x^2_quantity_array 6.56 ± 0.28 μs 4.45 ± 2 μs 1.48 ± 0.65
QuantityArray/broadcasting/x^4_array_of_quantities 0.0821 ± 0.0075 ms 0.0819 ± 0.005 ms 1 ± 0.11
QuantityArray/broadcasting/x^4_normal_array 0.0436 ± 0.00018 ms 0.0436 ± 0.00018 ms 0.999 ± 0.0059
QuantityArray/broadcasting/x^4_quantity_array 0.0437 ± 0.0002 ms 0.0468 ± 0.00025 ms 0.934 ± 0.0066
time_to_load 0.193 ± 0.0083 s 0.2 ± 0.0033 s 0.967 ± 0.044
Memory benchmarks
main 8c4fde2... main / 8c4fde2...
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.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (8f18f23) to head (8c4fde2).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #226   +/-   ##
=======================================
  Coverage   99.16%   99.17%           
=======================================
  Files          23       23           
  Lines        1320     1330   +10     
=======================================
+ Hits         1309     1319   +10     
  Misses         11       11           

☔ View full report in Codecov by Harness.
📢 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.

Comment thread src/utils.jl Outdated
Comment thread src/utils.jl
@MilesCranmer

Copy link
Copy Markdown
Member

@MilesCranmerBot please address comments above

@MilesCranmerBot

Copy link
Copy Markdown
Contributor Author

Addressed in MilesCranmerBot/DynamicQuantities.jl@e4ec781.

  • Removed the unreachable applicable(parent, aq) guard.
  • Added coverage for _parent_dimension(Quantity[]) === nothing.
  • Ran: JULIA_LOAD_PATH="$PWD/test:$PWD:@stdlib" /usr/local/bin/julia --project=test test/unittests.jl

MilesCranmerBot and others added 2 commits July 11, 2026 01:33
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
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.

dimension fetches fist item of AbstractArray even if empty

2 participants