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

Commit

Permalink
src/sage/tensor/modules/finite_rank_free_module.py, src/sage/categori…
Browse files Browse the repository at this point in the history
…es/pushout.py: Fix name mappings
  • Loading branch information
Matthias Koeppe committed Aug 24, 2022
1 parent a81428a commit 3f44174
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
38 changes: 36 additions & 2 deletions src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,9 @@ def __eq__(self, other):
return (self.n == other.n and
self.inner_product_matrix == other.inner_product_matrix and
self.with_basis == other.with_basis and
self.basis_keys == other.basis_keys)
self.basis_keys == other.basis_keys and
self.name_mapping == other.name_mapping and
self.latex_name_mapping == other.latex_name_mapping)
return False

def __ne__(self, other):
Expand Down Expand Up @@ -2032,6 +2034,17 @@ def merge(self, other):
[3 4 5]
[6 7 8]'
Names are removed when they conflict::
sage: from sage.categories.pushout import VectorFunctor, pushout
sage: M_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='M_ZZx')
sage: N_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='N_ZZx')
sage: pushout(M_ZZx, QQ)
Rank-4 free module M_ZZx_base_ext over the Univariate Polynomial Ring in x over Rational Field
sage: pushout(M_ZZx, N_ZZx)
Rank-4 free module over the Univariate Polynomial Ring in x over Integer Ring
sage: pushout(pushout(M_ZZx, N_ZZx), QQ)
Rank-4 free module over the Univariate Polynomial Ring in x over Rational Field
"""
if not isinstance(other, VectorFunctor):
return None
Expand Down Expand Up @@ -2065,8 +2078,29 @@ def merge(self, other):
else:
n = self.n

name_mapping = dict()
for base_ring, name in self.name_mapping.items():
try:
other_name = other.name_mapping[base_ring]
except KeyError:
name_mapping[base_ring] = name
else:
if name == other_name:
name_mapping[base_ring] = name

latex_name_mapping = dict()
for base_ring, latex_name in self.latex_name_mapping.items():
try:
other_latex_name = other.latex_name_mapping[base_ring]
except KeyError:
latex_name_mapping[base_ring] = latex_name
else:
if latex_name == other_latex_name:
latex_name_mapping[base_ring] = latex_name

return VectorFunctor(n, is_sparse, inner_product_matrix,
with_basis=with_basis, basis_keys=basis_keys)
with_basis=with_basis, basis_keys=basis_keys,
name_mapping=name_mapping, latex_name_mapping=latex_name_mapping)


class SubspaceFunctor(ConstructionFunctor):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/tensor/modules/finite_rank_free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ def construction(self):
kwds = dict(is_sparse=False,
inner_product_matrix=None,
with_basis=None,
name_mapping={self.base_ring(): self._name},
latex_name_mapping={self.base_ring(): self._latex_name})
name_mapping={self.base_ring(): self._name} if self._name else None,
latex_name_mapping={self.base_ring(): self._latex_name} if self._latex_name else None)
if self._sindex:
return (VectorFunctor(basis_keys=list(self.irange()), **kwds),
self.base_ring())
Expand Down

0 comments on commit 3f44174

Please sign in to comment.