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

Commit

Permalink
Use normalize_names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Scrimshaw committed May 27, 2017
1 parent ad23fbd commit 1c1cad1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/sage/combinat/free_module.py
Expand Up @@ -300,7 +300,9 @@ def __classcall_private__(cls, base_ring, basis_keys=None, category=None,
if prefix is None:
prefix = "B"

return super(CombinatorialFreeModule, cls).__classcall__(cls, base_ring, basis_keys, category=category, prefix=prefix, names=names, **keywords)
return super(CombinatorialFreeModule, cls).__classcall__(cls,
base_ring, basis_keys, category=category, prefix=prefix, names=names,
**keywords)

# We make this explicitly a Python class so that the methods,
# specifically _mul_, from category framework still works. -- TCS
Expand Down
4 changes: 1 addition & 3 deletions src/sage/monoids/free_monoid.py
Expand Up @@ -131,9 +131,7 @@ def FreeMonoid(index_set=None, names=None, commutative=False, **kwds):

if index_set not in ZZ:
if names is not None:
if isinstance(names, str):
names = names.split(',')
names = normalize_names(len(names), names)
names = normalize_names(-1, names)
from sage.monoids.indexed_free_monoid import IndexedFreeMonoid
return IndexedFreeMonoid(index_set, names=names, **kwds)

Expand Down
38 changes: 17 additions & 21 deletions src/sage/structure/indexed_generators.py
Expand Up @@ -11,6 +11,7 @@

from sage.rings.all import Integer
from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
from sage.structure.category_object import normalize_names

class IndexedGenerators(object):
r"""nodetex
Expand Down Expand Up @@ -581,20 +582,18 @@ def parse_indices_names(indices, names, prefix, kwds={}):
if indices is None:
if names is None:
raise ValueError("either the indices or names must be given")
if isinstance(names, str):
names = names.split(',')
names = tuple(names)
names = normalize_names(-1, names)
indices = names

if prefix is None:
prefix =''
prefix = ''
if 'string_quotes' not in kwds:
kwds['string_quotes'] = False
if 'bracket' not in kwds:
kwds['bracket'] = False

if isinstance(indices, dict): # dict of {name: index} -- not likely to be used
names = indices.keys()
names = normalize_names(-1, tuple(indices.keys()))
indices = FiniteEnumeratedSet([indices[n] for n in names])
elif isinstance(indices, str):
indices = FiniteEnumeratedSet(list(indices))
Expand All @@ -605,7 +604,7 @@ def parse_indices_names(indices, names, prefix, kwds={}):

def standardize_names_index_set(names=None, index_set=None, ngens=None):
"""
Standardize the ``names`` and ``index_set`` for a Lie algebra.
Standardize the ``names`` and ``index_set`` inputs.
OUTPUT:
Expand Down Expand Up @@ -642,28 +641,25 @@ def standardize_names_index_set(names=None, index_set=None, ngens=None):
sage: standardize_names_index_set(['x'], ['a', 'b'])
Traceback (most recent call last):
...
ValueError: the number of names must equal the size of the indexing set
IndexError: the number of names must equal the size of the indexing set
sage: standardize_names_index_set('x,y', ['a'])
Traceback (most recent call last):
...
ValueError: the number of names must equal the size of the indexing set
IndexError: the number of names must equal the size of the indexing set
sage: standardize_names_index_set('x,y,z', ngens=2)
Traceback (most recent call last):
...
ValueError: the number of names must equal the number of generators
IndexError: the number of names must equal the number of generators
sage: standardize_names_index_set(index_set=['a'], ngens=2)
Traceback (most recent call last):
...
ValueError: the size of the indexing set must equal the number of generators
IndexError: the size of the indexing set must equal the number of generators
"""
if isinstance(names, str):
names = tuple(names.split(','))
elif names is not None:
names = tuple(names)

if names is not None and len(names) == 1 and ngens > 1:
letter = names[0]
names = tuple([letter + str(i) for i in range(ngens)])
if names is not None:
if ngens is None or ngens < 0:
names = normalize_names(-1, names)
else:
names = normalize_names(ngens, names)

if index_set is None:
if names is None:
Expand All @@ -683,12 +679,12 @@ def standardize_names_index_set(names=None, index_set=None, ngens=None):

if names is not None:
if len(names) != index_set.cardinality():
raise ValueError("the number of names must equal"
raise IndexError("the number of names must equal"
" the size of the indexing set")
if ngens is not None and len(names) != ngens:
raise ValueError("the number of names must equal the number of generators")
raise IndexError("the number of names must equal the number of generators")
elif ngens is not None and index_set.cardinality() != ngens:
raise ValueError("the size of the indexing set must equal"
raise IndexError("the size of the indexing set must equal"
" the number of generators")

return (names, index_set)
Expand Down

0 comments on commit 1c1cad1

Please sign in to comment.