#15289: Implement indexed monoids
-------------------------------------+-------------------------------------
       Reporter:  tscrim             |        Owner:  sage-combinat
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.3
      Component:  algebra            |   Resolution:
       Keywords:  days54             |    Merged in:
        Authors:  Travis Scrimshaw   |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  public/monoids/15289-indexed       |  1ff1a0483f5e61959a432371b701f593a5dee599
   Dependencies:  #15309, #15169     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Replying to [comment:36 tscrim]:
 > Simon, so I've changed the `UniqueFactory` object `FreeMonoid` to a new
 factory function since it returns a class which I've designed as a
 `UniqueRepresentation`. However unpickling old `FreeMonoid` objects fails
 because of the unpickling mechanism of `UniqueFactory` redirects to
 `generic_factory_unpickle()` and has `FreeMonoid` from the global
 namespace as the first object.

 First thing I wonder: ''Why'' is that statically typed? Just to shave off
 a little calling overhead?

 > It is expecting it to be a `UniqueFactory` instance, so it errors out
 here. Furthermore because of the structure of the pickle, I'm unable to
 use `register_unpickle_override` or see anyway to redirect that specific
 pickle without changing the behavior of `generic_factory_unpickle()`.

 I don't really understand how `register_unpickle_override` is working. It
 seems that it can only work if `unpickle_global` is involved---and it is
 not clear to me if this is involved everywhere or only if there is no
 `__reduce__` method around.

 > I'm thinking the best thing to do is to change
 `generic_factory_unpickle()` to accept a general object as input and if
 the first input is no longer a `UniqueFactory`, then call it with the
 arguments given as part of the pickle.

 Makes sense to me. And I even think the following idiom would not be
 slower in terms of calling overhead than the current implementation:
 {{{
 def generic_factory_unpickle(factory, *args):
     cdef UniqueFactory F
     try:
         F = factory
     except TypeError:
         return factory(*args[1:])
     return F.get_objects(*args)
 }}}

 Note that I wrote `factory(*args[1:])`, since the first argument is the
 version information. So, either we need to shave it off here, or the new
 class (or function) replacing the old factory is required to take care of
 this.

 > I'm also thinking we should change this behavior so we don't keep
 running into this problem.

 I think with my suggestion above, unpickling of using factory would work
 as quickly as it used to, and it would relatively easily allow to replace
 the factory by something else (provided that this "something else" takes
 care of the argument mangling and the version information that is involved
 in the factory pickle).

--
Ticket URL: <http://trac.sagemath.org/ticket/15289#comment:44>
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