diff --git a/Project.toml b/Project.toml index 73efa9ee..432f74c2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StaticArrays" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.5.24" +version = "1.5.25" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/linalg.jl b/src/linalg.jl index bac3c3df..4e91e665 100644 --- a/src/linalg.jl +++ b/src/linalg.jl @@ -231,7 +231,7 @@ end m = maxabs_nested(a[1]) for j = 2:prod(size(a)) - m = @fastmath max(m, maxabs_nested(a[j])) + m = max(m, maxabs_nested(a[j])) end return m @@ -246,6 +246,7 @@ end return quote $(Expr(:meta, :inline)) scale = maxabs_nested(a) + !isfinite(scale) && return scale iszero(scale) && return _init_zero(a) return @inbounds scale * sqrt($expr) diff --git a/test/linalg.jl b/test/linalg.jl index c0c7867f..2b733279 100644 --- a/test/linalg.jl +++ b/test/linalg.jl @@ -318,6 +318,23 @@ end @test norm(SA[SVector{0,Int}(),SVector{0,Int}()]) isa float(Int) @test norm(SA[SVector{0,Int}(),SVector{0,Int}()]) == norm([Int[], Int[]]) + # norm of SVector with NaN and/or Inf elements -- issue #1135 + @test isnan(norm(SA[0.0, NaN])) + @test isnan(norm(SA[NaN, 0.0])) + @test norm(SA[0.0, Inf]) == Inf + @test norm(SA[Inf, 0.0]) == Inf + @test norm(SA[0.0, -Inf]) == Inf + @test norm(SA[-Inf, 0.0]) == Inf + @test norm(SA[Inf, Inf]) == Inf + @test norm(SA[-Inf, -Inf]) == Inf + @test norm(SA[Inf, -Inf]) == Inf + @test norm(SA[-Inf, Inf]) == Inf + @test isnan(norm(SA[Inf, NaN])) + @test isnan(norm(SA[NaN, Inf])) + @test isnan(norm(SA[-Inf, NaN])) + @test isnan(norm(SA[NaN, -Inf])) + @test isapprox(SA[0.0, NaN], SA[0.0, NaN], nans=true) + # no allocation for MArray -- issue #1126 @inline function calc_particle_forces!(s, pos1, pos2)