Skip to content

Middle product geometric#45

Merged
vneiger merged 22 commits into
mainfrom
middle_product_geometric_fixes
May 17, 2026
Merged

Middle product geometric#45
vneiger merged 22 commits into
mainfrom
middle_product_geometric_fixes

Conversation

@vneiger

@vneiger vneiger commented May 12, 2026

Copy link
Copy Markdown
Owner

This aims to revamp the middle product of polynomial matrices (nmod_poly_mat_mulmid) based on evaluation/interpolation at a geometric progression, based on the recent enhancement of geometric progressions in FLINT.

  • check if DIRTY_ALLOC is still relevant for performance, and remove it otherwise [removed]
  • use the mulmid, nlo, nhi notation like in FLINT's univariate polynomials
  • add a main function that takes as input suitably large precomputations of a geometric progression
  • chase possible bug when this is used within PMBasis residual computation
  • augment tests with many more possibilities of degrees (currently, restricted to a single degree / nlo,nhi configuration), and check this still works [works, with minor points to understand: raised ellC to nhi+1 instead of nhi]
  • modify precomputations so that only eval-interp ones are done
  • benchmark w.r.t. previous version
  • choose some reasonable thresholds for switching between naive and geometric

@vneiger

vneiger commented May 17, 2026

Copy link
Copy Markdown
Owner Author

To finalize this PR, I also reintroduced the Vandermonde-based multiplication, useful for medium degrees, and added some general interface nmod_poly_mat_multiply which picks the fastest algorithm (tuning is handmade and not very fine, but reasonably ok on my machine). The general mulmid and multiply are now used in pmbasis and kernel functions, and this provides some interesting gain as we can see below.

Here are times for kernel bases of $m \times (m-1)$ matrices (can be interpreted as linear system solving), via the ZLS algorithm. NEW is after this PR, OLD before this PR, PML/NTL(app)(int) are the versions present in the NTL part of PML either based on approximants or interpolants. NTL was compiled with AVX FFT, which limits the used prime to 50 bits (unlike what the table suggests: the two right columns are for a 50 bit modulus).

Conclusions for kernel:

  • with the new mulmid and multiply, performance of the kernel basis is close to the NTL version, and most often slightly better
  • we would gain from having interpolant variants of pmbasis, to be able to write an equivalent of the "int" version of the kernel (it is always a bit faster than "app")
bits rdim cdim len  NEW      OLD      PML/NTL(app) PML/NTL(int)
60   8    7    10   2.68e-04 2.69e-04 0.00057410   0.00079652
60   8    7    50   3.61e-03 3.83e-03 0.00585903   0.00703731
60   8    7    100  9.32e-03 1.02e-02 0.01558650   0.01663842
60   8    7    500  7.54e-02 8.47e-02 0.11440348   0.09571409
60   16   15   10   1.56e-03 1.73e-03 0.00266319   0.00319753
60   16   15   50   1.89e-02 2.32e-02 0.02784193   0.02801034
60   16   15   100  4.72e-02 6.46e-02 0.06647217   0.06550239
60   16   15   500  4.09e-01 6.14e-01 0.47068419   0.38894776
60   32   31   10   8.12e-03 1.05e-02 0.01243096   0.01243924
60   32   31   50   1.14e-01 1.66e-01 0.11840505   0.11721851
60   32   31   100  2.53e-01 4.96e-01 0.28561832   0.27061736
60   32   31   500  1.97e+00 4.71e+00 2.12873509   1.73920571
60   64   63   10   4.84e-02 7.04e-02 0.07198635   0.06347543
60   64   63   50   6.06e-01 1.17e+00 0.55478581   0.54666129
60   64   63   100  1.38e+00 3.44e+00 1.39742554   1.30012050
60   64   63   500  1.00e+01 3.70e+01 10.0611709   8.19106525
60   128  127  10   3.36e-01 5.58e-01 0.48880811   0.43524574
60   128  127  50   3.92e+00 7.58e+00 3.07954105   2.96782870
60   128  127  100  8.17e+00 2.03e+01 7.39021262   6.85440104
60   128  127  500  5.64e+01 2.01e+02 53.5813920   42.46814010

And some timings for pmbasis. Conclusions:

  • timings are basically unchanged for the one column case, this is where gains could be obtained from linearizations as done in pmbasis linearized  #41 (the column "lin" gives a perhaps optimistic idea of what we could obtain)
  • for 2 columns or more, the gain is good (factor between about 2 and more than 5, and improving when dimension grows)
  • the NTL versions are slightly faster, and the fastest one is also the one based on evaluation/interpolation at a geometric progression (except for the one-column case)
bits rdim cdim order   NEW       OLD      NTL(geo) NTL(fft) NTL(lin)
40   8    4    2560    1.17e-01  1.44e-01 1.29e-01
40   8    4    5120    2.62e-01  3.08e-01
40   8    4    8000    4.12e-01  4.43e-01 3.98e-01
40   40   1    8000    1.02e+00  1.34e+00          1.74e+00 4.02e-01
40   100  1    8000    5.04e+00  5.44e+00          1.15e+01  1.05e+00
40   100  3    2560    2.82e+00  4.42e+00
40   100  3    5120    6.41e+00  1.05e+01
40   100  3    8000    1.04e+01  1.68e+01
60   40   8    20      1.33e-03  1.32e-03
60   40   8    40      5.09e-03  8.76e-03
60   40   8    80      1.42e-02  3.34e-02
60   40   8    160     4.02e-02  1.09e-01
60   40   8    320     1.06e-01  3.14e-01
60   40   8    640     2.69e-01  8.85e-01
60   40   8    1280    6.69e-01  2.44e+00
60   40   8    1800    1.04e+00  3.84e+00
60   32   16   20      2.06e-03  2.07e-03
60   32   16   40      7.43e-03  1.74e-02
60   32   16   80      2.27e-02  6.87e-02
60   32   16   160     6.62e-02  2.56e-01
60   32   16   320     1.85e-01  7.41e-01
60   32   16   640     4.93e-01  2.01e+00
60   32   16   1280    1.18e+00  4.99e+00
60   32   16   1800    1.84e+00  7.14e+00
60   32   16   2560    2.85e+00  1.18e+01  2.13e+00
60   64   32   20      1.31e-02  1.30e-02
60   64   32   40      4.09e-02  1.11e-01
60   64   32   80      1.20e-01  4.62e-01
60   64   32   160     3.29e-01  1.68e+00
60   64   32   320     8.66e-01  5.27e+00
60   64   32   640     2.22e+00  1.47e+01  2.08e+00
60   64   32   1280    5.41e+00  3.74e+01  4.95e+00
60   64   32   1800    8.40e+00  5.37e+01  6.27e+00
60   64   32   2560    1.27e+01  inf       1.08e+01

More complete timings attached.
timings_pmbasis.txt

@vneiger vneiger marked this pull request as ready for review May 17, 2026 10:48
@vneiger vneiger merged commit 9263efb into main May 17, 2026
6 checks passed
@vneiger vneiger deleted the middle_product_geometric_fixes branch May 17, 2026 16:45
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.

1 participant