Skip to content

Move vector_random() to free_module.py with doctests #40344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
# https://www.gnu.org/licenses/
###########################################################################



import itertools
from warnings import warn

Expand Down Expand Up @@ -223,6 +225,21 @@
#
###############################################################################

def vector_random(R, n, *args, **kwargs):
r"""
Return a random element of the free module of rank ``n`` over ``R``.

EXAMPLES::

sage: from sage.modules.free_module import vector_random
sage: v = vector_random(ZZ, 3)
sage: len(v)
3
sage: v.parent().base_ring() is ZZ
True
"""
return FreeModule(R, n).random_element(*args, **kwargs)


class FreeModuleFactory(UniqueFactory):
r"""
Expand All @@ -233,6 +250,7 @@ def create_key(self, base_ring, rank, sparse=False, inner_product_matrix=None):
TESTS::

sage: loads(dumps(ZZ^6)) is ZZ^6

True
sage: loads(dumps(RDF^3)) is RDF^3
True
Expand Down