From ebde62152d3e74fd8216eb50336babfc1b045144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Tue, 5 Nov 2024 18:36:48 -0500 Subject: [PATCH 1/2] [BlockSparseArrays] Fix nstored and norm(NaN) (#1565) --- .../BlockSparseArraysGradedAxesExt/test/runtests.jl | 11 ++--------- .../blocksparsearrayinterface.jl | 3 +-- .../src/lib/BlockSparseArrays/test/test_basics.jl | 5 ++++- .../src/sparsearrayinterface/map.jl | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl index 585dbb5afe..53c883bf54 100644 --- a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl +++ b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl @@ -15,6 +15,7 @@ using NDTensors.GradedAxes: isdual using NDTensors.LabelledNumbers: label using NDTensors.SparseArrayInterface: nstored +using NDTensors.SymmetrySectors: U1 using NDTensors.TensorAlgebra: fusedims, splitdims using LinearAlgebra: adjoint using Random: randn! @@ -26,13 +27,6 @@ function blockdiagonal!(f, a::AbstractArray) return a end -struct U1 - n::Int -end -GradedAxes.dual(c::U1) = U1(-c.n) -GradedAxes.fuse_labels(c1::U1, c2::U1) = U1(c1.n + c2.n) -Base.isless(c1::U1, c2::U1) = isless(c1.n, c2.n) - const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) @testset "BlockSparseArraysGradedAxesExt (eltype=$elt)" for elt in elts @testset "map" begin @@ -66,8 +60,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) @test blocksize(b) == (2, 2, 2, 2) @test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2]) @test nstored(b) == 256 - # TODO: Fix this for `BlockedArray`. - @test_broken block_nstored(b) == 16 + @test block_nstored(b) == 16 for i in 1:ndims(a) @test axes(b, i) isa BlockedOneTo{Int} end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 182504e038..732a895286 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -305,5 +305,4 @@ function blocksparse_blocks( end using BlockArrays: BlocksView -# TODO: Is this correct in general? -SparseArrayInterface.nstored(a::BlocksView) = 1 +SparseArrayInterface.nstored(a::BlocksView) = length(a) 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 From c105287f42647b3f2c1d45932c0fdc50eab5a556 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Tue, 5 Nov 2024 18:37:35 -0500 Subject: [PATCH 2/2] [NDTensors] Bump to v0.3.54 [no ci] --- NDTensors/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index eb85447638..1e24dc0300 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.53" +version = "0.3.54" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"