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

Commit

Permalink
FreeModule_generic.some_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Aug 25, 2016
1 parent a8e6334 commit 520aaf1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,58 @@ def _an_element_(self):
except ValueError:
return self(0)

def some_elements(self):
r"""
Return some elements of this free module.
See :class:`TestSuite` for a typical use case.
OUTPUT:
An iterator.
EXAMPLES::
sage: F = FreeModule(ZZ, 2)
sage: tuple(F.some_elements())
((1, 0),
(1, 1),
(0, 1),
(-1, 2),
(-2, 3),
...
(-49, 50))
sage: F = FreeModule(QQ, 3)
sage: tuple(F.some_elements())
((1, 0, 0),
(1/2, 1/2, 1/2),
(1/2, -1/2, 2),
(-2, 0, 1),
(-1, 42, 2/3),
(-2/3, 3/2, -3/2),
(4/5, -4/5, 5/4),
...
(46/103823, -46/103823, 103823/46))
sage: F = FreeModule(SR, 2)
sage: tuple(F.some_elements())
((1, 0), (some_variable, some_variable))
"""
from itertools import islice
yield self.an_element()
yield self.base().an_element() * sum(self.gens())
some_elements_base = iter(self.base().some_elements())
n = self.degree()
while True:
L = list(islice(some_elements_base, n))
if len(L) != n:
return
try:
yield self(L)
except TypeError, ValueError:
pass

def _element_constructor_(self, x, coerce=True, copy=True, check=True):
r"""
Create an element of this free module from ``x``.
Expand Down

0 comments on commit 520aaf1

Please sign in to comment.