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

mul_strassen: avoid computing some entries twice #2076

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/fmpz_mat/mul_strassen.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,22 @@ void fmpz_mat_mul_strassen(fmpz_mat_t C, const fmpz_mat_t A, const fmpz_mat_t B)

if (a > 2*anr)
{
fmpz_mat_t Ar, Cr;
fmpz_mat_t Ar, Br, Cr;
fmpz_mat_window_init(Ar, A, 2*anr, 0, a, b);
fmpz_mat_window_init(Cr, C, 2*anr, 0, a, c);
fmpz_mat_mul(Cr, Ar, B);
fmpz_mat_window_init(Cr, C, 2*anr, 0, a, 2*bnc);

/* don't compute the overlapping entries twice */
if (c > 2 * bnc)
{
fmpz_mat_window_init(Br, B, 0, 0, b, 2*bnc);
fmpz_mat_mul(Cr, Ar, Br);
fmpz_mat_window_clear(Br);
}
else
{
fmpz_mat_mul(Cr, Ar, B);
}

fmpz_mat_window_clear(Ar);
fmpz_mat_window_clear(Cr);
}
Expand Down
18 changes: 15 additions & 3 deletions src/gr_mat/mul_strassen.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,22 @@ int gr_mat_mul_strassen(gr_mat_t C, const gr_mat_t A, const gr_mat_t B, gr_ctx_t

if (ar > 2 * anr)
{
gr_mat_t Ar, Cr;
gr_mat_t Ar, Br, Cr;
gr_mat_window_init(Ar, A, 2 * anr, 0, ar, ac, ctx);
gr_mat_window_init(Cr, C, 2 * anr, 0, ar, bc, ctx);
status |= gr_mat_mul(Cr, Ar, B, ctx);
gr_mat_window_init(Cr, C, 2 * anr, 0, ar, 2 * bnc, ctx);

/* don't compute the overlapping entries twice */
if (bc > 2 * bnc)
{
gr_mat_window_init(Br, B, 0, 0, ac, 2 * bnc, ctx);
status |= gr_mat_mul(Cr, Ar, Br, ctx);
gr_mat_window_clear(Br, ctx);
}
else
{
status |= gr_mat_mul(Cr, Ar, B, ctx);
}

gr_mat_window_clear(Ar, ctx);
gr_mat_window_clear(Cr, ctx);
}
Expand Down
Loading