Skip to content

Commit b2fd32b

Browse files
committed
fix slicing BlockSparseArrays
1 parent 24fb3c8 commit b2fd32b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using BlockArrays:
2020
findblockindex
2121
using Compat: allequal
2222
using Dictionaries: Dictionary, Indices
23-
using ..GradedAxes: blockedunitrange_getindices, to_blockindices
23+
using ..GradedAxes: blockedunitrange_getindices, gradedunitrange_getindices, to_blockindices
2424
using ..SparseArrayInterface: SparseArrayInterface, nstored, stored_indices
2525

2626
# A return type for `blocks(array)` when `array` isn't blocked.

NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
# https://github.com/ITensor/ITensors.jl/issues/1336.
3131
function blocksparse_to_indices(a, inds, I::Tuple{UnitRange{<:Integer},Vararg{Any}})
3232
bs1 = to_blockindices(inds[1], I[1])
33-
I1 = BlockSlice(bs1, blockedunitrange_getindices(inds[1], I[1]))
33+
I1 = BlockSlice(bs1, gradedunitrange_getindices(inds[1], I[1]))
3434
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
3535
end
3636

@@ -45,7 +45,7 @@ end
4545

4646
# a[[Block(2), Block(1)], [Block(2), Block(1)]]
4747
function blocksparse_to_indices(a, inds, I::Tuple{Vector{<:Block{1}},Vararg{Any}})
48-
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
48+
I1 = BlockIndices(I[1], gradedunitrange_getindices(inds[1], I[1]))
4949
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
5050
end
5151

@@ -54,7 +54,7 @@ end
5454
function blocksparse_to_indices(
5555
a, inds, I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}},Vararg{Any}}
5656
)
57-
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
57+
I1 = BlockIndices(I[1], gradedunitrange_getindices(inds[1], I[1]))
5858
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
5959
end
6060

@@ -64,7 +64,7 @@ end
6464
function blocksparse_to_indices(
6565
a, inds, I::Tuple{AbstractBlockVector{<:Block{1}},Vararg{Any}}
6666
)
67-
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
67+
I1 = BlockIndices(I[1], gradedunitrange_getindices(inds[1], I[1]))
6868
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
6969
end
7070

NDTensors/src/lib/GradedAxes/test/test_basics.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ using BlockArrays:
99
blocklasts,
1010
blocklength,
1111
blocklengths,
12-
blocks
12+
blocks,
13+
combine_blockaxes
1314
using NDTensors.GradedAxes: GradedOneTo, GradedUnitRange, OneToOne, blocklabels, gradedrange
1415
using NDTensors.LabelledNumbers:
1516
LabelledUnitRange, islabelled, label, labelled, labelled_isequal, unlabel
@@ -94,6 +95,8 @@ end
9495
@test length(a[Block(2)]) == 3
9596
@test blocklengths(only(axes(a))) == blocklengths(a)
9697
@test blocklabels(only(axes(a))) == blocklabels(a)
98+
99+
@test combine_blockaxes(a, a) isa GradedOneTo
97100
end
98101

99102
# Slicing operations

0 commit comments

Comments
 (0)