Skip to content
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

Fix p-norm for unitful quantities #1291

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

JoshuaLampert
Copy link
Contributor

This is #1125 and #1128 for general p-norms, where $p\neq 0,2,\infty$. Before:

julia> norm(SVector(1.0, 2.0)*u"m", 1)
ERROR: DimensionError: 0.0 and 3.0 m are not dimensionally compatible.
Stacktrace:
 [1] _lt
   @ ~/.julia/packages/Unitful/dHMk1/src/quantities.jl:250 [inlined]
 [2] <(x::Quantity{Float64, NoDims, Unitful.FreeUnits{…}}, y::Quantity{Float64, 𝐋, Unitful.FreeUnits{…}})
   @ Unitful ~/.julia/packages/Unitful/dHMk1/src/quantities.jl:240
 [3] <(x::Int64, y::Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}})
   @ Unitful ~/.julia/packages/Unitful/dHMk1/src/quantities.jl:242
 [4] macro expansion
   @ ~/.julia/dev/StaticArrays/src/linalg.jl:331 [inlined]
 [5] _norm
   @ ~/.julia/dev/StaticArrays/src/linalg.jl:311 [inlined]
 [6] norm(a::SVector{2, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, p::Int64)
   @ StaticArrays ~/.julia/dev/StaticArrays/src/linalg.jl:310
 [7] top-level scope
   @ REPL[27]:1
Some type information was truncated. Use `show(err)` to see complete types.

and

julia> norm(SVector(0.0, 0.0)*u"nm", 1)
NaN nm

After this PR:

julia> norm(SVector(1.0, 2.0)*u"m", 1)
3.0 m

and

julia> norm(SVector(0.0, 0.0)*u"nm", 1)
0.0 nm

Copy link
Collaborator

@mateuszbaran mateuszbaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM. Could you just bump patch version?

@JoshuaLampert
Copy link
Contributor Author

Thanks, LGTM. Could you just bump patch version?

Done in 2a717dc.

@mateuszbaran mateuszbaran merged commit b23d668 into JuliaArrays:master Dec 20, 2024
19 of 24 checks passed
@JoshuaLampert JoshuaLampert deleted the fix-p-norm-unitful branch December 20, 2024 08:51
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.

2 participants