SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
120 stars 15 forks source link

Make default parametric denominator of FixedRational `::Int64` #123

Closed MilesCranmer closed 3 months ago

MilesCranmer commented 3 months ago

This fixes a weird issue where the user would write out a quantity explicitly, like:

user_quantity = Quantity(10.0, Dimensions{FixedRational{Int32,25200}}(1, 0, 0, 0, 0, 0, 0))

and be surprised when this is not the same type as 10u"m". The reason for this is that FixedRational{Int32,25200}} != FixedRational{Int32,Int32(25200)}}!

So, this sets the default denominator to have Int64 type so that the user can write out an integer and not be surprised when it's a different type from the standard.

github-actions[bot] commented 3 months ago

Benchmark Results

main 37be60fd7daf91... main/37be60fd7daf91...
Quantity/creation/Quantity(x) 4.32 ± 0.92 ns 3.71 ± 0.92 ns 1.16
Quantity/creation/Quantity(x, length=y) 3.11 ± 0.01 ns 3.41 ± 0.01 ns 0.912
Quantity/with_numbers/*real 3.11 ± 0.01 ns 3.1 ± 0.01 ns 1
Quantity/with_numbers/^int 8.98 ± 2.2 ns 8.37 ± 2.2 ns 1.07
Quantity/with_numbers/^int * real 9.6 ± 2.2 ns 8.05 ± 1.9 ns 1.19
Quantity/with_quantity/+y 4.04 ± 0.001 ns 4.04 ± 0.001 ns 1
Quantity/with_quantity//y 3.42 ± 0.01 ns 3.11 ± 0.001 ns 1.1
Quantity/with_self/dimension 3.1 ± 0.01 ns 2.79 ± 0.009 ns 1.11
Quantity/with_self/inv 3.11 ± 0.001 ns 3.11 ± 0.001 ns 1
Quantity/with_self/ustrip 2.79 ± 0.01 ns 2.79 ± 0.01 ns 1
QuantityArray/broadcasting/multi_array_of_quantities 0.145 ± 0.0006 ms 0.15 ± 0.00092 ms 0.969
QuantityArray/broadcasting/multi_normal_array 0.0622 ± 0.00028 ms 0.0499 ± 0.00018 ms 1.25
QuantityArray/broadcasting/multi_quantity_array 0.155 ± 0.00084 ms 0.155 ± 0.00059 ms 1
QuantityArray/broadcasting/x^2_array_of_quantities 25.8 ± 2.8 μs 24.7 ± 2.3 μs 1.05
QuantityArray/broadcasting/x^2_normal_array 6.02 ± 0.54 μs 5.84 ± 0.62 μs 1.03
QuantityArray/broadcasting/x^2_quantity_array 6.96 ± 0.25 μs 7.04 ± 0.29 μs 0.989
QuantityArray/broadcasting/x^4_array_of_quantities 0.0788 ± 0.00071 ms 0.0788 ± 0.00059 ms 1
QuantityArray/broadcasting/x^4_normal_array 0.0561 ± 0.00021 ms 0.0499 ± 0.0002 ms 1.12
QuantityArray/broadcasting/x^4_quantity_array 0.0594 ± 0.003 ms 0.05 ± 0.0002 ms 1.19
time_to_load 0.134 ± 0.0029 s 0.128 ± 0.0028 s 1.05

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).