Skip to content

stride/strides signature too broad? #17812

@timholy

Description

@timholy

The docstring for stride:

help?> stride
search: stride strides StridedArray StridedVector StridedMatrix StridedVecOrMat strwidth SymTridiagonal

  stride(A, k)

  Returns the distance in memory (in number of elements) between adjacent elements in dimension k.

specifies "in memory", but the signature for stride is stride(a::AbstractArray, i::Integer), and some AbstractArrays do not even store their values in memory:

julia> stride(1:5, 1)
1

julia> isa(1:5, StridedArray)
false

Should we change it to StridedArray? The biggest problem with this is that StridedArray was the motivating poster child for the desirability of traits, because StridedArray cannot be extended to user types.

We could introduce an IsStrided trait,

strided(A::StridedArray) = IsStrided()
strided(A) = NotStrided()

and dispatch on it for strides and stride. But then that implicitly places some expectation that the linear algebra code might switch to the trait rather than dispatching on StridedArray, and that's a lot of code to modify. So I didn't want to do this lightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions