#15618: Use the correct categories for coercion and conversion maps
-------------------------------------+-------------------------------------
       Reporter:  pbruin             |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.4
      Component:  coercion           |   Resolution:
       Keywords:  conversion map     |    Merged in:
        Authors:  Peter Bruin        |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/pbruin/15618-DefaultConvertMap   |  54a6ecae11f902b11ad651c67af021af6ed2da21
   Dependencies:  #16401, #16402,    |     Stopgaps:
  #17359                             |
-------------------------------------+-------------------------------------

Comment (by nbruin):

 Just this line:
 {{{
 if
 category.is_subcategory(FiniteDimensionalAlgebrasWithBasis(self.base_ring()))
 }}}
 is a memory leak:
 {{{
 sage: import gc
 sage: from collections import Counter
 sage: gc.collect()
 93
 sage: pre={id(a) for a in gc.get_objects()}
 sage:
 sage: for p in prime_range(20000):
 ....:         A =  FiniteDimensionalAlgebrasWithBasis(GF(p))
 ....:
 sage: gc.collect()
 0
 sage: post=Counter(str(type(a)) for a in gc.get_objects() if id(a) not in
 pre)
 sage: post
 Counter({"<type 'tuple'>": 314633, "<type 'dict'>": 106360, "<type
 'list'>": 88464, "<type 'cell'>": 67894, "<type
 'sage.misc.cachefunc.CachedMethodCallerNoArgs'>": 52032, "<type
 'weakref'>": 40733, "<class 'weakref.KeyedRef'>": 36193, "<type
 'function'>": 33947, "<type 'staticmethod'>": 33947, "<type
 'builtin_function_or_method'>": 33938, "<type
 'sage.misc.cachefunc.CachedMethodCaller'>": 33937, "<type 'frozenset'>":
 33933, "<class 'sage.structure.dynamic_class.DynamicClasscallMetaclass'>":
 33932, "<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>":
 25868, "<type 'sage.structure.coerce_dict.MonoDict'>": 4522, "<type
 'sage.structure.coerce_dict.MonoDictEraser'>": 4522, "<class
 'sage.categories.unital_algebras.UnitalAlgebras_with_category'>": 2262,
 "<class
 'sage.categories.vector_spaces.VectorSpaces.WithBasis_with_category'>":
 2262, "<class 'sage.categories.bimodules.Bimodules_with_category'>": 2262,
 "<class
 'sage.categories.unital_algebras.UnitalAlgebras.WithBasis_with_category'>":
 2262, "<class 'sage.categories.algebras.Algebras_with_category'>": 2262,
 "<class 'sage.categories.left_modules.LeftModules_with_category'>": 2262,
 "<class 'sage.categories.vector_spaces.VectorSpaces_with_category'>":
 2262, "<class
 'sage.categories.right_modules.RightModules_with_category'>": 2262,
 "<class
 
'sage.categories.finite_dimensional_algebras_with_basis.FiniteDimensionalAlgebrasWithBasis_with_category'>":
 2262, "<class
 'sage.categories.modules_with_basis.ModulesWithBasis_with_category'>":
 2262, "<class
 'sage.categories.algebras_with_basis.AlgebrasWithBasis_with_category'>":
 2262, "<class
 'sage.categories.magmatic_algebras.MagmaticAlgebras.WithBasis_with_category'>":
 2262, "<class
 'sage.categories.associative_algebras.AssociativeAlgebras_with_category'>":
 2262, "<class 'sage.categories.modules.Modules_with_category'>": 2262,
 "<type 'sage.structure.coerce_dict.TripleDict'>": 2261, "<class
 'sage.rings.ideal.Ideal_pid'>": 2261, "<type
 'sage.rings.finite_rings.integer_mod.NativeIntStruct'>": 2261, "<class
 'sage.categories.magmatic_algebras.MagmaticAlgebras_with_category'>":
 2261, "<class
 
'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn_with_category'>":
 2261, "<type 'sage.structure.coerce_dict.TripleDictEraser'>": 2261, "<type
 'instancemethod'>": 2261, "<class
 'sage.structure.dynamic_class.DynamicMetaclass'>": 15, "<class
 '_ast.Call'>": 3, "<type 'sage.misc.constant_function.ConstantFunction'>":
 2, "<class '_ast.Name'>": 2, "<type 'frame'>": 1, "<type 'set'>": 1,
 "<class '_ast.comprehension'>": 1, "<class '_ast.Interactive'>": 1,
 "<class
 
'sage.categories.finite_dimensional_modules_with_basis.FiniteDimensionalModulesWithBasis_with_category'>":
 1, "<class '_ast.Module'>": 1, "<type
 
'sage.categories.category_singleton.Category_contains_method_by_parent_class'>":
 1, "<type 'listiterator'>": 1, "<type 'generator'>": 1, "<class
 '_ast.Assign'>": 1, "<class
 'sage.categories.modules.Modules.FiniteDimensional_with_category'>": 1})
 }}}
 The problem is that categories themselves have infinite life, so one
 should not instantiate parametrized categories unless one really has to.
 To this end we now have:
 {{{
 sage: GF(3)['x'].category()
 Join of Category of euclidean domains and Category of commutative algebras
 over (finite fields and subquotients of monoids and quotients of
 semigroups)
 }}}
 (as you can see, the category doesn't explicitly link to `GF(3)` anymore)
 Admittedly:
 {{{
 sage: FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),
 Matrix([[0, 1], [0, 0]])]).category()
 Category of finite dimensional algebras with basis over Finite Field of
 size 3
 }}}
 so the memory leak already exists for `FiniteDimensionalAlgebra` in
 general. However, since you're introducing the line here, you should
 probably argue why you're not making the problem worse and/or open a
 ticket about the memory leak in general.

--
Ticket URL: <http://trac.sagemath.org/ticket/15618#comment:32>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to