Skip to content

Commit

Permalink
Merge d2ada3d into 6bd561c
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano authored May 18, 2022
2 parents 6bd561c + d2ada3d commit f8cf429
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# History of Measurements.jl

## v2.7.2 (2022-0?-??)

### Bug Fixes

* Fixed norm of `AbstractArray{<:Measurement}`
([#120](https://github.com/JuliaPhysics/Measurements.jl/pull/120)).

## v2.7.1 (2022-03-03)

### Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions src/Measurements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ include("conversions.jl")
include("comparisons-tests.jl")
include("utils.jl")
include("math.jl")
include("linear_algebra.jl")
include("show.jl")
include("parsing.jl")
include("plot-recipes.jl")
Expand Down
14 changes: 14 additions & 0 deletions src/linear_algebra.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using LinearAlgebra

function LinearAlgebra.normInf(A::AbstractArray{<:Measurement})
norm = LinearAlgebra.generic_normInf(A)
if iszero(norm.val)
# This is a bit complicated, follow me. The Inf-norm is the limit of the p-norms,
# for `p > 1`. But for `p > 1` we always have `(0 ± u) ^ p == 0 ± 0`, for any value
# of `u` so the limit is always `0 ± 0`, in particular the uncertainty is always
# zero. Therefore, if the the maximum absolute value is zero, then also the
# uncertainty must be zero, whatever were the other uncertainties.
return zero(norm)
end
return norm
end
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,19 @@ end
@test @inferred(b c) 7.020527859237536 ± 0.5707235338984873
@test @inferred(det(A)) 682 ± 9.650906693155829
@test @inferred(A * inv(A)) I
# This matrix `A` has the property that the Inf-norm of `A * inv(A) - I` has
# zero value but non-zero uncertainty in Julia v1.9, which would make the
# check `A * inv(A) ≈ I` fail.
A = [(14 ± 0.1) (23 ± 0.2); (-12 ± 0.3) (24 ± 0.4)]
@test @inferred(norm(A * inv(A) - I)) zero(Measurement{Float64}) atol=3e-16
@test @inferred(A * inv(A)) I

Z = [(0 ± 1) (0 ± 2); (0 ± 3) (0 ± 4)]
@test norm(Z, 0) == 4 ± 0 # Note: all elements of `Z` are `!iszero`
@test norm(Z, 1) == 0 ± sqrt(sum(abs2, uncertainty.(Z)))
@test norm(Z, 2) == zero(Measurement{Float64})
@test norm(Z, 5) == zero(Measurement{Float64})
@test norm(Z, Inf) == zero(Measurement{Float64})
end

@testset "NaNs" begin
Expand Down

0 comments on commit f8cf429

Please sign in to comment.