Skip to content

Commit

Permalink
Reduce the number of convert methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 22, 2024
1 parent ff094f7 commit ac0b14e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/blockaxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,14 @@ Base.unitrange(b::AbstractBlockedUnitRange) = first(b):last(b)

Base.promote_rule(::Type{<:AbstractBlockedUnitRange}, ::Type{Base.OneTo{Int}}) = UnitRange{Int}

Base.convert(::Type{BlockedOneTo}, axis::BlockedOneTo) = axis
_convert(::Type{BlockedOneTo}, axis::AbstractBlockedUnitRange) = BlockedOneTo(blocklasts(axis))
_convert(::Type{BlockedOneTo}, axis::AbstractUnitRange{Int}) = BlockedOneTo(last(axis):last(axis))
function Base.convert(::Type{BlockedOneTo}, axis::AbstractUnitRange{Int})
first(axis) == 1 || throw(ArgumentError("first element of range is not 1"))
_convert(BlockedOneTo, axis)
BlockedOneTo(blocklasts(axis))
end
function Base.convert(::Type{BlockedOneTo{CS}}, axis::AbstractUnitRange{Int}) where CS
first(axis) == 1 || throw(ArgumentError("first element of range is not 1"))
BlockedOneTo(convert(CS, blocklasts(axis)))
end
Base.convert(::Type{BlockedOneTo{CS}}, axis::BlockedOneTo{CS}) where CS = axis
Base.convert(::Type{BlockedOneTo{CS}}, axis::BlockedOneTo) where CS = BlockedOneTo(convert(CS, blocklasts(axis)))
Base.convert(::Type{BlockedOneTo{CS}}, axis::AbstractUnitRange{Int}) where CS = convert(BlockedOneTo{CS}, convert(BlockedOneTo, axis))

"""
blockaxes(A::AbstractArray)
Expand Down

0 comments on commit ac0b14e

Please sign in to comment.