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

Work on FlatsMatroid #38027

Merged
merged 4 commits into from
May 25, 2024
Merged

Work on FlatsMatroid #38027

merged 4 commits into from
May 25, 2024

Conversation

gmou3
Copy link
Contributor

@gmou3 gmou3 commented May 19, 2024

Add class-optimized _closure and _is_closed methods.

Add input handling of a list of flats, and of a lattice of flats. Note that previously one could only define a FlatsMatroid from a dictionary of flats (indexed by their rank). The definition from a raw list requires more time upon definition as it computes and stores the lattice of flats from the input list. On the positive side, given this lattice, some methods become blazingly fast (e.g., is_valid, whitney_numbers).

The lattice of flats is now cached upon computation.

📝 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.

Copy link

github-actions bot commented May 19, 2024

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

Add `_closure` and `_is_closed` methods.
Create subclass `LatticeOfFlatsMatroid` which results from an input of a
_list_ of flats (instead of a dict). This subclass requires more compute
upon definition as it computes and stores the lattice of flats from a
raw list. On the positive side, given this lattice, some methods become
blazingly fast (e.g., `is_valid`, `whitney_numbers`).
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

I am not sure about having a full subclass. I think FlatsMatroid should be able to take in the lattice as input and store it (and/or have an optional argument to compute it). If the lattice has been computed (which the user could ask for at some point), then the lattice should be stored and the matroid should chose the code path that take advantage of that. With the proposed change, the flats matroid cannot take advantage of knowing the lattice structure.

It's a bit of an overhaul, but I don't think it will be too difficult. What do you think?

Otherwise, I have some minor comments.

src/sage/matroids/flats_matroid.pyx Outdated Show resolved Hide resolved
src/sage/matroids/flats_matroid.pxd Show resolved Hide resolved
@gmou3
Copy link
Contributor Author

gmou3 commented May 20, 2024

It's a bit of an overhaul, but I don't think it will be too difficult. What do you think?

I like it. Quite easy and a good suggestion. Thanks!
Defining a subclass resulted in a lot of bloatcode (excuse my overly technical jargon).

Move functionality of caching and using the lattice of flats (_L) to the
main FlatsMatroid class. Suggestion by tscrim.
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

Thank you.

The only other thing is I would explicitly set self._L = None and check self._L is None. This is because (in principle) the lattice might be empty, which is planned to eventually be changed so that bool(empty_lattice) is False. This might cause an issue with the corner case of the empty matroid. Plus it makes it a bit more explicit that we are checking if something is initialized.

@gmou3
Copy link
Contributor Author

gmou3 commented May 21, 2024

Thank you.

The only other thing is I would explicitly set self._L = None and check self._L is None. This is because (in principle) the lattice might be empty, which is planned to eventually be changed so that bool(empty_lattice) is False. This might cause an issue with the corner case of the empty matroid. Plus it makes it a bit more explicit that we are checking if something is initialized.

Done. It is more explicit indeed. I also saved some lines of code from the __init__.

Please have a look and don't hesitate to keep the corrections coming. :D

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

I am happy with this as it stands. Positive review.

@vbraun vbraun merged commit 6d02e7b into sagemath:develop May 25, 2024
16 checks passed
@gmou3 gmou3 deleted the flats_matroid branch May 25, 2024 15:26
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 25, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request May 27, 2024
    
This change makes the code cleaner in multiple places.
The PR also includes some docstring edits in `set_system.pyx`.

### ⌛ Dependencies

- Depends on sagemath#37930 and sagemath#38027
    
URL: sagemath#38056
Reported by: gmou3
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request May 29, 2024
    
This change makes the code cleaner in multiple places.
The PR also includes some docstring edits in `set_system.pyx`.

### ⌛ Dependencies

- Depends on sagemath#37930 and sagemath#38027
    
URL: sagemath#38056
Reported by: gmou3
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request May 31, 2024
    
This change makes the code cleaner in multiple places.
The PR also includes some docstring edits in `set_system.pyx`.

### ⌛ Dependencies

- Depends on sagemath#37930 and sagemath#38027
    
URL: sagemath#38056
Reported by: gmou3
Reviewer(s): Matthias Köppe
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.

4 participants