-
-
Notifications
You must be signed in to change notification settings - Fork 599
Fix compilation and doctests with flintlib 3.2 #39413
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
Conversation
@antonio-rojas in case you find this useful when flintlib 3.2 is released. |
Thanks - haven't tested yet, but at first sight it looks like these functions are not used anywhere, can't we just remove the declarations so it works across all flint versions? |
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I, | ||
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I] | ||
[[1.000000000... +/- ...] + [+/- ...]*I, | ||
[1.000000000... +/- ...] + [+/- ...]*I] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using abs tol
like what you used above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but it refuses to work because of the doctest:...
above.
But
Removing may lead to some confusion (e.g. if some future person want to use the function), and also then we should probably make a blacklist in the autogen file itself. |
@@ -51,6 +51,7 @@ | |||
|
|||
#define PY_SSIZE_T_CLEAN | |||
#include <Python.h> | |||
#include "gmp.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like flint bug to me? Surely the header should be usable standalone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's by design: With
flintlib/flint@3604bb2 one needs to include the gmp header before using fmpz_get_mpz
.
Actually the breaking change is flintlib/flint#1964 … looks like backwards incompatibility wasn't intended but…? |
Makes sense, in fact those two functions are deprecated in flintlib 3.2. A few tests won't work for both versions, because the order of the roots is different. Sorting doesn't work for these. Using I can see a few improvements to doctesting may be useful here and there, but I don't have time right now to work on these:
The goals here would be:
|
Actually…
Yes, using |
Actually (2) that isn't the reason. If it were it would have printed out Meanwhile in IPython shell:
Probably there's some magic there. Confusingly dict keys seem to be sorted as well, while in sufficiently new version of Python dict entries are in fact ordered. Edit: apparently the magic is in
some are in SageMath.
|
Quick comments:
In any case, my suggestion of the |
that's what I mean, because of some magic (displayhook) in IPython and sage, dict and set are always sorted (first tried by element, if fail it retry by key=str), so it should be good. |
Ok, I added
The problem here seems to be that
|
Ugh, I guess you can do a If it's confusing only do it in a TESTS:: block, I suppose. |
For that it feels less hacky to do Anyway, what's going on with testing here? |
What do you mean (the CI failing? it's because of the randstate thing right? flintlib/flint#1964 ) |
No, it doesn't even start building sagemath, AFAICT. |
Now it should be ok for both flintlib 3.1 and 3.2. |
Documentation preview for this PR (built with commit 5e2704a; changes) is ready! 🎉 |
The sorting should be fixed now. The issue is not about complex sorting, but about real sorting:
🤷 |
In their defense, it works exactly how it is documented. Interval arithmetic does not satisfy trichotomy. The implementation of complex interval arithmetic comparison could probably be improved though…
If it is disabled then comparison will fallback to using repr. |
This is ready and it should be easy to review. |
In principle, ideally the flint.pxd should be autogenerated from the script. it's also necessary to fix this part of the script
Edit: I did that in #39530, run on flint latest master. Let's see if tests pass. Edit: Unfortunately it's not that easy. Looks like flint_rand_alloc and flint_rand_free will be deprecated in flint 3.2 anyway. As such I think it's easier to just remove the 2 function declarations. |
sagemathgh-39530: Improvement to flint_autogen reader See sagemath#39413 (comment) In flint latest master, there's this thing ``` .. function:: void n_mulmod_and_precomp_shoup(ulong * ab, ulong * ab_precomp, \ ulong a, ulong b, \ ulong a_pr_quo, ulong a_pr_rem, ulong b_precomp, \ ulong n) ``` In order to parse this (trailing backslash), it is necessary to modify `flint_autogen.py`. Now I only handled it for function so far. Also some minor unrelated changes. ### 📝 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. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. (no change) ### ⌛ 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#39530 Reported by: user202729 Reviewer(s): Frédéric Chapoton
Sure, but maybe we can get this in and later worry about regenerating with newer sources. |
sagemathgh-39530: Improvement to flint_autogen reader See sagemath#39413 (comment) In flint latest master, there's this thing ``` .. function:: void n_mulmod_and_precomp_shoup(ulong * ab, ulong * ab_precomp, \ ulong a, ulong b, \ ulong a_pr_quo, ulong a_pr_rem, ulong b_precomp, \ ulong n) ``` In order to parse this (trailing backslash), it is necessary to modify `flint_autogen.py`. Now I only handled it for function so far. Also some minor unrelated changes. ### 📝 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. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. (no change) ### ⌛ 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#39530 Reported by: user202729 Reviewer(s): Frédéric Chapoton
sagemathgh-39420: Replace reproducible_repr() with usage of displayhook * It is not very well-known that doctest has magic features to ignore the ordering of `dict` and `set` (see for example sagemath#39413 (comment) ), I try to make it more discoverable. * Since the displayhook is in place (since 68b10e1), the `reproducible_repr` (added in e68d6eb) is mostly redundant. * Implement `_repr_pretty_` for `KeyConvertingDict` to make doctest deterministic. (based on the framework of sagemath#39027) There's a slight difference between `reproducible_repr` ordering (which always order by string representation) and this function (which tries first to order by element values, then by string representation), and the ordering of elements is reversed for multivariate polynomial ring (in `R.<x,y,z> = QQ[]`, `z < y < x`). However, it should still be deterministic. ### 📝 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#39420 Reported by: user202729 Reviewer(s): Tobias Diez, user202729
sagemathgh-39420: Replace reproducible_repr() with usage of displayhook * It is not very well-known that doctest has magic features to ignore the ordering of `dict` and `set` (see for example sagemath#39413 (comment) ), I try to make it more discoverable. * Since the displayhook is in place (since 68b10e1), the `reproducible_repr` (added in e68d6eb) is mostly redundant. * Implement `_repr_pretty_` for `KeyConvertingDict` to make doctest deterministic. (based on the framework of sagemath#39027) There's a slight difference between `reproducible_repr` ordering (which always order by string representation) and this function (which tries first to order by element values, then by string representation), and the ordering of elements is reversed for multivariate polynomial ring (in `R.<x,y,z> = QQ[]`, `z < y < x`). However, it should still be deterministic. ### 📝 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#39420 Reported by: user202729 Reviewer(s): Tobias Diez, user202729
It turns out sorting in `ComplexIntervalField` is broken. In this case, there are two elements that do not compare. ``` sage: x = PolynomialRing(CBF, 'x').gen() sage: _, a, b, _ = sorted((x^4 - 3).roots(ComplexIntervalField(100), multiplicities=False)) sage: a == b False sage: a < b False sage: a > b False sage: sorted([a,b]) [0.?e-37 + 1.31607401295249246081921890180?*I, 0.?e-37 - 1.31607401295249246081921890180?*I] sage: sorted([b,a]) [0.?e-37 - 1.31607401295249246081921890180?*I, 0.?e-37 + 1.31607401295249246081921890180?*I] ```
sagemathgh-39420: Replace reproducible_repr() with usage of displayhook * It is not very well-known that doctest has magic features to ignore the ordering of `dict` and `set` (see for example sagemath#39413 (comment) ), I try to make it more discoverable. * Since the displayhook is in place (since 68b10e1), the `reproducible_repr` (added in e68d6eb) is mostly redundant. * Implement `_repr_pretty_` for `KeyConvertingDict` to make doctest deterministic. (based on the framework of sagemath#39027) There's a slight difference between `reproducible_repr` ordering (which always order by string representation) and this function (which tries first to order by element values, then by string representation), and the ordering of elements is reversed for multivariate polynomial ring (in `R.<x,y,z> = QQ[]`, `z < y < x`). However, it should still be deterministic. ### 📝 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#39420 Reported by: user202729 Reviewer(s): Tobias Diez, user202729
@user202729 since you already had a look into this PR, would you mind doing formally approving it so it gets merged? This will (hopefully) future proof us for when flintlib 3.2 gets released. |
Wait a minute, this thing
makes the C compiler considers the struct name |
Thanks for having a look.
Yes, this makes the preprocessor substitute the old This is generally preferable IMHO, however this is a special case because (a) flintlib 3.2 hasn't been released yet and (b) the only two functions that require this type are deprecated. Therefore, if you prefer we can do this in a different way, either:
I think the last one might be the better choice, but I can do it either way if you prefer to the current approach. |
Okay, either way is good for me as well. |
Thanks! |
sagemathgh-39413: Fix compilation and doctests with flintlib 3.2 Tested with flintlib 3.2-rc1. May not work with flintlib 3.1. ### 📝 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. URL: sagemath#39413 Reported by: Gonzalo Tornaría Reviewer(s): Gonzalo Tornaría, Tobias Diez, user202729
sagemathgh-39413: Fix compilation and doctests with flintlib 3.2 Tested with flintlib 3.2-rc1. May not work with flintlib 3.1. ### 📝 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. URL: sagemath#39413 Reported by: Gonzalo Tornaría Reviewer(s): Gonzalo Tornaría, Tobias Diez, user202729
<!-- ^ 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. --> - [ ] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#39413 was merged. cc @tornaria @dimpase @user202729 URL: sagemath#39928 Reported by: Isuru Fernando Reviewer(s): Dima Pasechnik
sagemathgh-39928: Support flint 3.2 spkg-configure <!-- ^ 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. --> - [ ] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#39413 was merged. cc @tornaria @dimpase @user202729 URL: sagemath#39928 Reported by: Isuru Fernando Reviewer(s): Dima Pasechnik
Tested with flintlib 3.2-rc1.
May not work with flintlib 3.1.
📝 Checklist