Hi Jason! On Tue, Jan 12, 2010 at 12:19:36PM -0500, Jason Bandlow wrote: > While working on this, I added a ``TestSuite(phi)`` test where ``phi`` > is a TriangularModuleMorphism, mimicking what was done for > DiagonalModuleMorphism.
Good idea! > Unfortunately, pickling fails. I don't really know where to start > tracking this down... can you give me a pointer? phi is constructed from f, which itself can't be pickled: sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") sage: Y = CombinatorialFreeModule(QQ, [1, 2, 3]); y = Y.basis() sage: f = lambda i: sum( y[j] for j in range(i,4) ) sage: loads(dumps(f)) ------------------------------------------------------------ Traceback (most recent call last): PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed That's because functions are pickled by name; but the name of f is __main__.f. Pickles detects that there is no such function in the __main__module, and rightfully deduces that f could not be unpickled in a latter Sage session. Luckily, one can cheat-around this, faking f being picklable, by forcefully inserting it into __main__, as in: sage: import __main__; __main__.f = f Oh, and f should be defined with def, not lambda. sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") sage: Y = CombinatorialFreeModule(QQ, [1, 2, 3]); y = Y.basis() sage: def f(i): sum( y[j] for j in range(i,4) ) sage: import __main__; __main__.f = f sage: loads(dumps(f)) <function f at 0xbfbc9cc> sage: phi = X.module_morphism(f, triangular=True, codomain = Y) sage: TestSuite(phi).run() See the first example of TriangularModuleMorphism. Altogether, whenever possible, I try to use standard sage functions (like factorial) for such building blocks in tests. Here is a handy trick, which involves a bit of magic in sum_of_terms (it's a morphism, and therefore * is function composition): sage: f = Y.sum_of_terms * range sage: f(5) B[0] + B[1] + B[2] + B[3] + B[4] sage: loads(dumps(f)) A map to X Cheers, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/
-- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.