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

Commit

Permalink
src/sage/tensor: Allow _sym, _antisym attributes to be tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Aug 29, 2022
1 parent 3a65d2d commit 07ab991
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/sage/manifolds/differentiable/tensorfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,13 @@ def symmetries(self):
elif len(self._sym) == 1:
s = "symmetry: {}; ".format(self._sym[0])
else:
s = "symmetries: {}; ".format(self._sym)
s = "symmetries: {}; ".format(list(self._sym))
if not self._antisym:
a = "no antisymmetry"
elif len(self._antisym) == 1:
a = "antisymmetry: {}".format(self._antisym[0])
else:
a = "antisymmetries: {}".format(self._antisym)
a = "antisymmetries: {}".format(list(self._antisym))
print(s + a)

#### End of simple accessors #####
Expand Down
26 changes: 18 additions & 8 deletions src/sage/tensor/modules/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,12 +1773,12 @@ def __mul__(self, other):
"same starting index")
if isinstance(other, CompWithSym):
sym = []
if other._sym != []:
if other._sym:
for s in other._sym:
ns = tuple(s[i]+self._nid for i in range(len(s)))
sym.append(ns)
antisym = []
if other._antisym != []:
if other._antisym:
for s in other._antisym:
ns = tuple(s[i]+self._nid for i in range(len(s)))
antisym.append(ns)
Expand Down Expand Up @@ -3011,7 +3011,12 @@ def _canonicalize_sym_antisym(nb_indices, sym=None, antisym=None):
([(2, 1)], [])
"""
result_sym = []
if sym is not None and sym != []:
if sym is None:
sym = []
else:
# Handle the case that sym is an iterator
sym = list(sym)
if sym:
if isinstance(sym[0], (int, Integer)):
# a single symmetry is provided as a tuple or a range object;
# it is converted to a 1-item list:
Expand All @@ -3026,7 +3031,12 @@ def _canonicalize_sym_antisym(nb_indices, sym=None, antisym=None):
" not in [0," + str(nb_indices-1) + "]")
result_sym.append(tuple(isym))
result_antisym = []
if antisym is not None and antisym != []:
if antisym is None:
antisym = []
else:
# Handle the case that antisym is an iterator
antisym = list(antisym)
if antisym:
if isinstance(antisym[0], (int, Integer)):
# a single antisymmetry is provided as a tuple or a range
# object; it is converted to a 1-item list:
Expand Down Expand Up @@ -3535,7 +3545,7 @@ def paral_sum(a, b, local_list_ind):
com = tuple(set(isym).intersection(set(osym)))
if len(com) > 1:
common_antisym.append(com)
if common_sym != [] or common_antisym != []:
if common_sym or common_antisym:
result = CompWithSym(self._ring, self._frame, self._nid,
self._sindex, self._output_formatter,
common_sym, common_antisym)
Expand Down Expand Up @@ -3643,11 +3653,11 @@ def __mul__(self, other):
sym = list(self._sym)
antisym = list(self._antisym)
if isinstance(other, CompWithSym):
if other._sym != []:
if other._sym:
for s in other._sym:
ns = tuple(s[i]+self._nid for i in range(len(s)))
sym.append(ns)
if other._antisym != []:
if other._antisym:
for s in other._antisym:
ns = tuple(s[i]+self._nid for i in range(len(s)))
antisym.append(ns)
Expand Down Expand Up @@ -3973,7 +3983,7 @@ def non_redundant_index_generator(self):
si = self._sindex
imax = self._dim - 1 + si
ind = [si for k in range(self._nid)]
sym = self._sym.copy() # we may modify this in the following
sym = list(self._sym) # we may modify this in the following
antisym = self._antisym
for pos in range(self._nid):
for isym in antisym:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/tensor/modules/free_module_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ def symmetries(self):
elif len(self._sym) == 1:
s = "symmetry: {}; ".format(self._sym[0])
else:
s = "symmetries: {}; ".format(self._sym)
s = "symmetries: {}; ".format(list(self._sym))
if len(self._antisym) == 0:
a = "no antisymmetry"
elif len(self._antisym) == 1:
a = "antisymmetry: {}".format(self._antisym[0])
else:
a = "antisymmetries: {}".format(self._antisym)
a = "antisymmetries: {}".format(list(self._antisym))
print(s+a)

#### End of simple accessors #####
Expand Down

0 comments on commit 07ab991

Please sign in to comment.