SymbolicML / DynamicQuantities.jl

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

Clean up type utilities: `constructorof`, `with_type_parameters`, `dimension_names` #72

Closed MilesCranmer closed 11 months ago

MilesCranmer commented 11 months ago

This improves the type utilities, making it easier for a user to set up custom behavior in an abstract type:


TODO:


Edit 1: I'm going to say this will depend on https://github.com/JuliaObjects/ConstructionBase.jl/pull/81 so that we don't make LinearAlgebra.jl a hard dependency.

Edit 2: I'll just keep it as a custom constructorof to avoid having extra dependencies

MilesCranmer commented 11 months ago

I'd like to get this into v0.8 since it's a breaking change. So let me know soon if there are any other comments...

github-actions[bot] commented 11 months ago

Benchmark Results

main aec9a125f96008... t[main]/t[aec9a125f96008...]
Quantity/creation/Quantity(x) 3.2 ± 0.1 ns 3.2 ± 0.1 ns 1
Quantity/creation/Quantity(x, length=y) 3.3 ± 0.1 ns 3.3 ± 0.1 ns 1
Quantity/with_numbers/*real 2.9 ± 0.1 ns 2.9 ± 0.1 ns 1
Quantity/with_numbers/^int 10.1 ± 2.5 ns 10.1 ± 2.8 ns 1
Quantity/with_numbers/^int * real 10.5 ± 2.1 ns 10.5 ± 2.4 ns 1
Quantity/with_quantity/+y 5.9 ± 0.1 ns 5.9 ± 0.1 ns 1
Quantity/with_quantity//y 3.3 ± 0.1 ns 3.3 ± 0.1 ns 1
Quantity/with_self/dimension 1.6 ± 0.1 ns 1.6 ± 0.1 ns 1
Quantity/with_self/inv 3.3 ± 0.1 ns 3.3 ± 0.1 ns 1
Quantity/with_self/ustrip 1.6 ± 0.1 ns 1.6 ± 0.1 ns 1
QuantityArray/broadcasting/multi_array_of_quantities 0.198 ± 0.17 ms 0.197 ± 0.17 ms 1.01
QuantityArray/broadcasting/multi_normal_array 0.0682 ± 0.0017 ms 0.0681 ± 0.0008 ms 1
QuantityArray/broadcasting/multi_quantity_array 0.228 ± 0.0023 ms 0.228 ± 0.0026 ms 1
QuantityArray/broadcasting/x^2_array_of_quantities 0.0428 ± 0.0041 ms 0.0406 ± 0.0037 ms 1.05
QuantityArray/broadcasting/x^2_normal_array 8.4 ± 1.2 μs 8.1 ± 1 μs 1.04
QuantityArray/broadcasting/x^2_quantity_array 9.6 ± 1.3 μs 10.4 ± 0.9 μs 0.923
QuantityArray/broadcasting/x^4_array_of_quantities 0.117 ± 0.0044 ms 0.117 ± 0.0043 ms 0.994
QuantityArray/broadcasting/x^4_normal_array 0.0623 ± 0.0026 ms 0.062 ± 0.0006 ms 1
QuantityArray/broadcasting/x^4_quantity_array 0.0819 ± 0.0036 ms 0.0829 ± 0.0041 ms 0.988
time_to_load 0.202 ± 0.0011 s 0.201 ± 0.0021 s 1

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).