From 9ceba1c5fb935afd0aee44da73c22b22b72e1df4 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 6 Feb 2025 13:33:06 -0500 Subject: [PATCH 1/4] Fix some ambiguity errors with BlockArrays.jl --- .../BlockSparseArraysGradedUnitRangesExt.jl | 14 ++++++++++++++ test/test_gradedunitrangesext.jl | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl b/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl index 31a1fec..b503a94 100644 --- a/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl +++ b/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl @@ -29,6 +29,15 @@ function Base.similar( return similar_blocksparse(a, elt, axes) end +# Fix ambiguity error with `BlockArrays.jl`. +function Base.similar( + a::StridedArray, + elt::Type, + axes::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}}, +) + return similar_blocksparse(a, elt, axes) +end + # Fix ambiguity error with `BlockArrays.jl`. function Base.similar( a::StridedArray, @@ -63,6 +72,11 @@ function Base.getindex( return getindex_blocksparse(a, I1, I_rest...) end +# Fix ambiguity error with Base. +function Base.getindex(a::Vector, I::AbstractGradedUnitRange) + return getindex_blocksparse(a, I) +end + # Fix ambiguity errors. function Base.getindex( a::AnyAbstractBlockSparseArray, diff --git a/test/test_gradedunitrangesext.jl b/test/test_gradedunitrangesext.jl index 67b069e..c81b320 100644 --- a/test/test_gradedunitrangesext.jl +++ b/test/test_gradedunitrangesext.jl @@ -2,7 +2,8 @@ using Test: @test, @testset using BlockArrays: AbstractBlockArray, Block, BlockedOneTo, blockedrange, blocklengths, blocksize -using BlockSparseArrays: BlockSparseArray, BlockSparseMatrix, blockstoredlength +using BlockSparseArrays: + BlockSparseArray, BlockSparseMatrix, BlockSparseVector, blockstoredlength using GradedUnitRanges: GradedUnitRanges, GradedOneTo, @@ -332,6 +333,20 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) @test iszero(b[Block(1, 2)]) @test b[Block(2, 2)] == a2 @test all(GradedUnitRanges.space_isequal.(axes(b), (r, dual(r)))) + + # Regression test for Vector, which caused + # an ambiguity error with Base. + r = gradedrange([U1(0) => 2, U1(1) => 3]) + a1 = randn(elt, 2) + a2 = zeros(elt, 3) + a = vcat(a1, a2) + b = a[r] + @test eltype(b) === elt + @test b isa BlockSparseVector{elt} + @test blockstoredlength(b) == 1 + @test b[Block(1)] == a1 + @test iszero(b[Block(2)]) + @test all(GradedUnitRanges.space_isequal.(axes(b), (r,))) end end end From e2535b0eb5722de2351545b038c2e7c98254870b Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 6 Feb 2025 13:33:27 -0500 Subject: [PATCH 2/4] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6a8ab90..50581f2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlockSparseArrays" uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" authors = ["ITensor developers and contributors"] -version = "0.2.12" +version = "0.2.13" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From 8e23672220427b99980a78de32fd756e491a1eef Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 6 Feb 2025 13:38:37 -0500 Subject: [PATCH 3/4] Comments --- .../BlockSparseArraysGradedUnitRangesExt.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl b/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl index b503a94..72ceaae 100644 --- a/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl +++ b/ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl @@ -77,7 +77,7 @@ function Base.getindex(a::Vector, I::AbstractGradedUnitRange) return getindex_blocksparse(a, I) end -# Fix ambiguity errors. +# Fix ambiguity error with BlockSparseArrays.jl. function Base.getindex( a::AnyAbstractBlockSparseArray, I1::AbstractGradedUnitRange, @@ -85,6 +85,8 @@ function Base.getindex( ) return getindex_blocksparse(a, I1, I_rest...) end + +# Fix ambiguity error with BlockSparseArrays.jl. function Base.getindex( a::AnyAbstractBlockSparseArray{<:Any,2}, I1::AbstractGradedUnitRange, From 84260df553b04cb1a6e3ea079b368fb0ef45218a Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 6 Feb 2025 15:36:03 -0500 Subject: [PATCH 4/4] Reenable most Aqua tests --- test/test_aqua.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_aqua.jl b/test/test_aqua.jl index 6f678e2..0463d2d 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -3,6 +3,6 @@ using Aqua: Aqua using Test: @testset @testset "Code quality (Aqua.jl)" begin - # TODO: Fix Aqua issues and add this back. - # Aqua.test_all(BlockSparseArrays) + # TODO: Reenable ambiguity and piracy checks. + Aqua.test_all(BlockSparseArrays; ambiguities=false, piracies=false) end