Skip to content

Commit d9d54bd

Browse files
authored
Fix norm of StaticArrays with non-finite elements (#1161)
* Add tests for norm of SVector with NaN or Inf elements * Fix norm of StaticArrays with non-finite elements * Bump patch version
1 parent 3e74bde commit d9d54bd

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.5.24"
3+
version = "1.5.25"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/linalg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ end
231231

232232
m = maxabs_nested(a[1])
233233
for j = 2:prod(size(a))
234-
m = @fastmath max(m, maxabs_nested(a[j]))
234+
m = max(m, maxabs_nested(a[j]))
235235
end
236236

237237
return m
@@ -246,6 +246,7 @@ end
246246
return quote
247247
$(Expr(:meta, :inline))
248248
scale = maxabs_nested(a)
249+
!isfinite(scale) && return scale
249250

250251
iszero(scale) && return _init_zero(a)
251252
return @inbounds scale * sqrt($expr)

test/linalg.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,23 @@ end
318318
@test norm(SA[SVector{0,Int}(),SVector{0,Int}()]) isa float(Int)
319319
@test norm(SA[SVector{0,Int}(),SVector{0,Int}()]) == norm([Int[], Int[]])
320320

321+
# norm of SVector with NaN and/or Inf elements -- issue #1135
322+
@test isnan(norm(SA[0.0, NaN]))
323+
@test isnan(norm(SA[NaN, 0.0]))
324+
@test norm(SA[0.0, Inf]) == Inf
325+
@test norm(SA[Inf, 0.0]) == Inf
326+
@test norm(SA[0.0, -Inf]) == Inf
327+
@test norm(SA[-Inf, 0.0]) == Inf
328+
@test norm(SA[Inf, Inf]) == Inf
329+
@test norm(SA[-Inf, -Inf]) == Inf
330+
@test norm(SA[Inf, -Inf]) == Inf
331+
@test norm(SA[-Inf, Inf]) == Inf
332+
@test isnan(norm(SA[Inf, NaN]))
333+
@test isnan(norm(SA[NaN, Inf]))
334+
@test isnan(norm(SA[-Inf, NaN]))
335+
@test isnan(norm(SA[NaN, -Inf]))
336+
@test isapprox(SA[0.0, NaN], SA[0.0, NaN], nans=true)
337+
321338
# no allocation for MArray -- issue #1126
322339

323340
@inline function calc_particle_forces!(s, pos1, pos2)

0 commit comments

Comments
 (0)