From 4d86ca0d7ee81b01adf29edfff02012247b09c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Tue, 5 Nov 2024 15:42:49 -0500 Subject: [PATCH] fix norm with NaN --- NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl | 5 ++++- .../lib/SparseArrayInterface/src/sparsearrayinterface/map.jl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl index 095364687f..ad4b5449bc 100644 --- a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl +++ b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl @@ -15,7 +15,7 @@ using BlockArrays: blocksizes, mortar using Compat: @compat -using LinearAlgebra: Adjoint, mul! +using LinearAlgebra: Adjoint, mul!, norm using NDTensors.BlockSparseArrays: @view!, BlockSparseArray, @@ -94,6 +94,9 @@ include("TestBlockSparseArraysUtils.jl") iszero(a[I]) end end + + a[3, 3] = NaN + @test isnan(norm(a)) end @testset "Tensor algebra" begin a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4])) diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl b/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl index f637a5701e..8a5f32d8a6 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl @@ -115,6 +115,6 @@ end function sparse_mapreduce(f, op, a::AbstractArray; init=reduce_init(f, op, a), kwargs...) output = mapreduce(f, op, sparse_storage(a); init, kwargs...) f_notstored = apply_notstored(f, a) - @assert op(output, eltype(output)(f_notstored)) == output + @assert isequal(op(output, eltype(output)(f_notstored)), output) return output end