Skip to content

Commit

Permalink
Fix p-norm for unitful quantities (#1291)
Browse files Browse the repository at this point in the history
* fix p-norm for unitful quantities

* set version to v1.9.9
  • Loading branch information
JoshuaLampert authored Dec 20, 2024
1 parent b62e257 commit b23d668
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StaticArrays"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.9.8"
version = "1.9.9"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 2 additions & 2 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ end
$(Expr(:meta, :inline))
scale = maxabs_nested(a)

scale==0 && return _init_zero(a)
iszero(scale) && return _init_zero(a)
p == 1 && return @inbounds scale * $expr_p1
return @inbounds scale * ($expr)^(inv(p))
end
Expand All @@ -328,7 +328,7 @@ end
p == Inf && return mapreduce(norm, max, a) # no need for scaling

l = p==1 ? @inbounds($expr_p1) : @inbounds(($expr)^(inv(p)))
0<l<Inf && return l
zero(l) < l && isfinite(l) && return l
return _norm_scaled(Size(a), a, p) # p != 0, 2, Inf
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ using Unitful
@test norm(SVector(1.0*u"m")) == 1.0*u"m"
# issue $1127
@test norm(SVector(0.0, 0.0)*u"nm") == 0.0*u"nm"

@test norm(SVector(1.0, 2.0)*u"m", 1) == 3.0*u"m"
@test norm(SVector(0.0, 0.0)*u"nm", 1) == 0.0*u"nm"
end

2 comments on commit b23d668

@mateuszbaran
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/121726

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.9.9 -m "<description of version>" b23d6687e25a4266d6ced4b381eb950f1e400cb8
git push origin v1.9.9

Please sign in to comment.