Skip to content

Commit 88aa06f

Browse files
authored
Fix ambiguities with BlockArrays.jl (#39)
1 parent a7197ad commit 88aa06f

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.12"
4+
version = "0.2.13"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

ext/BlockSparseArraysGradedUnitRangesExt/BlockSparseArraysGradedUnitRangesExt.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ function Base.similar(
2929
return similar_blocksparse(a, elt, axes)
3030
end
3131

32+
# Fix ambiguity error with `BlockArrays.jl`.
33+
function Base.similar(
34+
a::StridedArray,
35+
elt::Type,
36+
axes::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}},
37+
)
38+
return similar_blocksparse(a, elt, axes)
39+
end
40+
3241
# Fix ambiguity error with `BlockArrays.jl`.
3342
function Base.similar(
3443
a::StridedArray,
@@ -63,14 +72,21 @@ function Base.getindex(
6372
return getindex_blocksparse(a, I1, I_rest...)
6473
end
6574

66-
# Fix ambiguity errors.
75+
# Fix ambiguity error with Base.
76+
function Base.getindex(a::Vector, I::AbstractGradedUnitRange)
77+
return getindex_blocksparse(a, I)
78+
end
79+
80+
# Fix ambiguity error with BlockSparseArrays.jl.
6781
function Base.getindex(
6882
a::AnyAbstractBlockSparseArray,
6983
I1::AbstractGradedUnitRange,
7084
I_rest::AbstractGradedUnitRange...,
7185
)
7286
return getindex_blocksparse(a, I1, I_rest...)
7387
end
88+
89+
# Fix ambiguity error with BlockSparseArrays.jl.
7490
function Base.getindex(
7591
a::AnyAbstractBlockSparseArray{<:Any,2},
7692
I1::AbstractGradedUnitRange,

test/test_aqua.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ using Aqua: Aqua
33
using Test: @testset
44

55
@testset "Code quality (Aqua.jl)" begin
6-
# TODO: Fix Aqua issues and add this back.
7-
# Aqua.test_all(BlockSparseArrays)
6+
# TODO: Reenable ambiguity and piracy checks.
7+
Aqua.test_all(BlockSparseArrays; ambiguities=false, piracies=false)
88
end

test/test_gradedunitrangesext.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
using Test: @test, @testset
33
using BlockArrays:
44
AbstractBlockArray, Block, BlockedOneTo, blockedrange, blocklengths, blocksize
5-
using BlockSparseArrays: BlockSparseArray, BlockSparseMatrix, blockstoredlength
5+
using BlockSparseArrays:
6+
BlockSparseArray, BlockSparseMatrix, BlockSparseVector, blockstoredlength
67
using GradedUnitRanges:
78
GradedUnitRanges,
89
GradedOneTo,
@@ -332,6 +333,20 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
332333
@test iszero(b[Block(1, 2)])
333334
@test b[Block(2, 2)] == a2
334335
@test all(GradedUnitRanges.space_isequal.(axes(b), (r, dual(r))))
336+
337+
# Regression test for Vector, which caused
338+
# an ambiguity error with Base.
339+
r = gradedrange([U1(0) => 2, U1(1) => 3])
340+
a1 = randn(elt, 2)
341+
a2 = zeros(elt, 3)
342+
a = vcat(a1, a2)
343+
b = a[r]
344+
@test eltype(b) === elt
345+
@test b isa BlockSparseVector{elt}
346+
@test blockstoredlength(b) == 1
347+
@test b[Block(1)] == a1
348+
@test iszero(b[Block(2)])
349+
@test all(GradedUnitRanges.space_isequal.(axes(b), (r,)))
335350
end
336351
end
337352
end

0 commit comments

Comments
 (0)