Skip to content

Base.getindex producing a view #42

Description

@lkdvos

Currently, the behavior of StridedView is such that getindex is secretely producing a view, which is either a slight abuse of notation or some type of piracy on the Base behavior.

The docs for AbstractArray state:

"""
    getindex(A, inds...)

Return a subset of array A as selected by the indices inds.

Each index may be any supported index type, such as an Integer, CartesianIndex, range, or array of supported indices. A : may be used to select all elements along a specific dimension, and a boolean array (e.g. an `Array{Bool}` or a `BitArray`) may be used to filter for elements where the corresponding index is true.

When inds selects multiple elements, this function returns a newly allocated array. To index multiple elements without making a copy, use `view` instead.

See the manual section on array indexing for details.
"""

While this would be a painful breaking change, it might be worth it to follow this behavior a bit closer, since this leads to unexpected issues in generic AbstractArray implementations that make assumptions about modifying behavior.
See e.g. QuantumKitHub/MatrixAlgebraKit.jl#226

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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