Skip to content

Commit

Permalink
define blocklabels(::LabelledUnitRange)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogauthe committed Nov 7, 2024
1 parent 64cbffb commit 027465d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ end
# == is just a range comparison that ignores labels. Need dedicated function to check equality.
struct NoLabel end
blocklabels(r::AbstractUnitRange) = Fill(NoLabel(), blocklength(r))
blocklabels(la::LabelledUnitRange) = label(la)

function LabelledNumbers.labelled_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange)
return blockisequal(a1, a2) && (blocklabels(a1) == blocklabels(a2))
Expand Down
1 change: 1 addition & 0 deletions NDTensors/src/lib/GradedAxes/src/labelledunitrangedual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nondual(a::LabelledUnitRangeDual) = a.nondual_unitrange
dual(a::LabelledUnitRangeDual) = nondual(a)
flip(a::LabelledUnitRangeDual) = dual(flip(nondual(a)))
isdual(::LabelledUnitRangeDual) = true
blocklabels(la::LabelledUnitRangeDual) = label(la)

LabelledNumbers.label(a::LabelledUnitRangeDual) = dual(label(nondual(a)))
LabelledNumbers.unlabel(a::LabelledUnitRangeDual) = unlabel(nondual(a))
Expand Down
15 changes: 15 additions & 0 deletions NDTensors/src/lib/GradedAxes/test/test_dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ end
@test label(lad) == U1(-1)
@test unlabel(lad) == 1:2
@test lad == 1:2
@test !labelled_isequal(la, lad)
@test !space_isequal(la, lad)
@test isdual(lad)
@test nondual(lad) === la
@test dual(lad) === la

# check default behavior for objects without dual
la = labelled(1:2, 'x')
lad = dual(la)
@test lad isa LabelledUnitRangeDual
@test label(lad) == 'x'
@test unlabel(lad) == 1:2
@test lad == 1:2
@test labelled_isequal(la, lad)
@test !space_isequal(la, lad)
@test isdual(lad)
@test nondual(lad) === la
@test dual(lad) === la
Expand Down

0 comments on commit 027465d

Please sign in to comment.