Skip to content

Commit 23b63fd

Browse files
mtfishmanclaude
andauthored
Make test_abstract_blocktype work with MatrixAlgebraKit 0.6.6 (#262)
## Summary Two issues surface in `test/test_abstract_blocktype.jl` once MatrixAlgebraKit 0.6.6 is resolved (which can happen on any new `Pkg.add`/`Pkg.update` against the registered v0.10.39, since its `test/Project.toml` allows `MatrixAlgebraKit = "0.6.0 - 0.6.4, 0.6.6"`): - `@test_broken f(a)` for `f ∈ (svd_full, svd_trunc)` on JLArray-backed `BlockSparseMatrix{T, AbstractMatrix{T}}` errors with `Expression evaluated to non-Boolean` because `svd_full` now succeeds and returns a 3-tuple — it used to throw, which `@test_broken` correctly caught. - The unconditional `@test c * u ≈ a` in the right-side loop is flaky on JLArray for `right_orth`, `lq_compact`, `lq_full`. These factorizations regressed in MatrixAlgebraKit 0.6.5/0.6.6 and produce `c * u != a` on GPU-backed inputs (0.6.4 was correct), tracked upstream at QuantumKitHub/MatrixAlgebraKit.jl#218. Whether the assertion fails on a given CI run depends on the random matrix. This PR: - Seeds each `(arrayt, elt)` iteration with `StableRNG(1)` so the test is deterministic across runs. - Promotes `svd_full` to a regular `@test` on JLArray (the math is now correct). - Wraps `svd_trunc` in a Boolean-safe `@test ... broken = true` block so its return value can no longer surface as a non-Boolean error. - Marks `c * u ≈ a` as broken on JLArray for `right_orth`, `lq_compact`, `lq_full`, with a comment pointing at QuantumKitHub/MatrixAlgebraKit.jl#218. ## Test plan - [x] `Pkg.test BlockSparseArrays` passes locally with MatrixAlgebraKit 0.6.6 (`test_abstract_blocktype.jl`: 198 pass + 54 broken = 252). - [ ] CI is green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b912400 commit 23b63fd

6 files changed

Lines changed: 60 additions & 67 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
3-
version = "0.10.39"
3+
version = "0.10.40"
44
authors = ["ITensor developers <support@itensor.org> and contributors"]
55

66
[workspace]

test/test_abstract_blocktype.jl

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ using BlockArrays: Block
33
using BlockSparseArrays: BlockSparseMatrix, blockstoredlength
44
using JLArrays: JLArray
55
using LinearAlgebra: hermitianpart, norm
6-
using MatrixAlgebraKit: eig_full, eig_trunc, eig_vals, eigh_full, eigh_trunc, eigh_vals,
7-
isisometric, left_orth, left_polar, lq_compact, lq_full, qr_compact, qr_full,
8-
right_orth, right_polar, svd_compact, svd_full, svd_trunc
6+
using MatrixAlgebraKit: MatrixAlgebraKit, eig_full, eig_trunc, eig_vals, eigh_full,
7+
eigh_trunc, eigh_vals, isisometric, left_orth, left_polar, lq_compact, lq_full,
8+
qr_compact, qr_full, right_orth, right_polar, svd_compact, svd_full, svd_trunc
99
using SparseArraysBase: storedlength
10-
using Test: @test, @test_broken, @testset
10+
using StableRNGs: StableRNG
11+
using Test: @test, @testset
1112

1213
elts = (Float32, Float64, ComplexF32)
1314
arrayts = (Array, JLArray)
@@ -21,8 +22,9 @@ arrayts = (Array, JLArray)
2122
@test iszero(storedlength(a))
2223
@test iszero(blockstoredlength(a))
2324

25+
rng = StableRNG(1234)
2426
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
25-
a[Block(1, 1)] = dev(randn(elt, 2, 2))
27+
a[Block(1, 1)] = dev(randn(rng, elt, 2, 2))
2628
@test !iszero(a[Block(1, 1)])
2729
@test a[Block(1, 1)] isa arrayt{elt, 2}
2830
@test iszero(a[Block(2, 2)])
@@ -32,10 +34,11 @@ arrayts = (Array, JLArray)
3234
@test iszero(a[Block(1, 2)])
3335
@test a[Block(1, 2)] isa Matrix{elt}
3436

37+
rng = StableRNG(1234)
3538
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
36-
a[Block(1, 1)] = dev(randn(elt, 2, 2))
39+
a[Block(1, 1)] = dev(randn(rng, elt, 2, 2))
3740
a′ = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
38-
a′[Block(2, 2)] = dev(randn(elt, 3, 3))
41+
a′[Block(2, 2)] = dev(randn(rng, elt, 3, 3))
3942

4043
b = copy(a)
4144
@test Array(b) Array(a)
@@ -53,68 +56,62 @@ arrayts = (Array, JLArray)
5356
@test Array(b) Array(a) * Array(a′)
5457
@test norm(b) 0
5558

59+
rng = StableRNG(1234)
5660
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
57-
a[Block(1, 1)] = dev(randn(elt, 2, 2))
61+
a[Block(1, 1)] = dev(randn(rng, elt, 2, 2))
5862
for f in (eig_full, eig_trunc)
59-
if arrayt === Array
63+
@test begin
6064
d, v = f(a)
61-
@test a * v v * d
62-
else
63-
@test_broken f(a)
64-
end
65+
a * v v * d
66+
end broken = arrayt Array
6567
end
66-
if arrayt === Array
68+
@test begin
6769
d = eig_vals(a)
68-
@test sort(Vector(d); by = abs) sort(eig_vals(Matrix(a)); by = abs)
69-
else
70-
@test_broken eig_vals(a)
71-
end
70+
sort(Vector(d); by = abs) sort(eig_vals(Matrix(a)); by = abs)
71+
end broken = arrayt Array
7272

73+
rng = StableRNG(1234)
7374
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
74-
a[Block(1, 1)] = dev(parent(hermitianpart(randn(elt, 2, 2))))
75+
a[Block(1, 1)] = dev(parent(hermitianpart(randn(rng, elt, 2, 2))))
7576
for f in (eigh_full, eigh_trunc)
76-
if arrayt === Array
77+
@test begin
7778
d, v = f(a)
78-
@test a * v v * d
79-
else
80-
@test_broken f(a)
81-
end
79+
a * v v * d
80+
end broken = arrayt Array
8281
end
83-
if arrayt === Array
82+
@test begin
8483
d = eigh_vals(a)
85-
@test sort(Vector(d); by = abs) sort(eig_vals(Matrix(a)); by = abs)
86-
else
87-
@test_broken eigh_vals(a)
88-
end
84+
sort(Vector(d); by = abs) sort(eig_vals(Matrix(a)); by = abs)
85+
end broken = arrayt Array
8986

87+
rng = StableRNG(1234)
9088
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
91-
a[Block(1, 1)] = dev(randn(elt, 2, 2))
89+
a[Block(1, 1)] = dev(randn(rng, elt, 2, 2))
9290
for f in (left_orth, left_polar, qr_compact, qr_full)
9391
u, c = f(a)
9492
@test u * c a
95-
if arrayt Array
96-
@test isisometric(u; side = :left)
97-
else
98-
# TODO: Fix comparison with UniformScaling on GPU.
99-
@test_broken isisometric(u; side = :left)
100-
end
93+
# TODO: Fix comparison with UniformScaling on GPU.
94+
@test isisometric(u; side = :left) broken = arrayt Array
10195
end
10296
for f in (right_orth, right_polar, lq_compact, lq_full)
10397
c, u = f(a)
104-
@test c * u a
105-
if arrayt Array
106-
@test isisometric(u; side = :right)
107-
else
108-
# TODO: Fix comparison with UniformScaling on GPU.
109-
@test_broken isisometric(u; side = :right)
110-
end
98+
# `right_orth`, `lq_compact`, `lq_full` on JLArray-backed
99+
# `BlockSparseMatrix{T, AbstractMatrix{T}}` produce a `c * u` that does not
100+
# reproduce `a` (regression in MatrixAlgebraKit 0.6.6; fix tracked at
101+
# https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/219).
102+
broken =
103+
arrayt Array && f (right_orth, lq_compact, lq_full) &&
104+
pkgversion(MatrixAlgebraKit) < v"0.6.7"
105+
@test c * u a broken = broken
106+
# TODO: Fix comparison with UniformScaling on GPU.
107+
@test isisometric(u; side = :right) broken = arrayt Array
111108
end
112109
for f in (svd_compact, svd_full, svd_trunc)
113-
if arrayt Array && (f svd_full || f svd_trunc)
114-
@test_broken f(a)
115-
else
110+
# `svd_trunc` on JLArray-backed `BlockSparseMatrix{T, AbstractMatrix{T}}`
111+
# currently triggers scalar indexing on the GPU array.
112+
@test begin
116113
u, s, v = f(a)
117-
@test u * s * v a
118-
end
114+
u * s * v a
115+
end broken = (arrayt Array && f svd_trunc)
119116
end
120117
end

test/test_basics.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using JLArrays: JLArray, JLMatrix
1111
using LinearAlgebra: Adjoint, Transpose, dot, norm, tr
1212
using SparseArraysBase:
1313
SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, isstored, storedlength
14-
using Test: @inferred, @test, @test_broken, @test_throws, @testset
14+
using Test: @inferred, @test, @test_throws, @testset
1515
using TestExtras: @constinferred
1616
using TypeParameterAccessors: TypeParameterAccessors, Position
1717
include("TestBlockSparseArraysUtils.jl")
@@ -28,18 +28,18 @@ arrayts = (Array, JLArray)
2828
a = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))
2929
a[Block(1, 1)] = dev(randn(elt, 2, 2))
3030
a[Block(2, 2)] = dev(randn(elt, 3, 3))
31-
@test_broken a[:, 4]
31+
@test a[:, 4] broken = true
3232

3333
# TODO: Fix this and turn it into a proper test.
3434
a = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))
3535
a[Block(1, 1)] = dev(randn(elt, 2, 2))
3636
a[Block(2, 2)] = dev(randn(elt, 3, 3))
3737
@allowscalar @test a[2:4, 4] == Array(a)[2:4, 4]
38-
@test_broken a[4, 2:4]
38+
@test a[4, 2:4] broken = true
3939

4040
@test a[Block(1), :] isa BlockSparseArray{elt}
4141
@test adjoint(a) isa Adjoint{elt, <:BlockSparseArray}
42-
@test_broken adjoint(a)[Block(1), :] isa Adjoint{elt, <:BlockSparseArray}
42+
@test adjoint(a)[Block(1), :] isa Adjoint{elt, <:BlockSparseArray} broken = true
4343
# could also be directly a BlockSparseArray
4444
end
4545
@testset "Constructors" begin
@@ -153,10 +153,10 @@ arrayts = (Array, JLArray)
153153
a = arrayt(randn(elt, 2, 2))
154154
@test (@constinferred blockstype(a)) <: BlockArrays.BlockView{elt, 2}
155155
# TODO: This is difficult to determine just from type information.
156-
@test_broken blockstype(typeof(a)) <: BlockArrays.BlockView{elt, 2}
156+
@test blockstype(typeof(a)) <: BlockArrays.BlockView{elt, 2} broken = true
157157
@test (@constinferred blocktype(a)) <: arrayt{elt, 2}
158158
# TODO: This is difficult to determine just from type information.
159-
@test_broken blocktype(typeof(a)) <: SubArray{elt, 2, arrayt{elt, 2}}
159+
@test blocktype(typeof(a)) <: SubArray{elt, 2, arrayt{elt, 2}} broken = true
160160

161161
a = BlockSparseMatrix{elt, arrayt{elt, 2}}(undef, [1, 1], [1, 1])
162162
@test (@constinferred blockstype(a)) <: SparseMatrixDOK{arrayt{elt, 2}}
@@ -173,9 +173,9 @@ arrayts = (Array, JLArray)
173173
a = BlockedArray(arrayt(randn(elt, 2, 2)), [1, 1], [1, 1])
174174
@test (@constinferred blockstype(a)) <: BlockArrays.BlocksView{elt, 2}
175175
# TODO: This is difficult to determine just from type information.
176-
@test_broken blockstype(typeof(a)) <: BlockArrays.BlocksView{elt, 2}
176+
@test blockstype(typeof(a)) <: BlockArrays.BlocksView{elt, 2} broken = true
177177
@test blocktype(a) <: AbstractMatrix{elt}
178-
@test_broken blocktype(typeof(a)) <: AbstractMatrix{elt}
178+
@test blocktype(typeof(a)) <: AbstractMatrix{elt} broken = true
179179

180180
# sparsemortar
181181
for ax in (

test/test_genericblockindex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using BlockArrays: Block, BlockIndex, BlockSlice, BlockedArray, BlockedVector, b
33
using BlockSparseArrays: BlockSparseArrays, BlockIndexVector, BlockIndices,
44
GenericBlockIndex, blockedunitrange_getindices, blocksparsezeros, to_block,
55
to_block_indices, to_blockindexrange
6-
using Test: @test, @test_broken, @testset
6+
using Test: @test, @testset
77

88
# blockrange
99
# checkindex

test/test_map.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using GPUArraysCore: @allowscalar
77
using JLArrays: JLArray
88
using SparseArraysBase: storedlength
99
using StableRNGs: StableRNG
10-
using Test: @test, @test_broken, @test_throws, @testset
10+
using Test: @test, @test_throws, @testset
1111

1212
elts = (Float32, Float64, ComplexF32)
1313
arrayts = (Array, JLArray)
@@ -407,12 +407,8 @@ arrayts = (Array, JLArray)
407407
a[Block(1, 1)] = dev(randn(elt, 2, 2))
408408
a[Block(2, 2)] = dev(randn(elt, 3, 3))
409409
I = (:, [2, 4])
410-
if arrayt === Array
411-
@test Array(a[I...]) == Array(a)[I...]
412-
else
413-
# TODO: Broken on GPU, fix this.
414-
@test_broken a[I...]
415-
end
410+
# TODO: Broken on GPU, fix this.
411+
@test Array(a[I...]) == Array(a)[I...] broken = arrayt Array
416412

417413
a = BlockSparseArray{elt}(undef, [2, 3], [2, 3])
418414
@views for b in [Block(1, 1), Block(2, 2)]
@@ -718,5 +714,5 @@ arrayts = (Array, JLArray)
718714
a[Block(2, 2)] = randn(elt, 3, 3)
719715
@test a[2:4, 4] == Array(a)[2:4, 4]
720716
# TODO: Fix this.
721-
@test_broken a[4, 2:4] == Array(a)[4, 2:4]
717+
@test a[4, 2:4] == Array(a)[4, 2:4] broken = true
722718
end

test/test_tensoralgebraext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using BlockArrays: Block, BlockArray, blockedrange, blocksize
22
using BlockSparseArrays: BlockSparseArray
33
using Random: randn!
44
using TensorAlgebra: contract
5-
using Test: @test, @test_broken, @testset
5+
using Test: @test, @testset
66

77
function randn_blockdiagonal(elt::Type, axes::Tuple)
88
a = BlockSparseArray{elt}(undef, axes)

0 commit comments

Comments
 (0)