Skip to content

Commit

Permalink
small optimisation to evaluate_modular
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Oct 24, 2023
1 parent 52cf466 commit dfa8d9f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/gr_poly/evaluate_modular.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,22 @@ _gr_poly_evaluate_modular(gr_ptr y, gr_srcptr poly,
{
slong i, j, k, coeff_index, l, m;
gr_ptr xs, ys, tmp, partial_results;
gr_ptr tmp_gr;
k = n_sqrt(len)+1;
j = (len + k - 1) / k;

TMP_INIT;

TMP_START;
tmp = TMP_ALLOC(sz * k);
GR_TMP_INIT(tmp_gr, ctx);
GR_TMP_INIT_VEC(xs, j, ctx);
GR_TMP_INIT_VEC(xs, j + 1, ctx);
GR_TMP_INIT_VEC(ys, k, ctx);
GR_TMP_INIT_VEC(partial_results, j, ctx);

status |= _gr_vec_set_powers(xs, x, j, ctx);
status |= gr_mul(tmp_gr, x, GR_ENTRY(xs, j-1, sz), ctx); /* This is x^j */
status |= _gr_vec_set_powers(ys, tmp_gr, k, ctx);
status |= _gr_vec_set_powers(xs, x, j + 1, ctx);
status |= _gr_vec_set_powers(ys, GR_ENTRY(xs, j, sz), k, ctx);

for (l = 0; l < j; l++){
for (l = 0; l < j; l++)
{
i = 0; /* Count number of coeffs in this row */
for (m = 0; m < k; m++)
{
Expand All @@ -71,16 +69,14 @@ _gr_poly_evaluate_modular(gr_ptr y, gr_srcptr poly,
status |= _gr_vec_dot(GR_ENTRY(partial_results, l, sz), NULL, 0, tmp, ys, i, ctx);
}
status |=_gr_vec_dot(y, NULL, 0, partial_results, xs, j, ctx);
GR_TMP_CLEAR(tmp_gr, ctx);
GR_TMP_CLEAR_VEC(xs, j, ctx);
GR_TMP_CLEAR_VEC(xs, j + 1, ctx);
GR_TMP_CLEAR_VEC(ys, k, ctx);
GR_TMP_CLEAR_VEC(partial_results, j, ctx);
TMP_END;
}
return status;
}


int
gr_poly_evaluate_modular(gr_ptr res, const gr_poly_t f, gr_srcptr x, gr_ctx_t ctx)
{
Expand Down

0 comments on commit dfa8d9f

Please sign in to comment.