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 mutating arithmetic for SRows #1659

Merged
merged 11 commits into from
Nov 13, 2024

Conversation

lgoettgens
Copy link
Contributor

@lgoettgens lgoettgens commented Oct 23, 2024

Add mutating arithmetics for SRow with the interface from AA. Inspired by oscar-system/Oscar.jl#4228 (comment) by @fingolfin .
Furthermore, make some of the existing functions easier to use by letting them coerce scalars (if needed) and add automatic workarounds for assertions.

I tested the new methods locally using test_mutating_op_like_* from AA. Unfortunately, for CI this does not work atm as there is too much expected missing for SRows (like random elements, zero, ...).

This currently contains #1658 to avoid conflicts.

@fingolfin could you have a look at the methods added here as well?

@lgoettgens
Copy link
Contributor Author

Is the failure something known that sometimes crashes?

Error in testset ModAlgAss/Lattices/Lattices.jl:
Error During Test at /home/runner/work/Hecke.jl/Hecke.jl/test/testdefs.jl:20
  Got exception outside of a @test
  LoadError: Matrix must be square
  Stacktrace:
    [1] error(s::String)
      @ Base ./error.jl:35
    [2] det
      @ ~/work/Hecke.jl/Hecke.jl/src/LinearAlgebra/FakeFmpqMat.jl:357 [inlined]
    [3] _coprime_integral_ideal_class(a::Hecke.AlgAssAbsOrdIdl{MatAlgebra{QQFieldElem, QQMatrix}, MatAlgebraElem{QQFieldElem, QQMatrix}}, b::Hecke.AlgAssAbsOrdIdl{MatAlgebra{QQFieldElem, QQMatrix}, MatAlgebraElem{QQFieldElem, QQMatrix}})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/AlgAssAbsOrd/PicardGroup.jl:922
    [4] _is_principal_non_maximal(I::Hecke.AlgAssAbsOrdIdl{MatAlgebra{QQFieldElem, QQMatrix}, MatAlgebraElem{QQFieldElem, QQMatrix}})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/NumFieldOrd/NfOrd/PicardGroup.jl:363
    [5] _is_principal_with_data_etale(a::Hecke.AlgAssAbsOrdIdl{MatAlgebra{QQFieldElem, QQMatrix}, MatAlgebraElem{QQFieldElem, QQMatrix}}; local_freeness::Bool)
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/AlgAssAbsOrd/PicardGroup.jl:488
    [6] _is_principal_with_data_etale
      @ ~/work/Hecke.jl/Hecke.jl/src/AlgAssAbsOrd/PicardGroup.jl:478 [inlined]
    [7] #_is_principal_with_data#4748
      @ ~/work/Hecke.jl/Hecke.jl/src/AlgAssAbsOrd/PIP.jl:44 [inlined]
    [8] _is_isomorphic_with_isomorphism_same_ambient_module(L::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix}, M::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix}, ::Val{true})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/ModAlgAss/Lattices/Morphisms.jl:289
    [9] _is_isomorphic(L::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix}, M::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix}, with_iso_val::Val{true})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/ModAlgAss/Lattices/Morphisms.jl:[334](https://github.com/thofma/Hecke.jl/actions/runs/11477268995/job/31938971542?pr=1659#step:7:337)
   [10] is_isomorphic_with_isomorphism(L::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix}, M::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/ModAlgAss/Lattices/Morphisms.jl:303
   [11] is_free_with_basis(L::Hecke.ModAlgAssLat{Hecke.AlgAssAbsOrd{GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}, GroupAlgebraElem{QQFieldElem, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}}, Hecke.ModAlgAss{QQField, QQMatrix, GroupAlgebra{QQFieldElem, MultTableGroup, MultTableGroupElem}}, QQMatrix})
      @ Hecke ~/work/Hecke.jl/Hecke.jl/src/ModAlgAss/Lattices/Morphisms.jl:394
   [12] top-level scope
      @ ~/work/Hecke.jl/Hecke.jl/test/ModAlgAss/Lattices/Lattices.jl:5

@fingolfin
Copy link
Contributor

Looks good to me, thanks

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 12 lines in your changes missing coverage. Please review.

Project coverage is 75.96%. Comparing base (66ab098) to head (9c8d5cd).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
src/Sparse/Row.jl 88.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1659      +/-   ##
==========================================
+ Coverage   75.84%   75.96%   +0.11%     
==========================================
  Files         361      362       +1     
  Lines      113694   114299     +605     
==========================================
+ Hits        86234    86828     +594     
- Misses      27460    27471      +11     
Files with missing lines Coverage Δ
src/Sparse/ZZRow.jl 91.56% <100.00%> (+0.33%) ⬆️
src/Sparse/Row.jl 83.94% <88.00%> (+4.97%) ⬆️

... and 49 files with indirect coverage changes

@thofma
Copy link
Owner

thofma commented Oct 25, 2024

needs a rebase as #1658 has been merged

P.S.: Have not seen this error before. Trying to reproduce it locally. Should be unrelated to the changes here.

@fingolfin
Copy link
Contributor

typo in title: arithmetcs

@@ -465,20 +467,23 @@ function scale_row!(a::SRow{T}, b::T) where T
deleteat!(a.values, i)
Copy link
Contributor

Choose a reason for hiding this comment

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

Orthogonal to this PR, but: Since you now handle b==0 at the start, the iszero(a.values[i]) check above the fold can only return true if the coefficient ring is not a domain. So it could be strengthened to something like !is_domain_type(T) && iszero(a.values[i]).

Since is_domain_type is a trait depending only on T, the compiler can eliminate the is_domain_type(T) check -- if it returns true it can elide the if block, and if it is false we the same code we have currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this can easily wait for a follow-up PR. (Also scale_row! and scale_row_right! could be merged)

@joschmitt joschmitt changed the title Add mutating arithmetcs for SRows Add mutating arithmetics for SRows Oct 25, 2024
@lgoettgens lgoettgens changed the title Add mutating arithmetics for SRows Add mutating arithmetic for SRows Oct 25, 2024
@thofma
Copy link
Owner

thofma commented Oct 26, 2024

What is planned with respect to tests?

@lgoettgens lgoettgens marked this pull request as draft October 26, 2024 19:34
@lgoettgens
Copy link
Contributor Author

We have some generic functions in AA that test if the mutating ops are properly implemented. But as I wrote above, it is not that easy to apply them here, but I do my best to somehow put that together

@thofma
Copy link
Owner

thofma commented Oct 26, 2024

I was not sure whether this comment means that we want to

  1. merge this here without tests,
  2. wait for a test function from AA, or
  3. add ad hoc tests.

@lgoettgens
Copy link
Contributor Author

Wait with merging until I have time to look into this on Monday

@lgoettgens
Copy link
Contributor Author

I added some tests regarding zero! and add!. For mul! and addmul! the test function (by fault) tries to multiply two SRows which of course errors. Nemocas/AbstractAlgebra.jl#1892 will provide a workaround.
With the corresponding branch from AA deved, these tests succeed locally for me.

The two options now (@thofma needs to decide between):

  1. Merge now. Once Adapt test_mutating_op_like_(add)mul to work with scalar mul as well Nemocas/AbstractAlgebra.jl#1892 is available, uncomment the tests in a future PR.
  2. Wait until Adapt test_mutating_op_like_(add)mul to work with scalar mul as well Nemocas/AbstractAlgebra.jl#1892 is available, uncomment the tests then, and then merge.

@lgoettgens lgoettgens marked this pull request as ready for review November 5, 2024 11:28
@thofma
Copy link
Owner

thofma commented Nov 8, 2024

Let's wait for 2)

@lgoettgens
Copy link
Contributor Author

@thofma testing is now finished with the new AA release from yesterday. Could you tag a release once this is merged, so that we can make use of it in Oscar? Thanks!

@thofma thofma merged commit ad39e8f into thofma:master Nov 13, 2024
17 checks passed
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.

3 participants