-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
Make IndexedFreeModuleElement compatible with collections.abc, change method support to return a SupportView #34509
Comments
This comment has been minimized.
This comment has been minimized.
Dependencies: #34505 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:5
I am against this change. They are vectors and only on their backend are implemented as a Contrast this to the “usual” free modules, where they have a natural compatibility with |
comment:6
Replying to Travis Scrimshaw:
It does define
|
comment:7
Replying to Travis Scrimshaw:
This makes no sense. |
comment:8
Replying to Travis Scrimshaw:
Yes, and there are two interpretations of this when the parent is a submodule.
|
This comment has been minimized.
This comment has been minimized.
comment:10
Replying to Matthias Köppe:
We want the two implementations to have the same API as much as possible. Rn vectors iterate over coefficients, but iterating over keys/supports here would be the exact opposite of that behavior. |
comment:11
Yes, it makes no sense to say that returning |
This comment has been minimized.
This comment has been minimized.
comment:13
Replying to Matthias Köppe:
So actually returning the coefficient as part of the iterator instead of saying you should access it by a completely different method is exactly the same by your logic. You wouldn’t agree that it is a much smaller change to have Rn vector iterators change to return the pairs? |
comment:14
Replying to Travis Scrimshaw:
That would be a really bad change for dense vectors, which clearly want to be a |
comment:15
Replying to Matthias Köppe:
Unfortunately because of different implementation goals (mainly the speed that is needed for the Rn modules), we cannot enforce compatibility for everything. I would rather all vectors follow what CFM vectors do from a more abstract mathematical point of view, but we have to make trade-offs. This one is here very clear-cut. Also, it isn’t just limited to sparse vectors, right? |
comment:16
Replying to Matthias Köppe:
I am not saying we should change it (see comment:15), but if we did, it would be smaller. |
comment:17
Replying to Travis Scrimshaw:
You'll have to be more concrete than that. There's nothing in the proposed change that has anything to do with performance. |
comment:18
I do see lots of uses of the idiom So maybe an easier change would be to get rid of the |
comment:19
Replying to Matthias Köppe:
If we change the iterator for Rn modules to make it compatible with what |
comment:20
Replying to Matthias Köppe:
+1 on this basically. I doubt anyone is using the support containment check where speed really matters, but that is my only slight hesitancy because that change would make it much slower (via the additional temporary object from |
comment:21
Replying to Travis Scrimshaw:
OK, yes, that's just one of several reasons why this change would be bad. It's not being proposed here. |
comment:22
Replying to Travis Scrimshaw:
Yes, of course the current implementation of |
comment:23
By the way, can |
comment:24
If there's no zero value in |
comment:25
Either way instead of inventing a new name such as |
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:66
ok, done |
comment:67
Should we also do comparisons with different
Sorry if this was something you were planning to support and hadn’t gotten to that stage yet. |
comment:68
Replying to Matthias Köppe:
Thank you. |
comment:69
Replying to Travis Scrimshaw:
I'm unsure about this, and I think I would defer it to a follow-up ticket. It could get full |
comment:70
In view of #29218, I would also move The |
comment:71
But that will go to #29218. |
comment:72
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:75
The failure in |
comment:77
All morally green, ready for review (The Build&Test failure is another well-known random failure, in |
Reviewer: Travis Scrimshaw |
comment:78
Sorry, lost track of this. LGTM. |
comment:79
Thank you! |
Changed branch from u/mkoeppe/make_indexedfreemoduleelement_a_collections_abc_mapping to |
This is the element class of a
CombinatorialFreeModule
.Its implementation of
__iter__
,__contains__
,__len__
are not compatible with anything in the collections.abc protocols. Specifically,but
__iter__
ating over this collection gives objects that are not__contain__
ed in it.To improve interoperability, we propose to make the following changes:
__contains__
method (currently testing whether a given index is in the support). After its removal, the class would no longer be considered by Python to be a subclass ofcollections.abc.Collection
, but merely aSized
Iterable
.support
to return an instance of a new classSupportView
, which provides a fast__contains__
method, instead of a list.(Similarly, in #24815, it was proposed to make the elements of free modules from
sage.modules
a collections.abc.Sequence.)Part of Meta-ticket #30309: Unify free module elements API: methods dict, monomial_coefficients, etc.
Depends on #34505
CC: @fchapoton @tscrim @mwageringel @nthiery @anneschilling
Component: linear algebra
Author: Matthias Koeppe
Branch/Commit:
2fe3b98
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/34509
The text was updated successfully, but these errors were encountered: