Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Components.items: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 30, 2022
1 parent 12be2d9 commit 4958211
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/sage/tensor/modules/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,40 @@ def _set_value_list(self, ind, format_type, val):
for i in range(si, nsi):
self._set_value_list(ind + [i], format_type, val[i-si])

def items(self):
r"""
Return an iterable of ``(indices, value)`` elements.
This may (but is not guaranteed to) suppress zero values.
EXAMPLES::
sage: from sage.tensor.modules.comp import Components, CompWithSym
sage: c = Components(ZZ, (ZZ^2).basis(), 3)
sage: c[0,1,0], c[1,0,1], c[1,1,1] = -2, 5, 3
sage: list(c.items())
[((0, 1, 0), -2), ((1, 0, 1), 5), ((1, 1, 1), 3)]
sage: c = CompWithSym(ZZ, (ZZ^2).basis(), 3, sym=((1, 2)))
sage: c[0,1,0], c[1,0,1], c[1,1,1] = -2, 5, 3
sage: list(c.items())
[((0, 0, 1), -2),
((0, 1, 0), -2),
((1, 0, 1), 5),
((1, 1, 0), 5),
((1, 1, 1), 3)]
"""
for ind in self.index_generator():
val = self[ind]
if hasattr(val, 'is_trivial_zero'):
zero_value = val.is_trivial_zero()
else:
zero_value = val == 0
if not zero_value:
yield ind, val

def display(self, symbol, latex_symbol=None, index_positions=None,
index_labels=None, index_latex_labels=None,
format_spec=None, only_nonzero=True, only_nonredundant=False):
Expand Down

0 comments on commit 4958211

Please sign in to comment.