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

Commit

Permalink
CompWithSym._canonicalize_sym_antisym: Sort earlier to validate indic…
Browse files Browse the repository at this point in the history
…es faster
  • Loading branch information
Matthias Koeppe committed Sep 1, 2022
1 parent ffea896 commit fed09d5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/sage/tensor/modules/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3054,11 +3054,11 @@ def _canonicalize_sym_antisym(nb_indices, sym=None, antisym=None, *,
else:
# Drop trivial symmetry
continue
for i in isym:
if i < 0 or i > nb_indices - 1:
raise IndexError("invalid index position: " + str(i) +
" not in [0," + str(nb_indices-1) + "]")
result_sym.append(tuple(isym))
isym = tuple(sorted(isym))
if isym[0] < 0 or isym[-1] > nb_indices - 1:
raise IndexError("invalid index position: " + str(i) +
" not in [0," + str(nb_indices-1) + "]")
result_sym.append(isym)
result_antisym = []
if antisym is None:
antisym = []
Expand All @@ -3078,11 +3078,11 @@ def _canonicalize_sym_antisym(nb_indices, sym=None, antisym=None, *,
else:
# Drop trivial antisymmetry
continue
for i in isym:
if i < 0 or i > nb_indices - 1:
raise IndexError("invalid index position: " + str(i) +
" not in [0," + str(nb_indices - 1) + "]")
result_antisym.append(tuple(isym))
isym = tuple(sorted(isym))
if isym[0] < 0 or isym[-1] > nb_indices - 1:
raise IndexError("invalid index position: " + str(i) +
" not in [0," + str(nb_indices - 1) + "]")
result_antisym.append(isym)
# Final consistency check:
index_list = []
for isym in result_sym:
Expand All @@ -3094,8 +3094,6 @@ def _canonicalize_sym_antisym(nb_indices, sym=None, antisym=None, *,
raise IndexError("incompatible lists of symmetries: the same " +
"index position appears more than once")
# Canonicalize sort order, make tuples
result_sym = [tuple(sorted(s)) for s in result_sym]
result_antisym = [tuple(sorted(s)) for s in result_antisym]
result_sym = tuple(sorted(result_sym))
result_antisym = tuple(sorted(result_antisym))
return result_sym, result_antisym
Expand Down

0 comments on commit fed09d5

Please sign in to comment.