From 9bd7c1f51c8a5e419d18a1938b2f2a7f27ba6316 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 16 Apr 2026 13:59:24 -0400 Subject: [PATCH 1/2] Fix @test_broken tests that now pass on Julia v1.12.6 Julia v1.12.6 fixed type inference for abstract array dispatch (JuliaLang/julia#57582), which makes JLArray-backed BlockSparseMatrix operations (eig, svd, qr, iszero on views) work correctly. Use `broken = gpu_broken` with a VERSION check so tests remain broken on older Julia versions. Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 2 +- test/test_abstract_blocktype.jl | 57 +++++++++++---------------------- test/test_map.jl | 7 ++-- 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/Project.toml b/Project.toml index 242155ea..50d21421 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockSparseArrays" uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" -version = "0.10.35" +version = "0.10.36" authors = ["ITensor developers and contributors"] [workspace] diff --git a/test/test_abstract_blocktype.jl b/test/test_abstract_blocktype.jl index 94d57505..7ac7bb00 100644 --- a/test/test_abstract_blocktype.jl +++ b/test/test_abstract_blocktype.jl @@ -7,7 +7,7 @@ using MatrixAlgebraKit: eig_full, eig_trunc, eig_vals, eigh_full, eigh_trunc, ei isisometric, left_orth, left_polar, lq_compact, lq_full, qr_compact, qr_full, right_orth, right_polar, svd_compact, svd_full, svd_trunc using SparseArraysBase: storedlength -using Test: @test, @test_broken, @testset +using Test: @test, @testset elts = (Float32, Float64, ComplexF32) arrayts = (Array, JLArray) @@ -15,6 +15,7 @@ arrayts = (Array, JLArray) elt in elts dev = adapt(arrayt) + gpu_broken = arrayt ≠ Array && VERSION < v"1.12.6" a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3]) @test sprint(show, MIME"text/plain"(), a) isa String @@ -56,65 +57,45 @@ arrayts = (Array, JLArray) a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3]) a[Block(1, 1)] = dev(randn(elt, 2, 2)) for f in (eig_full, eig_trunc) - if arrayt === Array + @test begin d, v = f(a) - @test a * v ≈ v * d - else - @test_broken f(a) - end + a * v ≈ v * d + end broken = gpu_broken end - if arrayt === Array + @test begin d = eig_vals(a) - @test sort(Vector(d); by = abs) ≈ sort(eig_vals(Matrix(a)); by = abs) - else - @test_broken eig_vals(a) - end + sort(Vector(d); by = abs) ≈ sort(eig_vals(Matrix(a)); by = abs) + end broken = gpu_broken a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3]) a[Block(1, 1)] = dev(parent(hermitianpart(randn(elt, 2, 2)))) for f in (eigh_full, eigh_trunc) - if arrayt === Array + @test begin d, v = f(a) - @test a * v ≈ v * d - else - @test_broken f(a) - end + a * v ≈ v * d + end broken = gpu_broken end - if arrayt === Array + @test begin d = eigh_vals(a) - @test sort(Vector(d); by = abs) ≈ sort(eig_vals(Matrix(a)); by = abs) - else - @test_broken eigh_vals(a) - end + sort(Vector(d); by = abs) ≈ sort(eig_vals(Matrix(a)); by = abs) + end broken = gpu_broken a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3]) a[Block(1, 1)] = dev(randn(elt, 2, 2)) for f in (left_orth, left_polar, qr_compact, qr_full) u, c = f(a) @test u * c ≈ a - if arrayt ≡ Array - @test isisometric(u; side = :left) - else - # TODO: Fix comparison with UniformScaling on GPU. - @test_broken isisometric(u; side = :left) - end + @test isisometric(u; side = :left) broken = gpu_broken end for f in (right_orth, right_polar, lq_compact, lq_full) c, u = f(a) @test c * u ≈ a - if arrayt ≡ Array - @test isisometric(u; side = :right) - else - # TODO: Fix comparison with UniformScaling on GPU. - @test_broken isisometric(u; side = :right) - end + @test isisometric(u; side = :right) broken = gpu_broken end for f in (svd_compact, svd_full, svd_trunc) - if arrayt ≢ Array && (f ≡ svd_full || f ≡ svd_trunc) - @test_broken f(a) - else + @test begin u, s, v = f(a) - @test u * s * v ≈ a - end + u * s * v ≈ a + end broken = gpu_broken && (f ≡ svd_full || f ≡ svd_trunc) end end diff --git a/test/test_map.jl b/test/test_map.jl index fcd9f364..3b6942bd 100644 --- a/test/test_map.jl +++ b/test/test_map.jl @@ -15,6 +15,7 @@ arrayts = (Array, JLArray) elt in elts dev = adapt(arrayt) + gpu_broken = arrayt ≠ Array && VERSION < v"1.12.6" a = dev(BlockSparseArray{elt}(undef, ([2, 3], [3, 4]))) @views for b in [Block(1, 2), Block(2, 1)] @@ -98,16 +99,14 @@ arrayts = (Array, JLArray) @test iszero(storedlength(a)) @test iszero(b) @test iszero(storedlength(b)) - # TODO: Broken on GPU. - @test iszero(c) broken = arrayt ≠ Array + @test iszero(c) broken = gpu_broken @test iszero(storedlength(c)) @allowscalar a[5, 7] = 1 @test !iszero(a) @test storedlength(a) == 3 * 4 @test !iszero(b) @test storedlength(b) == 3 * 4 - # TODO: Broken on GPU. - @test !iszero(c) broken = arrayt ≠ Array + @test !iszero(c) broken = gpu_broken @test storedlength(c) == 3 * 4 d = @view a[1:4, 1:6] @test iszero(d) From ef95471d2f041dae5f41e7cb2239c88bca94c1f8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 16 Apr 2026 14:34:30 -0400 Subject: [PATCH 2/2] Remove incorrect VERSION check from gpu_broken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The JLArray operations still fail in fresh Pkg.test() processes on Julia v1.12.6; they only succeeded in a warmed REPL session. Drop the VERSION < v"1.12.6" condition and keep gpu_broken = arrayt ≠ Array. Co-Authored-By: Claude Opus 4.6 (1M context) --- test/test_abstract_blocktype.jl | 2 +- test/test_map.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_abstract_blocktype.jl b/test/test_abstract_blocktype.jl index 7ac7bb00..134499f0 100644 --- a/test/test_abstract_blocktype.jl +++ b/test/test_abstract_blocktype.jl @@ -15,7 +15,7 @@ arrayts = (Array, JLArray) elt in elts dev = adapt(arrayt) - gpu_broken = arrayt ≠ Array && VERSION < v"1.12.6" + gpu_broken = arrayt ≠ Array a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3]) @test sprint(show, MIME"text/plain"(), a) isa String diff --git a/test/test_map.jl b/test/test_map.jl index 3b6942bd..b24b5f4d 100644 --- a/test/test_map.jl +++ b/test/test_map.jl @@ -15,7 +15,7 @@ arrayts = (Array, JLArray) elt in elts dev = adapt(arrayt) - gpu_broken = arrayt ≠ Array && VERSION < v"1.12.6" + gpu_broken = arrayt ≠ Array a = dev(BlockSparseArray{elt}(undef, ([2, 3], [3, 4]))) @views for b in [Block(1, 2), Block(2, 1)]