Skip to content

Commit 3686cd7

Browse files
authored
[BlockSparseArrays] Fix nstored and norm(NaN) (#1565)
1 parent 8d4a14f commit 3686cd7

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

ext/BlockSparseArraysGradedAxesExt/test/runtests.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using NDTensors.GradedAxes:
1515
isdual
1616
using NDTensors.LabelledNumbers: label
1717
using NDTensors.SparseArrayInterface: nstored
18+
using NDTensors.SymmetrySectors: U1
1819
using NDTensors.TensorAlgebra: fusedims, splitdims
1920
using LinearAlgebra: adjoint
2021
using Random: randn!
@@ -26,13 +27,6 @@ function blockdiagonal!(f, a::AbstractArray)
2627
return a
2728
end
2829

29-
struct U1
30-
n::Int
31-
end
32-
GradedAxes.dual(c::U1) = U1(-c.n)
33-
GradedAxes.fuse_labels(c1::U1, c2::U1) = U1(c1.n + c2.n)
34-
Base.isless(c1::U1, c2::U1) = isless(c1.n, c2.n)
35-
3630
const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
3731
@testset "BlockSparseArraysGradedAxesExt (eltype=$elt)" for elt in elts
3832
@testset "map" begin
@@ -66,8 +60,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
6660
@test blocksize(b) == (2, 2, 2, 2)
6761
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
6862
@test nstored(b) == 256
69-
# TODO: Fix this for `BlockedArray`.
70-
@test_broken block_nstored(b) == 16
63+
@test block_nstored(b) == 16
7164
for i in 1:ndims(a)
7265
@test axes(b, i) isa BlockedOneTo{Int}
7366
end

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,5 +305,4 @@ function blocksparse_blocks(
305305
end
306306

307307
using BlockArrays: BlocksView
308-
# TODO: Is this correct in general?
309-
SparseArrayInterface.nstored(a::BlocksView) = 1
308+
SparseArrayInterface.nstored(a::BlocksView) = length(a)

test/test_basics.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using BlockArrays:
1515
blocksizes,
1616
mortar
1717
using Compat: @compat
18-
using LinearAlgebra: Adjoint, mul!
18+
using LinearAlgebra: Adjoint, mul!, norm
1919
using NDTensors.BlockSparseArrays:
2020
@view!,
2121
BlockSparseArray,
@@ -94,6 +94,9 @@ include("TestBlockSparseArraysUtils.jl")
9494
iszero(a[I])
9595
end
9696
end
97+
98+
a[3, 3] = NaN
99+
@test isnan(norm(a))
97100
end
98101
@testset "Tensor algebra" begin
99102
a = BlockSparseArray{elt}(undef, ([2, 3], [3, 4]))

0 commit comments

Comments
 (0)