Skip to content

Conversation

devansh-srv
Copy link
Contributor

@devansh-srv devansh-srv commented Mar 5, 2025

The as_tuples argument helps in achieving hashing of Combinations objects by producing elements of type tuple
This refers to issue 39455

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@devansh-srv
Copy link
Contributor Author

Please review and guide me over this @maxale

Copy link

github-actions bot commented Mar 5, 2025

Documentation preview for this PR (built with commit 836586e; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@maxale
Copy link
Contributor

maxale commented Mar 5, 2025

Please review and guide me over this @maxale

As I said, I'm not much familiar with Sage internals and I cannot guide you here.

@devansh-srv
Copy link
Contributor Author

Hey @fchapoton Please allow workflow run
I am a newbie so did not know about
pycodestyle and ./sage -t --new
but now I have locally checked and it passed all 97 tests on the combination.py file

@devansh-srv
Copy link
Contributor Author

Hey @fchapoton now I have fixed the docstring lint issue
Can you tell me how can I locally check this
I used pydocstyle to locally test code lint issue
but how can I locally test docstring lint issues

@devansh-srv
Copy link
Contributor Author

Hey @fchapoton I have finally fixed the issue in the docstring lint and checked it
Please allow the workflow run so that I can see if there are any problems

@devansh-srv
Copy link
Contributor Author

Hey @fchapoton there was some problem in the code lint which I have fixed and checked it
Please allow the workflow run so that I can see if there are any problems

@DaveWitteMorris
Copy link
Member

I'm sorry, but I don't think this is the right approach. We don't want another class that is almost the same as Combinations, because that would clutter the api, add to our maintenance burden, and cause confusion for users.

I think it will be ok to have combinations be tuples, rather than lists, so I think that's probably the change that should be made. However, this change may break some existing code, so I think there will need to be a deprecation period in which lists are the default, but tuples are available, perhaps by setting a keyword argument.

@devansh-srv
Copy link
Contributor Author

@DaveWitteMorris yeah that will be the most organic way. Thank you for guiding me. I'll do it right away

@devansh-srv
Copy link
Contributor Author

devansh-srv commented Mar 6, 2025

@DaveWitteMorris and @fchapoton can you please review the latest changes

@devansh-srv
Copy link
Contributor Author

Hey @fchapoton do I need to make any changes?
I think this is fine
If not please give suggestions
Also, please allow workflow run so that I can see if something is wrong

@@ -240,7 +256,7 @@ def __eq__(self, other) -> bool:

def __ne__(self, other) -> bool:
"""
Test for unequality.
Test for inequality.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo this change

Copy link
Contributor Author

@devansh-srv devansh-srv Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was failing due to codespell
it suggested to use inequality

@cached_method
def __hash__(self) -> int:
"""
Returns the hash of combinations(mset,k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first line of doc should use "Return" (imperative mode)

@cached_method
def __hash__(self) -> int:
"""
Returns the hash of combinations(mset)
Copy link
Contributor

@fchapoton fchapoton Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return, not Returns

and with a final dot

@@ -456,7 +501,7 @@ def _iterator(self, items, n):
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
"""
for combination in itertools.combinations(items, n):
yield list(combination)
yield combination if self.as_tuples else list(combination)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the if outside of the loop

Copy link
Contributor Author

@devansh-srv devansh-srv Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if self.as_tuples:
            for combination in itertools.combinations(items, n):
                yield combination
        else:
            for combination in itertools.combinations(items, n):
                yield list(combination)

@fchapoton is this fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

@devansh-srv devansh-srv Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fchapoton please review latest changes and allow workflow run
Also meson conda build for python 3.11.x was failing
is it a necessary check
if so how can I fix it

"""
Return the combinatorial class of combinations of the multiset
``mset``. If ``k`` is specified, then it returns the combinatorial
class of combinations of ``mset`` of size ``k``.

Return the Combination as tuples instead of lists if as_tuples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Return the Combination as tuples instead of lists if as_tuples
This returns the Combination as tuple instead of list if ``as_tuples``

sage: hash(Combinations([1,2,1],2)) == hash(c)
True
"""
return hash(str(self.__repr__()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong. maybe hash(tuple(self)) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right

Copy link
Contributor Author

@devansh-srv devansh-srv Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fchapoton Please review the latest changes as you had suggested and update me about some other changes if required

@devansh-srv
Copy link
Contributor Author

devansh-srv commented Mar 7, 2025

@fchapoton what can possibly be the problem with the check
[Build & Test / test-long (src/sage/[p-z]*) (pull_request)]
with
Process completed with exit code 64
as I have not made any changes to any file in src/sage/[p-z]*
It had passed for commit 7dd73e2
Do you know how can I fix this?

@devansh-srv
Copy link
Contributor Author

devansh-srv commented Mar 8, 2025

@DaveWitteMorris @fchapoton
What went wrong with this?
I cannot understand
the same test [Build & Test / test-long (src/sage/[p-z]*) (pull_request)]
had passed on a previous commit 7dd73e2
Is this some random failure in CI?

@devansh-srv
Copy link
Contributor Author

exit code 64 usually means there is some issue with build path (probably in docker)
like docker_target or something
@DaveWitteMorris , @fchapoton can you help me out here?

@devansh-srv
Copy link
Contributor Author

@fchapoton Please review this issue

@devansh-srv devansh-srv marked this pull request as draft March 9, 2025 13:49
@devansh-srv devansh-srv marked this pull request as ready for review March 9, 2025 13:49
@devansh-srv
Copy link
Contributor Author

@DaveWitteMorris what is the problem
can you please review and discuss?

@devansh-srv
Copy link
Contributor Author

@DaveWitteMorris I have managed to rebuild sage
Please review the changes made in the latest commit and tell me if anything needs to be changed

@devansh-srv
Copy link
Contributor Author

devansh-srv commented Mar 26, 2025

Can someone please tell me what has to be done for this code to be merged
I am not able to comprehend why this has not been merged
Please review and tell me if anything needs to be changed
Request to @fchapoton and @DaveWitteMorris

@fchapoton
Copy link
Contributor

Please be patient. Very patient. Everybody here has many other duties.

@devansh-srv
Copy link
Contributor Author

Please be patient. Very patient. Everybody here has many other duties.

Understood. Just wanted to check if there are any specific blockers I should address.
Thanks for your time!

@devansh-srv devansh-srv marked this pull request as draft March 26, 2025 12:58
@devansh-srv devansh-srv marked this pull request as ready for review April 2, 2025 13:37
@devansh-srv devansh-srv force-pushed the CombHash branch 2 times, most recently from c374166 to e87423b Compare April 3, 2025 01:13
@devansh-srv devansh-srv requested a review from fchapoton April 4, 2025 21:20
Comment on lines 47 to 48
The boolean keyword ``as_tuples`` determines whether each combination
is represented as a tuple or as a list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The boolean keyword ``as_tuples`` determines whether each combination
is represented as a tuple or as a list.
The boolean keyword ``as_tuples`` (default: ``False``) determines whether
each combination is represented as a tuple or as a list.

Comment on lines 483 to 484
for combination in itertools.combinations(items, n):
yield combination
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for combination in itertools.combinations(items, n):
yield combination
yield from itertools.combinations(items, n)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, when self.as_tuples is True, can you just return itertools.combinations(items, n)?

@DaveWitteMorris
Copy link
Member

Thanks for making the changes. I think it is good now.

vbraun pushed a commit to vbraun/sage that referenced this pull request May 4, 2025
sagemathgh-39633: added as_tuples as an optional argument to Combinations to facilitate hashing in Combination objects
    
The as_tuples argument helps in achieving hashing of Combinations
objects by producing elements of type tuple
This refers to issue
[39455](sagemath#39455)

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39633
Reported by: Devansh Srivastava
Reviewer(s): DaveWitteMorris, Devansh Srivastava, Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request May 5, 2025
sagemathgh-39633: added as_tuples as an optional argument to Combinations to facilitate hashing in Combination objects
    
The as_tuples argument helps in achieving hashing of Combinations
objects by producing elements of type tuple
This refers to issue
[39455](sagemath#39455)

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39633
Reported by: Devansh Srivastava
Reviewer(s): DaveWitteMorris, Devansh Srivastava, Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request May 6, 2025
sagemathgh-39633: added as_tuples as an optional argument to Combinations to facilitate hashing in Combination objects
    
The as_tuples argument helps in achieving hashing of Combinations
objects by producing elements of type tuple
This refers to issue
[39455](sagemath#39455)

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39633
Reported by: Devansh Srivastava
Reviewer(s): DaveWitteMorris, Devansh Srivastava, Frédéric Chapoton
@vbraun vbraun merged commit ada990b into sagemath:develop May 11, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants