Skip to content

Commit e716903

Browse files
committed
use GradedAxes interface
1 parent 032bde4 commit e716903

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ Base.step(a::GradedUnitRangeDual) = label_dual(step(nondual(a)))
1717

1818
Base.view(a::GradedUnitRangeDual, index::Block{1}) = a[index]
1919

20-
function Base.getindex(a::GradedUnitRangeDual, indices::AbstractUnitRange{<:Integer})
20+
function gradedunitrange_getindices(
21+
a::GradedUnitRangeDual, indices::AbstractUnitRange{<:Integer}
22+
)
2123
return dual(getindex(nondual(a), indices))
2224
end
2325

2426
using BlockArrays: Block, BlockIndexRange, BlockRange
2527

26-
function Base.getindex(a::GradedUnitRangeDual, indices::Integer)
28+
function gradedunitrange_getindices(a::GradedUnitRangeDual, indices::Integer)
2729
return label_dual(getindex(nondual(a), indices))
2830
end
2931

30-
function Base.getindex(a::GradedUnitRangeDual, indices::Block{1})
32+
function gradedunitrange_getindices(a::GradedUnitRangeDual, indices::Block{1})
3133
return label_dual(getindex(nondual(a), indices))
3234
end
3335

34-
function Base.getindex(a::GradedUnitRangeDual, indices::BlockRange)
36+
function gradedunitrange_getindices(a::GradedUnitRangeDual, indices::BlockRange)
3537
return label_dual(getindex(nondual(a), indices))
3638
end
3739

3840
# fix ambiguity
39-
function Base.getindex(
41+
function gradedunitrange_getindices(
4042
a::GradedUnitRangeDual, indices::BlockRange{1,<:Tuple{AbstractUnitRange{Int}}}
4143
)
4244
return dual(getindex(nondual(a), indices))
@@ -52,15 +54,13 @@ function unitrangedual_getindices_blocks(a::GradedUnitRangeDual, indices)
5254
end
5355

5456
# TODO: Move this to a `BlockArraysExtensions` library.
55-
function blockedunitrange_getindices(a::GradedUnitRangeDual, indices::Block{1})
56-
return a[indices]
57-
end
58-
59-
function Base.getindex(a::GradedUnitRangeDual, indices::Vector{<:Block{1}})
57+
function gradedunitrange_getindices(a::GradedUnitRangeDual, indices::Vector{<:Block{1}})
6058
return unitrangedual_getindices_blocks(a, indices)
6159
end
6260

63-
function Base.getindex(a::GradedUnitRangeDual, indices::Vector{<:BlockIndexRange{1}})
61+
function gradedunitrange_getindices(
62+
a::GradedUnitRangeDual, indices::Vector{<:BlockIndexRange{1}}
63+
)
6464
return unitrangedual_getindices_blocks(a, indices)
6565
end
6666

@@ -79,16 +79,10 @@ function BlockArrays.BlockSlice(b::Block, r::GradedUnitRangeDual)
7979
end
8080

8181
using NDTensors.LabelledNumbers: LabelledNumbers, LabelledUnitRange, label
82-
# The Base version of `length(::AbstractUnitRange)` drops the label.
83-
function Base.length(a::GradedUnitRangeDual{<:Any,<:LabelledUnitRange})
84-
return dual(length(nondual(a)))
85-
end
8682
function Base.iterate(a::GradedUnitRangeDual, i)
8783
i == last(a) && return nothing
8884
return dual.(iterate(nondual(a), i))
8985
end
90-
# TODO: Is this a good definition?
91-
Base.unitrange(a::GradedUnitRangeDual) = a
9286

9387
using NDTensors.LabelledNumbers: LabelledInteger, label, labelled, unlabel
9488
using BlockArrays: BlockArrays, blockaxes, blocklasts, combine_blockaxes, findblock

0 commit comments

Comments
 (0)