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

Add to check for fixed total/length in IntegerVector #34510

Closed
trevorkarn opened this issue Sep 8, 2022 · 25 comments
Closed

Add to check for fixed total/length in IntegerVector #34510

trevorkarn opened this issue Sep 8, 2022 · 25 comments

Comments

@trevorkarn
Copy link
Contributor

The current IntegerVector.check() method only checks for the positivity of each element. This adds a check for specified totals (n) and lengths (k).

This ticket also allows for any collections.abc.Sequence object to be checked as an integer vector.

CC: @tscrim @trevorkarn @darijgr

Component: combinatorics

Keywords: gsoc2022 integer-vector check

Author: Trevor K. Karn

Branch/Commit: 43e6813

Reviewer: Travis Scrimshaw

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

@trevorkarn trevorkarn added this to the sage-9.8 milestone Sep 8, 2022
@trevorkarn
Copy link
Contributor Author

Changed keywords from gsoc2022 to gsoc2022 integer-vector check

@trevorkarn trevorkarn self-assigned this Sep 8, 2022
@trevorkarn trevorkarn changed the title Add to check for fixed length in IntegerVector Add to check for fixed total/length in IntegerVector Sep 8, 2022
@trevorkarn
Copy link
Contributor Author

comment:2

There is also a defect in this:

sage: IV33 = IntegerVectors(n=3, k=3)
sage: IV33([0])
[0]
sage: IV33([0]) in IV33
True

@trevorkarn
Copy link
Contributor Author

Branch: u/tkarn/34510

@trevorkarn
Copy link
Contributor Author

New commits:

c071210Add tests, remove buggy check, add to check

@trevorkarn
Copy link
Contributor Author

Commit: c071210

@tscrim
Copy link
Collaborator

tscrim commented Sep 9, 2022

comment:4

I would just check that it belongs to the parent. The first test should be done by that anyways.

Also, for the error message:

f"{self} is not an element of {self.parent()}"

@tscrim
Copy link
Collaborator

tscrim commented Sep 9, 2022

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Sep 9, 2022

comment:5

Once changed and a green bot, positive review.

@tscrim

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 9, 2022

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9fc9a42Add tests, remove buggy check, add to check
d5522d2Fix error message and fix bug and add tests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 9, 2022

Changed commit from c071210 to d5522d2

@trevorkarn
Copy link
Contributor Author

comment:7

Should be good to go. Removing the first check allowed [-1] to be understood as an IntegerVector so I fixed that in the IntegerVector.__contains__.

@tscrim
Copy link
Collaborator

tscrim commented Sep 9, 2022

comment:8

Good catch on another bug. [-1] in IntegerVectors() is indeed bad. One last thing is changing

-if not isinstance(x, (list, tuple, IntegerVector)):
+if not isinstance(x, sequence):

using the from collections.abc import sequence (that way it also takes things like Compositions as well). We should just do that here as well (with an update to the ticket description too).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 13, 2022

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

4ddf379Add tests, remove buggy check, add to check
43e6813List/tuple -> sequence

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 13, 2022

Changed commit from d5522d2 to 43e6813

@trevorkarn
Copy link
Contributor Author

comment:10

Replying to Travis Scrimshaw:

One last thing is changing

-if not isinstance(x, (list, tuple, IntegerVector)):
+if not isinstance(x, sequence):

using the from collections.abc import sequence

Done!

@trevorkarn

This comment has been minimized.

@trevorkarn
Copy link
Contributor Author

comment:13

Here's something surprising! Compositions are not understood as Sequences.

sage: c = Composition([3,4,2,4])
sage: from collections.abc import Sequence
sage: isinstance(c, Sequence)
False

@trevorkarn
Copy link
Contributor Author

comment:14

Replying to Trevor Karn:

Here's something surprising! Compositions are not understood as Sequences.

sage: c = Composition([3,4,2,4])
sage: from collections.abc import Sequence
sage: isinstance(c, Sequence)
False

The bug because of the Compositions, so I'm opening #34527 and this is now ready for review.

@tscrim
Copy link
Collaborator

tscrim commented Sep 13, 2022

comment:16

Actually, I suspect this holds for things more general things within Sage because of the extra requirements of a __reversed__() and count() methods. We can weaken this to collection.

@trevorkarn
Copy link
Contributor Author

comment:17

Replying to Travis Scrimshaw:

Actually, I suspect this holds for things more general things within Sage because of the extra requirements of a __reversed__() and count() methods. We can weaken this to collection.

I think we discussed this offline but I just want to confirm that this should be a Sequence because there is implicitly a fixed order?

@tscrim
Copy link
Collaborator

tscrim commented Sep 16, 2022

comment:18

Yes, that's correct.

@trevorkarn
Copy link
Contributor Author

comment:19

Replying to Travis Scrimshaw:

Yes, that's correct.

Ok then I think this ticket is ready for review. Am I missing anything?

@tscrim
Copy link
Collaborator

tscrim commented Sep 18, 2022

comment:20

LGTM. Thank you.

@vbraun
Copy link
Member

vbraun commented Sep 25, 2022

Changed branch from u/tkarn/34510 to 43e6813

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

3 participants