Resupdate - #48
Conversation
|
Thanks! First comments on the easier parts:
|
|
All changes look fine, thanks a lot! And nice speed-ups. I'll just take time to re-read carefully the new variant, and then this should be ready to merge. (I'd like maybe to do very minor changes here and there but this can be kept for later.) Minor comment concerning "portions developed with the assistance of Claude (Anthropic, Sonnet 5)": there was some discussion in a FLINT thread about mentioning this in copyrights at the top of the files. For the moment the approach was rather to mention the AI assistance in the pull request here, but leave just your name in the copyright. |
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
Ok, fine. Modified. |
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
Co-authored-by: Vincent Neiger <vneiger@users.noreply.github.com>
|
Thanks! |
mbasis "resupdate" and dispatch by shape
nmod_mat_poly.hhas long sketched aresupdatevariant ofmbasis(residual maintained incrementally instead of recomputed from scratch each
iteration) and a dispatcher choosing between it and the current
rescompvariant by shape.
nmod_mat_poly_mbasis(the current function) is renamed tonmod_mat_poly_mbasis_rescomp, unchanged internally (pure rename, samebehaviour, same known limitations).
nmod_mat_poly_mbasis_resupdateis added: maintains the vector of futureresidual coefficients
R[d],d = ord..order-1, updating it via the sameelementary row operations applied to
appbasat each iteration, instead ofrecomputing the residual from
appbas*matpfrom scratch.nmod_mat_poly_mbasisbecomes the dispatcher:2*cdim > rdimpicksresupdate, elserescomp.choice, so they always agree bit-for-bit on the same input — the dispatch
is a pure timing decision, never a correctness one.
_mbasis_low_rank_addmul,scoped to the new
resupdatefunction only): theper-iteration update
bottom += nsbas*topis a rank-cdimupdategenerically; below a small threshold (4, tuned in-context) it's done as
explicit rank-1 updates instead of paying
nmod_mat_addmul's per-entryverhead for a tiny inner dimension.
Portions developed with the assistance of Claude (Anthropic, Sonnet 5).
2*cdim > rdimvscdim > rdim/2 + 1rescomp's residual-recomputation cost is
O(m n^2 order^2 / 2); resupdate'sresidual-maintenance cost is
O(m n (m-n) order^2 / 2)— a factorn/(m-n)cheaper. The two costs are equal exactly at
n = m-n, i.e.cdim = rdim/2.2*cdim > rdim(strict) is the threshold validated by this data; at exactlycdim = rdim/2resupdate has no measured edge, so rescomp is used there.A bug found (fixed here)
Found that the existing function has a pre-existing latent bug at
order = 0:the main loop never runs in that case, so
nsbasis never initialized — butthe unconditional
nmod_mat_clear(nsbas)at the end of the function is calledon it anyway.
Fixed in both
rescompandresupdateby givingnsbasa trivial0 x 0init before the loop, and changing the loop's own
if (ord >= 1) nmod_mat_clear(nsbas)guard to an unconditional clear-before-reassign(now always valid, since
nsbasis always already initialized).Test added
src/nmod_mat_poly_extra/test/t-mbasis_variants.c: targetsrescomp/resupdate/the dispatcher directly at the mat_poly level —checks the two variants agree bit-for-bit, the dispatcher picks the right
one, and the result is a genuine approximant basis
(
nmod_poly_mat_is_approximant_basis) via conversion. Includes anexplicit (non-random)
order=0regression case for the bug above.Complements the existing
nmod_poly_mat_extra/test/t-mbasis.c, whichexercises the
nmod_poly_mat_mbasiswrapper and, since that wrapper callsinto this dispatcher, already provides transitive coverage across both
shape regimes via its own random rdim/cdim sweep.
What needs to be studied further
2*cdim > rdimdispatcher.NMOD_MAT_POLY_MBASIS_LOWRANK_THRES 4low rank threshold.Testing performed
order = 0fix, repeated 3x.prime with 50 bits, see the files.
Riders
Few things to avoid warnings at compilation when using maple interface. Does
not modify anything if maple is not involved.
In particular, uses now
CPPFLAGS="$CPPFLAGS -isystem $withval/include"inconfigure.ac.bench_mod_2.pdf
bench_50_bits.pdf