Skip to content

Support for-loop iteration over 1-dim memory views #2227

Description

@scoder

Currently, efficient iteration over a memory views axis requires indexing. Iterating with a for-in-loop should result in the same code.

Convert the loop in IterationTransform._optimise_for_loop() in Optimize.py, similar to the range optimisation.

Additional idea: for multi-dimensional views, the iteration could yield borrowed slices, with their lifetime bound to the current loop iteration. That would avoid the refcounting overhead for them, which can hurt for very small slices (as found in #2987). Iteration seems to provide a natural frame for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions