Skip to content

Matrix and Components should have a sparse iterator #29619

@mwageringel

Description

@mwageringel

As observed on this Ask SageMath question, it does not seem to be possible to iterate over the non-zero entries of a tensor. This is unfortunate because the entries are stored in a sparse format, in a dictionary.

Since a tensor might have symmetries, this is more involved than just iterating over the dictionary, but such an iterator would immediately be useful for the implementation of the display() method, for instance.

Here we implement a method Components.items, returning an iterable of (indices, value). This is compatible with the sparse and dense vectors from sage.modules.

(Because a Components does not currently have a parent, it does not make sense to define the method monomial_coefficients - as defined by ModulesWithBasis.)

We also define Matrix.items with the same interface.

CC: @egourgoulhon @LBrunswic @honglizhaobob @tscrim

Component: linear algebra

Author: Matthias Koeppe

Branch/Commit: 74d9493

Reviewer: Eric Gourgoulhon

Issue created by migration from https://trac.sagemath.org/ticket/29619

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions