Skip to content

StaticArray types with cartesian index style #649

Open
@TheBB

Description

@TheBB

I was trying to create a new static array type (an unsafe strided statically-sized view - or USS View for short). Because of the strided this type must have a cartesian index style. Most of the generated functions in StaticArrays generate code with linear indexing. Unfortunately, splitting a linear index to a cartesian one is fairly slow.

Ideally one could generate code using linear indexing for linear-indexable types and cartesian indexing for cartesian-indexable types. I tried to write a patch like this, but it turns out that generated (that is, generator) functions run in an older world and can't see new methods to Base.IndexStyle. Ouch.

So if there's interest in supporting external subtypes of StaticArray with different index styles, I believe this has to be encoded on the type level as a new parameter, i.e.

abstract type StaticArray{S, T, N, I<:IndexStyle} <: AbstractArray{T, N} end
Base.IndexStyle(::Type{StaticArray{S,T,N,I}}) where {S,T,N,I} = I()
struct SArray{S, T, N, L} <: StaticArray{S, T, N, IndexLinear} # .... etc

Is there interest in doing this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurefeatures and feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions