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 more QQFieldElem and ZZRingElem ccalls #1866

Merged
merged 4 commits into from
Sep 26, 2024

Conversation

fingolfin
Copy link
Member

  • add some missing add!, mul!, etc. methods
  • add more efficient +, -, * methods for a ZZRingElem or QQFieldElem as first argument, and an integer as second argument
  • optimize is_one and is_zero for QQFieldElem
  • drop some pointless uses of @inline
  • add cmp for QQFieldElem and use it
  • add numerator! and denominator!
  • change a bunch of "unsafe" methods to accept ZZRingElemOrPtr resp. QQFieldElemOrPtr instead of just ZZRingElem and QQFieldElem to make them more flexible

This got a bit out of hand. I have more things lined up, but let's get this in while it passes my local tests, and to see what HeckeCI and OscarCI report.

- add some missing add!, mul!, etc. methods
- add more efficient +, -, * methods for a ZZRingElem or QQFieldElem
  as first argument, and an integer as second argument
- optimize is_one and is_zero for QQFieldElem
- drop some pointless uses of `@inline`
- add `cmp` for QQFieldElem and use it
- add numerator! and denominator!
- change a bunch of "unsafe" methods to accept ZZRingElemOrPtr resp.
  QQFieldElemOrPtr instead of just ZZRingElem and QQFieldElem to
  make them more flexible
Copy link

codecov bot commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 67.59259% with 35 lines in your changes missing coverage. Please review.

Project coverage is 87.29%. Comparing base (a47d0f6) to head (2cd8387).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/flint/fmpq.jl 62.96% 30 Missing ⚠️
src/julia/Rational.jl 0.00% 3 Missing ⚠️
src/flint/fmpz.jl 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1866      +/-   ##
==========================================
+ Coverage   87.00%   87.29%   +0.29%     
==========================================
  Files          98       97       -1     
  Lines       35934    35878      -56     
==========================================
+ Hits        31264    31321      +57     
+ Misses       4670     4557     -113     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/flint/fmpq.jl Outdated Show resolved Hide resolved
+(a::Int, b::QQFieldElem) = b + a

+(a::ZZRingElem, b::QQFieldElem) = b + a
+(a::QQFieldElem, b::Integer) = a + ZZRingElem(b)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some idea in my head: dispatch this directly to add! and handle the conversion there (similar for the other arithmetics). Then the above loop can be removed and instead all methods be installed for IntegerUnion.

What do you think about this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am OK with handling more in add!. However, we can't get rid of the loop because we'll get ambiguity errors (e.g. for FracField + Int vs QQFieldElem + Integer).

I suggest we merge this first and then we can think about handling additional cases. In fact I have another PR that helps with that in the pipeline.

return c
end

add!(c::QQFieldElemOrPtr, a::Union{ZZRingElemOrPtr, Int, UInt}, b::QQFieldElemOrPtr) = add!(c, b, a)
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the proposed change above (doing conversion in add! instead of +), this should get changed to IntegerUnion as well, to only have to do conversion in the last argument

If we don't apply the above change, I would argue that this method doesn't have a right to stay, as we only allow restricted types in these functions.
Similarly, sub! doesn't handle the wrong argument order

Copy link
Member Author

Choose a reason for hiding this comment

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

The case of sub! is a bit different, because there we can't just switch the order without loss -- we have to insert a neg!

Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

Apart from #1866 (comment), I am happy to merge this first and discuss later, before we get any problems with conflicts or downstream

Co-authored-by: Lars Göttgens <[email protected]>
@lgoettgens
Copy link
Collaborator

For the OscarCI failure, I think you can add a method for QQFieldElem cmp that converts Integer to ZZRingElem

@fingolfin
Copy link
Member Author

For the OscarCI failure, I think you can add a method for QQFieldElem cmp that converts Integer to ZZRingElem

Done.

@benlorenz
Copy link
Collaborator

The OscarCI tests are running but I just noticed a bunch of precompilation errors:

ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.
WARNING: Method definition numerator!(Nemo.ZZRingElem, Nemo.QQFieldElem) in module Nemo at /home/runner/work/Nemo.jl/Nemo.jl/src/flint/fmpq.jl:1076 overwritten in module Hecke at /home/runner/work/Nemo.jl/Nemo.jl/oscar-dev/Hecke/src/QuadForm/Enumeration.jl:1028.
WARNING: Method definition denominator!(Nemo.ZZRingElem, Nemo.QQFieldElem) in module Nemo at /home/runner/work/Nemo.jl/Nemo.jl/src/flint/fmpq.jl:1081 overwritten in module Hecke at /home/runner/work/Nemo.jl/Nemo.jl/oscar-dev/Hecke/src/QuadForm/Enumeration.jl:1033.

(https://github.com/Nemocas/Nemo.jl/actions/runs/11047475910/job/30688836009?pr=1866#step:7:305)

Triggered from here: https://github.com/thofma/Hecke.jl/blob/master/src/QuadForm/Enumeration.jl#L1028

@fingolfin
Copy link
Member Author

Ah, that's because those functions also exist in Hecke. I'll take them out here for now and we can migrate them later

@thofma
Copy link
Member

thofma commented Sep 26, 2024

How about keeping them, but not exporting them?

@fingolfin
Copy link
Member Author

@thofma ah that might work, good idea, thank you

@fingolfin fingolfin merged commit 1b6961c into Nemocas:master Sep 26, 2024
24 of 25 checks passed
@fingolfin fingolfin deleted the mh/more-fmpq branch September 26, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants