Skip to content

Commit d0c02bd

Browse files
committed
define flip_blockvector
1 parent 0216abc commit d0c02bd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

NDTensors/src/lib/GradedAxes/src/gradedunitrangedual.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,11 @@ function blockedunitrange_getindices(
6565
a::GradedUnitRangeDual,
6666
indices::BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}},
6767
)
68-
arr = mortar(map(b -> a[b], blocks(indices)))
68+
v = mortar(map(b -> a[b], blocks(indices)))
6969
# GradedOneTo appears in mortar
7070
# flip arr axis to preserve dual information
7171
# axes(arr) will appear in axes(view(::BlockSparseArray, [Block(1)[1:1]]))
72-
# TODO way to create BlockArray with specified axis without relying on internal?
73-
block_axes = (flip(only(axes(arr))),)
74-
flipped = BlockArrays._BlockArray(vec.(blocks(arr)), block_axes)
75-
return flipped
72+
return flip_blockvector(v)
7673
end
7774

7875
function blockedunitrange_getindices(
@@ -88,12 +85,16 @@ function blockedunitrange_getindices(
8885
# `only(axes(a[indices])) isa `GradedUnitRange`
8986
# if `a isa `GradedUnitRange`, for example.
9087

91-
arr = mortar(vblocks, length.(vblocks))
88+
v = mortar(vblocks, length.(vblocks))
9289
# GradedOneTo appears in mortar
9390
# axes(arr) will appear in axes(view(::BlockSparseArray, [Block(1)[1:1]]))
91+
return flip_blockvector(v)
92+
end
93+
94+
function flip_blockvector(v::BlockVector)
9495
# TODO way to create BlockArray with specified axis without relying on internal?
95-
block_axes = (flip(only(axes(arr))),)
96-
flipped = BlockArrays._BlockArray(vec.(blocks(arr)), block_axes)
96+
block_axes = flip.(axes(v))
97+
flipped = BlockArrays._BlockArray(vec.(blocks(v)), block_axes)
9798
return flipped
9899
end
99100

0 commit comments

Comments
 (0)