From eedca9c8bac7fc096e36c0dc41d97b98b055ee38 Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Fri, 12 May 2023 19:29:06 -0300 Subject: [PATCH 1/3] Add tests for norm of SVector with NaN or Inf elements --- test/linalg.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/linalg.jl b/test/linalg.jl index c0c7867f1..2b7332797 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) From 198f1a623884dca5c89e8629ba96dcf3fb718f55 Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Fri, 12 May 2023 19:54:51 -0300 Subject: [PATCH 2/3] Fix norm of StaticArrays with non-finite elements --- src/linalg.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/linalg.jl b/src/linalg.jl index bac3c3dfd..4e91e665a 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) From a49161271dcda1be76285628ee47a5819e0a1ab1 Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Sat, 13 May 2023 17:49:25 -0300 Subject: [PATCH 3/3] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 73efa9ee4..432f74c23 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"