@@ -63,29 +63,6 @@ function space_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange)
6363 return (isdual (a1) == isdual (a2)) && labelled_isequal (a1, a2)
6464end
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.
9067function Base. AbstractUnitRange {T} (a:: GradedOneTo{<:LabelledInteger{T}} ) where {T}
9168 return unlabel_blocks (a)
10784
10885Base. 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-
12187function gradedrange (lblocklengths:: AbstractVector{<:Pair{<:Any,<:Integer}} )
12288 return gradedrange (labelled .(last .(lblocklengths), first .(lblocklengths)))
12389end
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-
193151function unlabel_blocks (a:: GradedOneTo )
194152 # TODO : Use `blocklasts(a)`.
195153 return BlockedOneTo (unlabel .(a. lasts))
209167function gradedunitrange_blockfirsts (a:: AbstractGradedUnitRange )
210168 return labelled .(blockfirsts (unlabel_blocks (a)), blocklabels (a))
211169end
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)
217172end
218173
@@ -243,8 +198,6 @@ function firstblockindices(a::AbstractGradedUnitRange)
243198end
244199
245200function 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))
249202end
250203
@@ -269,11 +222,6 @@ function gradedunitrange_getindices(
269222 return blockedunitrange_getindices (a, indices)
270223end
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.
277225function gradedunitrange_getindices (a:: AbstractGradedUnitRange , indices:: BlockSlice )
278226 return a[indices. block]
279227end
@@ -287,8 +235,6 @@ function gradedunitrange_getindices(a::AbstractGradedUnitRange, indices::BlockIn
287235end
288236
289237function 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))
293239end
294240
@@ -306,13 +252,6 @@ function Base.getindex(
306252 return gradedunitrange_getindices (a, indices)
307253end
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-
316255function Base. getindex (a:: AbstractGradedUnitRange , indices:: BlockIndex{1} )
317256 return gradedunitrange_getindices (a, indices)
318257end
324263# getindex(::GradedUnitRange, ::Any)
325264# getindex(::AbstractUnitRange, ::AbstractUnitRange{<:Integer})
326265# ```
327- # TODO : Maybe not needed once GradedAxes is rewritten
328- # for BlockArrays v1.
329266function Base. getindex (a:: AbstractGradedUnitRange , indices:: BlockSlice )
330267 return gradedunitrange_getindices (a, indices)
331268end
0 commit comments