-
Notifications
You must be signed in to change notification settings - Fork 27
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 tests for modules wrapping flint #39
Conversation
(lambda n: flint.fmpz(n).rising(2), | ||
[0, 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110]), | ||
(lambda n: flint.fmpz.bin_uiui(n, 0), | ||
[OE, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), |
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.
These function signatures are generally a bit inconsistent e.g.:
fmpz(n).func()
fmpz.func(n)
fmpz(n).func(m)
fmpz.func(n, m)
Is that something that should be kept for backwards compatibility?
Perhaps if a consistent scheme was decided then aliases could be added with more consistent signatures e.g. fmpz.rising_factorial(n,m)
.
Does it really make sense to have _ui
in the name for a Python method?
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.
This has to be decided on a case by case basis I think. Sometimes a function f(x,y) has a clear primary variable and then x.f(y) makes sense; binomials and rising factorials arguably fall into this category. In other cases a static method makes more sense.
We could also add a namespace of standalone functions (not requiring method calls), but that is a separate issue.
Agree there is no reason to have ui versions in the Python interface.
(lambda n: flint.fmpz(n).is_probable_prime(), | ||
[0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0]), | ||
(lambda n: flint.fmpz(n).is_perfect_power(), | ||
[T, T, T, F, F, T, F, F, F, T, T, F]), |
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 guess is_prime
and is_probable_prime
should be changed to return True/False rather than 0/1.
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.
Yes.
test/test.py
Outdated
assert flint.fmpz(f) == f | ||
assert flint.fmpz(str(i)) == f | ||
raises(lambda: flint.fmpz("qwe"), ValueError) | ||
raises(lambda: flint.fmpz([]), TypeError) |
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 just realised I'm using this raises
function incorrectly because it works different from the pytest/sympy
one. Is there any reason not to use pytest in general here in python_flint
?
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.
No, I wouldn't mind.
What exactly is a good way to test an arb? I wanted to do something like this:
That doesn't work though because the arb created is not exactly the same and has a larger radius:
It doesn't seem to be possible to make an arb with a smaller radius:
It seems like I have to change the context just to construct the arb:
The context precision also affects the way that the arb is printed even when it has a higher precision. |
I hadn't realised that the Linux builds in CI were still using MPIR rather than GMP. They now fail because they're trying to download from mpir.org which has now expired. |
I would use Otherwise, it is usually best to check if intervals overlap:
|
Is there a way to construct an Arb that is exactly the same as another? I see these
I don't quite see how I can explicitly construct a second arb that precisely matches this value. |
The easiest solution might be to wrap |
086b977
to
93217dc
Compare
It would probably be useful to add those if that's a format already used by arb. To me the most natural representation in Python would be to convert an arb to/from a tuple of 4 int/fmpz e.g. |
The The representation used by |
Yes, that's what I was thinking. It would be good to have a way to convert to and from this format as a tuple of integers rather than a string representation of those integers. I see what you mean though that it might be simplest to just wrap the text dump functions for now. |
return t | ||
r = fmpq_poly_equal((<fmpq_series>s).val, (<fmpq_series>t).val) | ||
if r: | ||
r = (<fmpq_series>s).prec == (<fmpq_series>t).prec |
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.
Is this the kind of equality comparison we want for series?
- A series cannot compare equal to anything that is not a series e.g.
fmpq_series([1]) != 1
- An
fmpz_series
can compare equal to anfmpq_series
:fmpq_series([1]) == fmpz_series([1])
- Two series with different prec compare unequal:
fmpz_series([1],5) != fmpz_series([1],6)
- Invalid series compare equal:
fmpz_series([],-1) == fmpz_series([],-1)
Okay I think this PR is at a reasonable milestone for review/merge. Tests are added for almost full line coverage of all modules relating to flint (rather than arb). I've also fixed a few bugs and added Later I think it would be good to reorganise these tests to make more of the testing code generic so that e.g. all poly types are tested by the same test code for consistency. There are currently some inconsistencies about exactly which type has which methods and what exceptions they raise etc so that could be fixed at the same time. I haven't looked at the arb modules at all yet but again that can be something to follow up. The arb-related modules are only really tested by the doctests and in some cases they give fairly low coverage. The coverage with both tests and doctests here is:
|
The remaining parts that aren't covered are mostly:
|
Equality of series is a bit tricky. It depends whether you want to compare series as symbolic expressions, as elements of R[x] / x^n, or as elements of R[[x]]. In the latter case, the O() term should be understood the same way as an error bound in interval arithmetic, and
is actually undecidable (following the semantics of BTW, I think |
Yeah, that looks bogus. |
I don't necessarily disagree but I'm wondering why they were there before. Is it to allow something like a nan e.g.: In [50]: fmpq_series([1,1],1,3).derivative().derivative().derivative()
Out[50]: O(x^0)
In [51]: fmpq_series([1,1],1,3).derivative().derivative().derivative().derivative()
Out[51]: (invalid power series) |
I don't remember why I ever put them in; probably because I was too lazy to implement all edge cases. Case in point: the derivative of (I will add a C type for power series as part of the generics system eventually...) |
I think that equality also needs to be understood differently from mathematical equality in the context of a programming language. For example in testing we really want The general question of mathematical equality or equivalence is something much more involved and that can be interpreted differently depending on the context. Of course it is possible that our notion of series equality can correspond to a particular notion of mathematical equality but in practical terms we want basic properties like |
Indeed:
I think the interface should provide separate, explicit functions for testing equality of representations and testing mathematical equality, e.g. There are then pros and cons to having Python's For mathematical equality, you could map the truth status to Python booleans in different ways. Pessimistic logic (current
Optimistic logic:
Strict logic:
Triple-valued logic:
In the
|
The consideration needed for >>> {1,1.0}
{1}
>>> {1.0,1}
{1.0} With that being decided though the context in which we need to think about Having |
I wanted to run these tests on OSX arm64 after merging #42 but I don't seem to be able to get Cirrus CI to run on this PR. |
Okay, I'll add this and use it for the series tests. |
11dfee6
to
9c168ce
Compare
Okay, this is tested with OSX arm64 after rebasing (and the tests pass). |
Current coverage report:
|
Okay, let's merge this now to have better coverage testing in others PRs. |
This is a work in progress.
Maybe the test script should be reorganised a bit as the current one-test-function-per-module structure will get a bit unwieldy if more tests are added.