Opened 11 years ago

Closed 11 years ago

#10127 closed defect (fixed)

Fix initialization order in CombinatorialFreeModule

Reported by: nthiery Owned by: AlexGhitza
Priority: major Milestone: sage-4.6.1
Component: algebra Keywords:
Cc: sage-combinat, nborie Merged in: sage-4.6.1.alpha0
Authors: Nicolas Borie Reviewers: Nicolas M. Thiéry
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by nthiery)

This patch fixes CombinatorialFreeModule?.init in order to set self._basis_keys early enough in case the initialization of the categories use self.basis().keys(). This occured on several occasions in non trivial constructions. In the following example, AlgebrasWithBasis? constructs Homset(self,self) to extend by bilinearity the product_on_basis method, which in turn triggers the self._repr_()::

    sage: class MyAlgebra(CombinatorialFreeModule):
    ...       def _repr_(self):
    ...           return "MyAlgebra on %s"%(self.basis().keys())
    ...       def product_on_basis(self,i,j):
    ...           pass
    sage: MyAlgebra(ZZ, ZZ, category = AlgebrasWithBasis(QQ))
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/misc/", line 258, in __call__
    return cls.__classcall__(cls, *args, **options)
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/misc/", line 115, in __call__
    w = self.f(*args, **kwds)
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/structure/", line 449, in __classcall__
    instance = type.__call__(cls, *args, **options)
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/combinat/", line 827, in __init__
    element_constructor = self._element_constructor_)
  File "parent.pyx", line 458, in sage.structure.parent.Parent.__init__ (sage/structure/parent.c:3855)
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/categories/", line 115, in __init_extra__
    if (self.product != self.product_from_element_class_mul) and hasattr(self, "element_class") and hasattr(self.element_class, "_mul_parent"):
  File "element.pyx", line 863, in sage.structure.element.Element.__richcmp__ (sage/structure/element.c:7107)
  File "element.pyx", line 804, in sage.structure.element.Element._richcmp (sage/structure/element.c:6487)
  File "coerce.pyx", line 907, in sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion (sage/structure/coerce.c:8540)
  File "sage_object.pyx", line 101, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1370)
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/categories/", line 302, in _repr_
    self._domain, self._codomain, self.__category)
  File "sage_object.pyx", line 101, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1370)
  File "<string>", line 4, in _repr_
  File "/opt/sage-4.5.2/local/lib/python2.6/site-packages/sage/combinat/", line 869, in basis
    return Family(self._basis_keys, self.monomial) #.
  File "parent.pyx", line 680, in sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:5311)
  File "parent.pyx", line 264, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:2757)
  File "parent.pyx", line 172, in sage.structure.parent.raise_attribute_error (sage/structure/parent.c:2629)
AttributeError: 'MyAlgebra_with_category' object has no attribute '_basis_keys'

Depends on #9648

Attachments (1)

trac_10127_free_module_basis_key_initialisation-nb.patch (2.8 KB) - added by nborie 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by nthiery

  • Description modified (diff)
  • Work issues Just needs a regression test deleted

comment:2 Changed 11 years ago by nthiery

  • Description modified (diff)

All test pass on 4.5.3, with #9648 applied first, and the latest version of this patch on the Sage-Combinat patch server.

Nicolas: you may set a positive review on my behalf as soon as you have uploaded the patch here.

comment:3 Changed 11 years ago by nborie

  • Status changed from new to needs_review

Test and Doc are ok!

More important than the patch, thanks for giving this precise description of the problem...

I give this patch a positive review.

comment:4 Changed 11 years ago by nborie

  • Status changed from needs_review to positive_review

comment:5 Changed 11 years ago by jdemeyer

  • Merged in set to sage-4.6.1.alpha0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.