Skip to content

Commit 229412c

Browse files
committed
fix test
1 parent 75be561 commit 229412c

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ end
5757
function blockedunitrange_getindices(
5858
a::GradedUnitRangeDual, indices::Vector{<:BlockIndexRange{1}}
5959
)
60-
# flip v to stay consistent with other cases where axes(v) are used
60+
# dual v axes to stay consistent with other cases where axes(v) are used
6161
return dual_axes(blockedunitrange_getindices(nondual(a), indices))
6262
end
6363

6464
function blockedunitrange_getindices(
6565
a::GradedUnitRangeDual,
6666
indices::BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}},
6767
)
68-
# flip v axis to preserve dual information
68+
# dual v axis to preserve dual information
6969
# axes(v) will appear in axes(view(::BlockSparseArray, [Block(1)[1:1]]))
7070
return dual_axes(blockedunitrange_getindices(nondual(a), indices))
7171
end
7272

7373
function blockedunitrange_getindices(
7474
a::GradedUnitRangeDual, indices::AbstractVector{<:Union{Block{1},BlockIndexRange{1}}}
7575
)
76-
# flip v axis to preserve dual information
76+
# dual v axis to preserve dual information
7777
# axes(v) will appear in axes(view(::BlockSparseArray, [Block(1)]))
7878
return dual_axes(blockedunitrange_getindices(nondual(a), indices))
7979
end
@@ -82,7 +82,10 @@ end
8282
function blockedunitrange_getindices(
8383
a::GradedUnitRangeDual, indices::AbstractBlockVector{<:Block{1}}
8484
)
85-
return dual_axes(blockedunitrange_getindices(nondual(a), indices))
85+
v = blockedunitrange_getindices(nondual(a), indices)
86+
# v elements are not dualled by dual_axes due to different structure.
87+
# take element dual here.
88+
return dual_axes(dual.(v))
8689
end
8790

8891
function dual_axes(v::BlockVector)

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,35 @@ end
219219
@test label(ad[Block(2)]) == U1(-1)
220220
@test label(ad[Block(2)[1:1]]) == U1(-1)
221221

222-
I = mortar([Block(2)[1:1]])
223-
g = ad[I]
224-
@test length(g) == 1
225-
@test label(first(g)) == U1(-1)
226-
@test isdual(g[Block(1)])
222+
v = ad[mortar([Block(2)[1:1]])]
223+
@test v isa AbstractVector{LabelledInteger{Int64,U1}}
224+
@test length(v) == 1
225+
@test label(first(v)) == U1(-1)
226+
@test unlabel(first(v)) == 3
227+
@test isdual(v[Block(1)])
228+
@test isdual(axes(v, 1))
229+
@test blocklabels(axes(v, 1)) == [U1(-1)]
227230

228-
@test isdual(axes(ad[[Block(1)]], 1)) # used in view(::BlockSparseVector, [Block(1)])
229-
@test isdual(axes(ad[mortar([Block(1)[1:1]])], 1)) # used in view(::BlockSparseVector, [Block(1)[1:1]])
230-
@test isdual(axes(ad[mortar([[Block(1)], [Block(2)]])]))
231+
v = ad[[Block(2)]]
232+
@test v isa AbstractVector{LabelledInteger{Int64,U1}}
233+
@test isdual(axes(v, 1)) # used in view(::BlockSparseVector, [Block(1)])
234+
@test label(first(v)) == U1(-1)
235+
@test unlabel(first(v)) == 3
236+
@test blocklabels(axes(v, 1)) == [U1(-1)]
237+
238+
v = ad[mortar([Block(2)[1:1]])]
239+
@test v isa AbstractVector{LabelledInteger{Int64,U1}}
240+
@test isdual(axes(v, 1)) # used in view(::BlockSparseVector, [Block(1)[1:1]])
241+
@test label(first(v)) == U1(-1)
242+
@test unlabel(first(v)) == 3
243+
@test blocklabels(axes(v, 1)) == [U1(-1)]
244+
245+
v = ad[mortar([[Block(2)], [Block(1)]])]
246+
@test v isa AbstractVector{LabelledInteger{Int64,U1}}
247+
@test isdual(axes(v, 1))
248+
@test label(first(v)) == U1(-1)
249+
@test unlabel(first(v)) == 3
250+
@test blocklabels(axes(v, 1)) == [U1(-1), U1(0)]
231251
end
232252
end
233253

0 commit comments

Comments
 (0)