Skip to content

Definition of BlockUnitRange #373

@putianyi889

Description

@putianyi889

A single firsts field should work, where the last index of the range is firsts[end]-1. The advantages are:

  • The codes will become cleaner and the performance can be better. There are currently many conditional statements on the first block. The proposed definition eliminates them.
  • The type stability can be improved. Now blocklengths(::BlockUnitRange{<:AbstractUnitRange}) is clearly a Fill and blocklengths(::BlockUnitRange{<:AbstractRange}) is a Vcat(::Int,::Fill). reference:
    function blockfirsts(a::BlockedUnitRange{Base.OneTo{Int}})
    first(a) == 1 || error("Offset axes not supported")
    Base.OneTo{Int}(length(blocklasts(a)))
    end
    function blocklengths(a::BlockedUnitRange{Base.OneTo{Int}})
    first(a) == 1 || error("Offset axes not supported")
    Ones{Int}(length(blocklasts(a)))
    end
    function blockfirsts(a::BlockedUnitRange{<:AbstractRange})
    st = step(blocklasts(a))
    first(a) == 1 || error("Offset axes not supported")
    @assert first(blocklasts(a))-first(a)+1 == st
    range(1; step=st, length=length(blocklasts(a)))
    end
    function blocklengths(a::BlockedUnitRange{<:AbstractRange})
    st = step(blocklasts(a))
    first(a) == 1 || error("Offset axes not supported")
    @assert first(blocklasts(a))-first(a)+1 == st
    Fill(st,length(blocklasts(a)))
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions