Opened 6 years ago
Last modified 6 years ago
#20767 closed enhancement
Move coercion to Element — at Version 33
Reported by:  jdemeyer  Owned by:  

Priority:  major  Milestone:  sage7.4 
Component:  coercion  Keywords:  
Cc:  nthiery, vdelecroix, SimonKing  Merged in:  
Authors:  Jeroen Demeyer  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  u/jdemeyer/move_coercion_to_element (Commits, GitHub, GitLab)  Commit:  e1d2ba46574273ec4d358e654ed195a82b81a654 
Dependencies:  #21126, #20686, #21139, #21140, #21152, #21153, #21154  Stopgaps: 
Description (last modified by )
This ticket has 2 main changes:
 Move all coercion logic from
RingElement
,ModuleElement
and the like toElement
.
Because of this, it matters a lot less whether a class inherits from Element
or from ModuleElement
/RingElement
/FieldElement
...
One difference remains: the more specialized classes have some default implementations for arithmetic. For example, ModuleElement
implements unary negation as multiplication by 1. The base class Element
has no such default implementations.
This patch also affects lookup in categories: with this patch, doubleunderscore methods like __add__
are never taken from the category. The Element
classes take precedence over the category, so the default implementations of arithmetic operations will override whatever is in the category (this is existing behaviour, not affected by this patch). For the base class Element
, this is not an issue since there are no default implementations.
 Change the implementation of doubleunderscore methods like
__add__
to returnNotImplemented
if one argument is not a SageElement
and coercion fails.
This will cause Python to try the reversed operation (__radd__
or __add__
in Cython). This way, Sage has improved support for operations with nonSage types.
Change History (33)
comment:1 Changed 6 years ago by
 Description modified (diff)
 Summary changed from Move coercion down to Element to Move coercion to Element
comment:2 Changed 6 years ago by
 Dependencies changed from #269, #20740, #20753, #20761, #20757 to #269, #20740, #20753, #20761, #20757, #20686
comment:3 Changed 6 years ago by
 Dependencies changed from #269, #20740, #20753, #20761, #20757, #20686 to #269, #20740, #20753, #20761, #20757, #20686, #20836
comment:4 Changed 6 years ago by
 Dependencies changed from #269, #20740, #20753, #20761, #20757, #20686, #20836 to #269, #20740, #20753, #20761, #20757, #20686, #20836, #20852
comment:5 Changed 6 years ago by
 Branch set to u/jdemeyer/move_coercion_to_element
comment:6 Changed 6 years ago by
 Commit set to ce70b30b0e05473aead282439474a176f09abe6c
 Dependencies changed from #269, #20740, #20753, #20761, #20757, #20686, #20836, #20852 to #269, #20686, #15947
comment:7 Changed 6 years ago by
 Dependencies changed from #269, #20686, #15947 to #269, #20686
comment:8 Changed 6 years ago by
 Commit changed from ce70b30b0e05473aead282439474a176f09abe6c to 04d1ef594face8e9cebd99acae4252a7b9899d38
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
88d9757  Comment that getattr_from_other_class is cached

7140ee3  Prefer absolute imports

fc6487c  Merge remotetracking branch 'trac/u/jdemeyer/upgrade_to_cython_0_24_1' into t/20686/optimize_method_lookup_from_the_categories_for_instances_of_cython_classes

16d4743  EvaluationMethods should be a newstyle class

54ccd82  Remove __dict__ attribute from ElementWrapper

9a71db1  Merge commit '54ccd828cb20b1254aeaf55bf7edab4a73f1032a'; tag '7.3.beta9' into t/20767/move_coercion_to_element

04d1ef5  Move arithmetic using coercion model to Element

comment:9 Changed 6 years ago by
 Commit changed from 04d1ef594face8e9cebd99acae4252a7b9899d38 to ada2e74a6104e88da56b391e681500d3ebc88d3d
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
ada2e74  Move arithmetic using coercion model to Element

comment:10 Changed 6 years ago by
 Commit changed from ada2e74a6104e88da56b391e681500d3ebc88d3d to b9a3614592e4a3a2f66ce2d2e52dcb0dcf013384
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
b9a3614  Move arithmetic using coercion model to Element

comment:11 Changed 6 years ago by
 Commit changed from b9a3614592e4a3a2f66ce2d2e52dcb0dcf013384 to 9c4bdefc8cbb6638699d620586d1bb707817094d
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
9c4bdef  Move arithmetic using coercion model to Element

comment:12 Changed 6 years ago by
 Dependencies changed from #269, #20686 to #21126, #20686
comment:13 Changed 6 years ago by
 Commit changed from 9c4bdefc8cbb6638699d620586d1bb707817094d to e4919e05c644722170152603e6de769f201d5478
comment:14 Changed 6 years ago by
 Dependencies changed from #21126, #20686 to #21126, #20686, #21139
comment:15 Changed 6 years ago by
 Commit changed from e4919e05c644722170152603e6de769f201d5478 to 1570a11911c8812f648369981182760767005cf3
comment:16 Changed 6 years ago by
 Dependencies changed from #21126, #20686, #21139 to #21126, #20686, #21139, #21140
comment:17 Changed 6 years ago by
 Commit changed from 1570a11911c8812f648369981182760767005cf3 to 950d4ab0b6be3adfcb47b738dfc74a8b931b6cf1
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
a0d5ec6  Implement negation for modular forms

fbcda3b  Merge branch 't/21139/implement_negation_for_modular_forms' into t/20767/move_coercion_to_element

69d18c7  Remove redundant _lmul_ and _rmul_ methods

2f8e1c9  Merge commit '69d18c75875c8a9f770e9ef493d6e721854f4448' into t/20767/move_coercion_to_element

950d4ab  Move arithmetic using coercion model to Element

comment:18 Changed 6 years ago by
 Commit changed from 950d4ab0b6be3adfcb47b738dfc74a8b931b6cf1 to 7c7f7293f38f324e77530c3fc565cf3e2a839458
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
7c7f729  Move arithmetic using coercion model to Element

comment:19 Changed 6 years ago by
 Commit changed from 7c7f7293f38f324e77530c3fc565cf3e2a839458 to 4d82fb71ce86a9eb79a41595571f1105f13aee36
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
4d82fb7  Move arithmetic using coercion model to Element

comment:20 Changed 6 years ago by
 Commit changed from 4d82fb71ce86a9eb79a41595571f1105f13aee36 to a67c31fc539dc21188dd36e5ce972be034d93b9f
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
a67c31f  Move arithmetic using coercion model to Element

comment:21 Changed 6 years ago by
 Commit changed from a67c31fc539dc21188dd36e5ce972be034d93b9f to bbc6e049de5b9376f9fb8f37cf23850529448c5a
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
bbc6e04  Move arithmetic using coercion model to Element

comment:22 Changed 6 years ago by
 Commit changed from bbc6e049de5b9376f9fb8f37cf23850529448c5a to 59f29566265b7ef0f559bf5fd95232c99e3f3a27
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
59f2956  Move arithmetic using coercion model to Element

comment:23 Changed 6 years ago by
 Commit changed from 59f29566265b7ef0f559bf5fd95232c99e3f3a27 to 8fc8d924e856d831ef21451aed4f687cb0574c4d
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
8fc8d92  Move arithmetic using coercion model to Element

comment:24 Changed 6 years ago by
 Dependencies changed from #21126, #20686, #21139, #21140 to #21126, #20686, #21139, #21140, #21152
comment:25 Changed 6 years ago by
 Commit changed from 8fc8d924e856d831ef21451aed4f687cb0574c4d to 21aea97e09005d62513b08c639ae086aa157af80
comment:26 Changed 6 years ago by
 Dependencies changed from #21126, #20686, #21139, #21140, #21152 to #21126, #20686, #21139, #21140, #21152, #21153, #21154
comment:27 Changed 6 years ago by
 Commit changed from 21aea97e09005d62513b08c639ae086aa157af80 to 16c545efb9c09c7054ce7b7638312fcd36a55227
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
0a44b08  Remove one doctest for __mul__

54b0fcd  Various minor fixes for the coercion model

2405dde  Merge commit '0a44b082f08c742fbe564c5afdd2f7309fabbb52'; commit '54b0fcdaf2fd69cd64978da526af6774b57a59a8' into t/20767/move_coercion_to_element

16c545e  Move arithmetic using coercion model to Element

comment:28 Changed 6 years ago by
 Status changed from new to needs_review
comment:29 Changed 6 years ago by
 Commit changed from 16c545efb9c09c7054ce7b7638312fcd36a55227 to e1d2ba46574273ec4d358e654ed195a82b81a654
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
e1d2ba4  Move arithmetic using coercion model to Element

comment:30 Changed 6 years ago by
 Description modified (diff)
comment:31 Changed 6 years ago by
 Description modified (diff)
comment:32 Changed 6 years ago by
 Description modified (diff)
comment:33 Changed 6 years ago by
 Description modified (diff)
New commits:
Improve getattr_from_other_class
Test that static methods work
Improve _sage_src_lines_()
Implement __mod__ in the coercion model
Merge commit 'f5361d972a61dcb60a76425264baa9e6d134e54b'; commit 'ccd5fcc16ac1708854a600cfc259c23d6c7568ff'; commit 'c41bc91addb41f593e4509d3fd6e9ce7c5789b39'; commit '80795088d0774413d5cbb94459d95b430e9fe2ad' into t/20767/move_coercion_to_element
Remove comments about "private" attributes with two underscores
Abstract away category lookup in cdef method getattr_from_category
Merge remotetracking branch 'origin/u/jdemeyer/optimize_method_lookup_from_the_categories_for_instances_of_cython_classes' into t/20767/move_coercion_to_element
Move arithmetic using coercion model to Element