Skip to content

Fix dimension for empty wrapped quantity arrays#226

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

Fix dimension for empty wrapped quantity arrays#226
MilesCranmerBot wants to merge 2 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 e4ec781... main / e4ec781...
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 3.14 ± 0.01 ns 3.15 ± 1 ns 1 ± 0.33
Quantity/with_numbers/^int 8.39 ± 2.4 ns 8.04 ± 2.4 ns 1.04 ± 0.44
Quantity/with_numbers/^int * real 8.39 ± 2.8 ns 8.39 ± 2.4 ns 1 ± 0.44
Quantity/with_quantity/+y 4.14 ± 0.031 ns 4.14 ± 0.069 ns 1 ± 0.018
Quantity/with_quantity//y 3.5 ± 0.01 ns 3.49 ± 0.01 ns 1 ± 0.0041
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.5 ± 0.01 ns 0.997 ± 0.004
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.152 ± 0.011 ms 0.999 ± 0.1
QuantityArray/broadcasting/multi_normal_array 0.0602 ± 0.0035 ms 0.0595 ± 0.0035 ms 1.01 ± 0.083
QuantityArray/broadcasting/multi_quantity_array 0.173 ± 0.001 ms 0.173 ± 0.0033 ms 1 ± 0.02
QuantityArray/broadcasting/x^2_array_of_quantities 26.9 ± 1.3 μs 26.5 ± 2.1 μs 1.01 ± 0.094
QuantityArray/broadcasting/x^2_normal_array 4.42 ± 0.5 μs 4.38 ± 0.45 μs 1.01 ± 0.15
QuantityArray/broadcasting/x^2_quantity_array 8.55 ± 0.34 μs 8.3 ± 0.51 μs 1.03 ± 0.075
QuantityArray/broadcasting/x^4_array_of_quantities 0.0884 ± 0.0014 ms 0.0882 ± 0.0026 ms 1 ± 0.034
QuantityArray/broadcasting/x^4_normal_array 0.0561 ± 0.0034 ms 0.0562 ± 0.00028 ms 0.998 ± 0.061
QuantityArray/broadcasting/x^4_quantity_array 0.0562 ± 0.0035 ms 0.0563 ± 0.0035 ms 0.999 ± 0.087
time_to_load 0.217 ± 0.0018 s 0.212 ± 0.0022 s 1.03 ± 0.014
Memory benchmarks
main e4ec781... main / e4ec781...
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 e4ec781... main / e4ec781...
Quantity/creation/Quantity(x) 3.14 ± 0.01 ns 3.48 ± 0.001 ns 0.902 ± 0.0029
Quantity/creation/Quantity(x, length=y) 3.48 ± 0.001 ns 3.48 ± 0.01 ns 1 ± 0.0029
Quantity/with_numbers/*real 3.13 ± 0.01 ns 3.14 ± 0.01 ns 0.997 ± 0.0045
Quantity/with_numbers/^int 13.3 ± 0.7 ns 13.3 ± 0.7 ns 1 ± 0.075
Quantity/with_numbers/^int * real 13.6 ± 1 ns 13.3 ± 1.1 ns 1.03 ± 0.11
Quantity/with_quantity/+y 4.26 ± 0.081 ns 4.14 ± 0.06 ns 1.03 ± 0.025
Quantity/with_quantity//y 3.48 ± 0.01 ns 3.49 ± 0.01 ns 1 ± 0.0041
Quantity/with_self/dimension 3.48 ± 0.01 ns 3.14 ± 0.01 ns 1.11 ± 0.0047
Quantity/with_self/inv 3.48 ± 0.01 ns 3.49 ± 0.01 ns 1 ± 0.0041
Quantity/with_self/ustrip 3.48 ± 0 ns 3.13 ± 0.001 ns 1.11 ± 0.00035
QuantityArray/broadcasting/multi_array_of_quantities 0.118 ± 0.007 ms 0.118 ± 0.0018 ms 1 ± 0.061
QuantityArray/broadcasting/multi_normal_array 0.056 ± 0.00026 ms 0.0525 ± 0.0035 ms 1.07 ± 0.071
QuantityArray/broadcasting/multi_quantity_array 0.0563 ± 0.00034 ms 0.0528 ± 0.0034 ms 1.07 ± 0.069
QuantityArray/broadcasting/x^2_array_of_quantities 28 ± 11 μs 27.9 ± 8.9 μs 1 ± 0.5
QuantityArray/broadcasting/x^2_normal_array 2.64 ± 2.2 μs 2.56 ± 1.8 μs 1.03 ± 1.1
QuantityArray/broadcasting/x^2_quantity_array 4.04 ± 2.7 μs 7.39 ± 0.53 μs 0.546 ± 0.37
QuantityArray/broadcasting/x^4_array_of_quantities 0.089 ± 0.0044 ms 0.0889 ± 0.0044 ms 1 ± 0.07
QuantityArray/broadcasting/x^4_normal_array 0.0491 ± 0.00037 ms 0.0491 ± 0.0035 ms 1 ± 0.072
QuantityArray/broadcasting/x^4_quantity_array 0.0527 ± 0.0035 ms 0.0492 ± 0.0035 ms 1.07 ± 0.1
time_to_load 0.188 ± 0.00063 s 0.19 ± 0.0012 s 0.992 ± 0.0073
Memory benchmarks
main e4ec781... main / e4ec781...
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

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.02%. Comparing base (8f18f23) to head (372fae1).

Files with missing lines Patch % Lines
src/utils.jl 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
- Coverage   99.16%   99.02%   -0.15%     
==========================================
  Files          23       23              
  Lines        1320     1331      +11     
==========================================
+ Hits         1309     1318       +9     
- Misses         11       13       +2     

☔ 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

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