Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cythonize ElementWrapper and make parent the first argument #14519

Closed
tscrim opened this issue May 2, 2013 · 15 comments
Closed

Cythonize ElementWrapper and make parent the first argument #14519

tscrim opened this issue May 2, 2013 · 15 comments

Comments

@tscrim
Copy link
Collaborator

tscrim commented May 2, 2013

For speed and consistency.

Depends on #14143
Depends on #14015
Depends on #14516

CC: @sagetrac-sage-combinat @nthiery @simon-king-jena

Component: performance

Keywords: cython ElementWrapper

Author: Travis Scrimshaw

Reviewer: Nicolas M. Thiéry

Merged: sage-5.12.beta2

Issue created by migration from https://trac.sagemath.org/ticket/14519

@tscrim tscrim added this to the sage-5.11 milestone May 2, 2013
@tscrim tscrim self-assigned this May 2, 2013
@tscrim
Copy link
Collaborator Author

tscrim commented May 3, 2013

Dependencies: #14143 #14516

@tscrim
Copy link
Collaborator Author

tscrim commented May 3, 2013

comment:1

Initial version which has a dependencies on #14143 (minor reject) and #14516 (since Letter no longer inherits from ElementWrapper, there is nothing to do there). Both of which this can be moved past with minor-moderate cost.

@tscrim
Copy link
Collaborator Author

tscrim commented May 9, 2013

Work Issues: fix segfault in UCF

@tscrim
Copy link
Collaborator Author

tscrim commented Jun 27, 2013

comment:3

The UCF segfault was due to it inheriting from both FieldElement and ElementWrapper. In particular, the _add_() / _mul_() / etc. functions of the UCF elements were not being called when ElementWrapper is an extension class. It also segfaults when I have it inherit from CombinatorialFreeModuleElement, which is what it wraps. I'll see if I can reduce it down to a simple test case and post it on another ticket and sage-devel since I don't know if this is a python, cython, or sage bug...

Also #11931 can be closed as a duplicate.

@tscrim
Copy link
Collaborator Author

tscrim commented Jun 27, 2013

Changed work issues from fix segfault in UCF to none

@simon-king-jena
Copy link
Member

comment:4

Note that I did experience a very subtle Cython problem: When one constructs a Python class that simultaneously inherits from RingElement and Morphism, then the two bases seem to have a compatible layout, however two different cpdef attributes of the two bases get confused. Perhaps this is similar here?

Sorry, I am too lazy to look up the ticket number or the discussion on the cython-user mailing list.

@tscrim
Copy link
Collaborator Author

tscrim commented Jun 28, 2013

comment:5

This is likely the same issue; luckily I could work (hack) around it here.

@nthiery
Copy link
Contributor

nthiery commented Jul 2, 2013

comment:6

Hi Travis,

I am finally looking at the patch now. Thanks for your work on this!

Some points:

  • In those places where the patch touches a "..." continuation, use the occasion to make it a "....:"
  • Line 312 of the coercion tutorial: missing space before D (it was missing already)
  • In all the calls to MyElement: proper spacing between arguments
  • universal_cyclotomic_field.py:
    • Unless unavoidable, don't change the order of the imports, and keep CombinatorialFreeModule imported in the __init__ instead of in the module.
    • Mention in the code that UCFElement can't multiple inherit from the two extension types FieldElement and ElementWrapper, which is why at this point the methods _latex_ and friends have to be duplicated (in the long run we can hope not to need anymore to inherit from FieldElement).
    • Check the spacing between the arguments in the call to element_class
  • disjoint_union_enumerated_sets.py: why did the type of el change?
  • The __nonzero__ feature is new, right? I'd rather avoid it at this point, since the semantic of being zero might differ quite some depending on the use case.

Let me know when you will have posted an updated patch fixing those as well as the failing tests detected by the patchbot.

@tscrim
Copy link
Collaborator Author

tscrim commented Jul 4, 2013

comment:7

Hey Nicolas,

Thank you for reviewing the patch.

Replying to @nthiery:

Some points:

  • In those places where the patch touches a "..." continuation, use the occasion to make it a "....:"
  • Line 312 of the coercion tutorial: missing space before D (it was missing already)
  • In all the calls to MyElement: proper spacing between arguments
  • universal_cyclotomic_field.py:
    • Unless unavoidable, don't change the order of the imports, and keep CombinatorialFreeModule imported in the __init__ instead of in the module.
    • Mention in the code that UCFElement can't multiple inherit from the two extension types FieldElement and ElementWrapper, which is why at this point the methods _latex_ and friends have to be duplicated (in the long run we can hope not to need anymore to inherit from FieldElement).

Done.

  • Check the spacing between the arguments in the call to element_class

I think done; if not I'll need something more specific.

  • disjoint_union_enumerated_sets.py: why did the type of el change?

Because it because an extension class.

  • The __nonzero__ feature is new, right? I'd rather avoid it at this point, since the semantic of being zero might differ quite some depending on the use case.

Done.

Let me know when you will have posted an updated patch fixing those as well as the failing tests detected by the patchbot.

The updated patch fixes almost everything except 1 doctest in misc/nested_class_test.py (as opposed to 2 previously) and I'm not quite sure what the problem is currently. I don't think I need a __reduce__() in the element wrapper since it has a __dict__ (and my __reduce__() was causing pickling to fail). If you have any insight into this, I'd appreciate it.

Thanks,

Travis

@tscrim
Copy link
Collaborator Author

tscrim commented Jul 4, 2013

Changed dependencies from #14143 #14516 to #14143 #14015 #14516

@tscrim
Copy link
Collaborator Author

tscrim commented Jul 9, 2013

@tscrim
Copy link
Collaborator Author

tscrim commented Jul 9, 2013

comment:8

Okay, I figured out what was going wrong. For the nested class, TestParent4 did not implement a __ne__ and is not a UniqueRepresentation, so it does not by default check not __eq__. In the ElementWrapper, I'm testing using __ne__.

For the posets, the problem was that ElementWrapper was checking if the second argument was a Parent class, rather than if the first argument is not a Parent. Thus wrapping a Set, which is a Parent, caused the deprecation warning and a swap to occur.

The rest of the errors were trivial in the sense I needed to put a parent as the first argument. In summary: err0rz b3 pwnd.

Best,

Travis

@nthiery
Copy link
Contributor

nthiery commented Jul 13, 2013

Reviewer: Nicolas M. Thiéry

@tscrim
Copy link
Collaborator Author

tscrim commented Jul 13, 2013

comment:10

Thanks for doing the review Nicolas.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Jul 21, 2013
@jdemeyer jdemeyer removed this from the sage-5.12 milestone Aug 2, 2013
@tscrim tscrim added this to the sage-5.12 milestone Aug 6, 2013
@tscrim tscrim removed the pending label Aug 6, 2013
@jdemeyer
Copy link

Merged: sage-5.12.beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants