Skip to content

Commit 3dcdd20

Browse files
committed
clean new implementation
1 parent efe1c7c commit 3dcdd20

File tree

1 file changed

+1
-64
lines changed

1 file changed

+1
-64
lines changed

NDTensors/src/lib/GradedAxes/src/gradedunitrange.jl

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,6 @@ function space_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange)
6363
return (isdual(a1) == isdual(a2)) && labelled_isequal(a1, a2)
6464
end
6565

66-
# This is only needed in certain Julia versions below 1.10
67-
# (for example Julia 1.6).
68-
# TODO: Delete this once we drop Julia 1.6 support.
69-
# The type constraint `T<:Integer` is needed to avoid an ambiguity
70-
# error with a conversion method in Base.
71-
function Base.UnitRange{T}(
72-
a::AbstractGradedUnitRange{<:LabelledInteger{T}}
73-
) where {T<:Integer}
74-
return UnitRange(unlabel_blocks(a))
75-
end
76-
77-
# This is only needed in certain Julia versions below 1.10
78-
# (for example Julia 1.6).
79-
# TODO: Delete this once we drop Julia 1.6 support.
80-
# The type constraint `T<:Integer` is needed to avoid an ambiguity
81-
# error with a conversion method in Base.
82-
using BlockArrays: BlockSlice
83-
function Base.UnitRange{T}(
84-
a::BlockSlice{<:Any,<:LabelledInteger{T},<:AbstractUnitRange{<:LabelledInteger{T}}}
85-
) where {T<:Integer}
86-
return UnitRange{T}(a.indices)
87-
end
88-
8966
# TODO: See if this is needed.
9067
function Base.AbstractUnitRange{T}(a::GradedOneTo{<:LabelledInteger{T}}) where {T}
9168
return unlabel_blocks(a)
@@ -107,17 +84,6 @@ end
10784

10885
Base.last(a::AbstractGradedUnitRange) = isempty(a.lasts) ? first(a) - 1 : last(a.lasts)
10986

110-
# TODO: This needs to be defined to circumvent an issue
111-
# in the `BlockArrays.BlocksView` constructor. This
112-
# is likely caused by issues around `BlockedUnitRange` constraining
113-
# the element type to be `Int`, which is being fixed in:
114-
# https://github.com/JuliaArrays/BlockArrays.jl/pull/337
115-
# Remove this definition once that is fixed.
116-
function BlockArrays.blocks(a::AbstractGradedUnitRange)
117-
# TODO: Fix `BlockRange`, try using `BlockRange` instead.
118-
return [a[Block(i)] for i in 1:blocklength(a)]
119-
end
120-
12187
function gradedrange(lblocklengths::AbstractVector{<:Pair{<:Any,<:Integer}})
12288
return gradedrange(labelled.(last.(lblocklengths), first.(lblocklengths)))
12389
end
@@ -182,14 +148,6 @@ end
182148
# TODO: This relies on internals of `BlockArrays`, maybe redesign
183149
# to try to avoid that.
184150
# TODO: Define `set_grades`, `set_sector_labels`, `set_labels`.
185-
function unlabel_blocks(a::BlockedOneTo)
186-
# TODO: Use `blocklasts(a)`.
187-
return BlockedOneTo(unlabel.(a.lasts))
188-
end
189-
function unlabel_blocks(a::BlockedUnitRange)
190-
return BlockArrays._BlockedUnitRange(a.first, unlabel.(a.lasts))
191-
end
192-
193151
function unlabel_blocks(a::GradedOneTo)
194152
# TODO: Use `blocklasts(a)`.
195153
return BlockedOneTo(unlabel.(a.lasts))
@@ -209,10 +167,7 @@ end
209167
function gradedunitrange_blockfirsts(a::AbstractGradedUnitRange)
210168
return labelled.(blockfirsts(unlabel_blocks(a)), blocklabels(a))
211169
end
212-
function BlockArrays.blockfirsts(a::GradedUnitRange)
213-
return gradedunitrange_blockfirsts(a)
214-
end
215-
function BlockArrays.blockfirsts(a::GradedOneTo)
170+
function BlockArrays.blockfirsts(a::AbstractGradedUnitRange)
216171
return gradedunitrange_blockfirsts(a)
217172
end
218173

@@ -243,8 +198,6 @@ function firstblockindices(a::AbstractGradedUnitRange)
243198
end
244199

245200
function gradedunitrange_getindices(a::AbstractGradedUnitRange, index)
246-
# This uses `blocklasts` since that is what is stored
247-
# in `BlockedUnitRange`, maybe abstract that away.
248201
return labelled(unlabel_blocks(a)[index], get_label(a, index))
249202
end
250203

@@ -269,11 +222,6 @@ function gradedunitrange_getindices(
269222
return blockedunitrange_getindices(a, indices)
270223
end
271224

272-
# Fixes ambiguity error with:
273-
# ```julia
274-
# gradedunitrange_getindices(::GradedUnitRange, ::AbstractUnitRange{<:Integer})
275-
# ```
276-
# TODO: Try removing once GradedAxes is rewritten for BlockArrays v1.
277225
function gradedunitrange_getindices(a::AbstractGradedUnitRange, indices::BlockSlice)
278226
return a[indices.block]
279227
end
@@ -287,8 +235,6 @@ function gradedunitrange_getindices(a::AbstractGradedUnitRange, indices::BlockIn
287235
end
288236

289237
function Base.getindex(a::AbstractGradedUnitRange, index::Integer)
290-
# This uses `blocklasts` since that is what is stored
291-
# in `BlockedUnitRange`, maybe abstract that away.
292238
return labelled(unlabel_blocks(a)[index], get_label(a, index))
293239
end
294240

@@ -306,13 +252,6 @@ function Base.getindex(
306252
return gradedunitrange_getindices(a, indices)
307253
end
308254

309-
# Fixes ambiguity error with `BlockArrays`.
310-
function Base.getindex(
311-
a::AbstractGradedUnitRange, indices::BlockRange{1,Tuple{Base.OneTo{Int}}}
312-
)
313-
return gradedunitrange_getindices(a, indices)
314-
end
315-
316255
function Base.getindex(a::AbstractGradedUnitRange, indices::BlockIndex{1})
317256
return gradedunitrange_getindices(a, indices)
318257
end
@@ -324,8 +263,6 @@ end
324263
# getindex(::GradedUnitRange, ::Any)
325264
# getindex(::AbstractUnitRange, ::AbstractUnitRange{<:Integer})
326265
# ```
327-
# TODO: Maybe not needed once GradedAxes is rewritten
328-
# for BlockArrays v1.
329266
function Base.getindex(a::AbstractGradedUnitRange, indices::BlockSlice)
330267
return gradedunitrange_getindices(a, indices)
331268
end

0 commit comments

Comments
 (0)