Skip to content

Commit

Permalink
Use swap_entrywise everywhere aliasing is supported using swaps. (Does
Browse files Browse the repository at this point in the history
not work, see comments on PR #940.
  • Loading branch information
wbhart committed Apr 22, 2021
1 parent fd7612c commit 9b42913
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion d_mat/gso.c
Expand Up @@ -29,7 +29,7 @@ d_mat_gso(d_mat_t B, const d_mat_t A)
d_mat_t t;
d_mat_init(t, A->r, A->c);
d_mat_gso(t, A);
d_mat_swap(B, t);
d_mat_swap_entrywise(B, t);
d_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion d_mat/mul_classical.c
Expand Up @@ -30,7 +30,7 @@ d_mat_mul_classical(d_mat_t C, const d_mat_t A, const d_mat_t B)
d_mat_t t;
d_mat_init(t, ar, bc);
d_mat_mul_classical(t, A, B);
d_mat_swap(C, t);
d_mat_swap_entrywise(C, t);
d_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion d_mat/qr.c
Expand Up @@ -29,7 +29,7 @@ d_mat_qr(d_mat_t Q, d_mat_t R, const d_mat_t A)
d_mat_t t;
d_mat_init(t, A->r, A->c);
d_mat_qr(t, R, A);
d_mat_swap(Q, t);
d_mat_swap_entrywise(Q, t);
d_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion d_mat/transpose.c
Expand Up @@ -30,7 +30,7 @@ d_mat_transpose(d_mat_t B, const d_mat_t A)
d_mat_t t;
d_mat_init(t, A->r, A->c);
d_mat_transpose(t, A);
d_mat_swap(B, t);
d_mat_swap_entrywise(B, t);
d_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpq_mat/gso.c
Expand Up @@ -28,7 +28,7 @@ fmpq_mat_gso(fmpq_mat_t B, const fmpq_mat_t A)
fmpq_mat_t t;
fmpq_mat_init(t, B->r, B->c);
fmpq_mat_gso(t, A);
fmpq_mat_swap(B, t);
fmpq_mat_swap_entrywise(B, t);
fmpq_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpz_mat/gram.c
Expand Up @@ -24,7 +24,7 @@ void fmpz_mat_gram(fmpz_mat_t B, const fmpz_mat_t A)
fmpz_mat_t t;
fmpz_mat_init(t, B->r, B->c);
fmpz_mat_gram(t, A);
fmpz_mat_swap(B, t);
fmpz_mat_swap_entrywise(B, t);
fmpz_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpz_mat/mul.c
Expand Up @@ -124,7 +124,7 @@ fmpz_mat_mul(fmpz_mat_t C, const fmpz_mat_t A, const fmpz_mat_t B)
fmpz_mat_t T;
fmpz_mat_init(T, ar, bc);
fmpz_mat_mul(T, A, B);
fmpz_mat_swap(C, T);
fmpz_mat_swap_entrywise(C, T);
fmpz_mat_clear(T);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpz_mat/solve_cramer.c
Expand Up @@ -144,7 +144,7 @@ fmpz_mat_solve_cramer(fmpz_mat_t X, fmpz_t den,
fmpz_mat_t T;
fmpz_mat_init(T, 3, 3);
success = _fmpz_mat_solve_cramer_3x3(T, den, A, B);
fmpz_mat_swap(T, X);
fmpz_mat_swap_entrywise(T, X);
fmpz_mat_clear(T);
return success;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpz_mat/sqr.c
Expand Up @@ -24,7 +24,7 @@ fmpz_mat_sqr(fmpz_mat_t B, const fmpz_mat_t A)
fmpz_mat_t t;
fmpz_mat_init(t, n, n);
fmpz_mat_sqr(t, A);
fmpz_mat_swap(B, t);
fmpz_mat_swap_entrywise(B, t);
fmpz_mat_clear(t);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions fmpz_poly/test/t-evaluate_horner_d_2exp.c
Expand Up @@ -20,7 +20,7 @@
int
main(void)
{
int i, result;
int i;
FLINT_TEST_INIT(state);

flint_printf("evaluate_horner_d_2exp....");
Expand All @@ -30,7 +30,7 @@ main(void)
{
fmpz_poly_t f;
double x, y, z, t;
slong xexp, yexp, zexp;
slong xexp, yexp;

x = d_randtest(state);
xexp = n_randint(state, 20) - 10;
Expand Down
2 changes: 1 addition & 1 deletion fmpz_poly_mat/mul_classical.c
Expand Up @@ -37,7 +37,7 @@ fmpz_poly_mat_mul_classical(fmpz_poly_mat_t C, const fmpz_poly_mat_t A,
fmpz_poly_mat_t T;
fmpz_poly_mat_init(T, ar, bc);
fmpz_poly_mat_mul_classical(T, A, B);
fmpz_poly_mat_swap(C, T);
fmpz_poly_mat_swap_entrywise(C, T);
fmpz_poly_mat_clear(T);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fmpz_poly_mat/mullow.c
Expand Up @@ -37,7 +37,7 @@ fmpz_poly_mat_mullow(fmpz_poly_mat_t C, const fmpz_poly_mat_t A,
fmpz_poly_mat_t T;
fmpz_poly_mat_init(T, ar, bc);
fmpz_poly_mat_mullow(T, A, B, len);
fmpz_poly_mat_swap(C, T);
fmpz_poly_mat_swap_entrywise(C, T);
fmpz_poly_mat_clear(T);
return;
}
Expand Down
8 changes: 2 additions & 6 deletions fq_mat_templates/minpoly.c
Expand Up @@ -18,7 +18,7 @@ TEMPLATE(T, mat_minpoly) (TEMPLATE(T, poly_t) p,
{
slong n = X->r, i, j, c, c1, c2, r1, r2;
slong * P1, * P2, * L1, * L2;
TEMPLATE(T, mat_t) A, B, v, w;
TEMPLATE(T, mat_t) A, B, v;
int first_poly = 1, indep = 1;
TEMPLATE(T, poly_t) b, g, r;
TEMPLATE(T, t) t, h;
Expand Down Expand Up @@ -59,7 +59,6 @@ TEMPLATE(T, mat_minpoly) (TEMPLATE(T, poly_t) p,
TEMPLATE(T, mat_init) (A, n + 1, 2*n + 1, ctx);
TEMPLATE(T, mat_init) (B, n, n, ctx);
TEMPLATE(T, mat_init) (v, n, 1, ctx);
TEMPLATE(T, mat_init) (w, n, 1, ctx);

L1 = (slong *) TMP_ALLOC((n + 1)*sizeof(slong));
L2 = (slong *) TMP_ALLOC(n*sizeof(slong));
Expand Down Expand Up @@ -109,9 +108,7 @@ TEMPLATE(T, mat_minpoly) (TEMPLATE(T, poly_t) p,
r1++;
r2 = indep ? r2 + 1 : r2;

/* fq_mat_mul does not support aliasing, so mul and swap */
TEMPLATE(T, mat_mul) (w, X, v, ctx);
TEMPLATE(T, mat_swap) (v, w, ctx);
TEMPLATE(T, mat_mul) (v, X, v, ctx);

for (i = 0; i < n; i++)
TEMPLATE(T, set) (TEMPLATE(T, mat_entry) (A, r1, i), TEMPLATE(T, mat_entry) (v, i, 0), ctx);
Expand Down Expand Up @@ -185,7 +182,6 @@ TEMPLATE(T, mat_minpoly) (TEMPLATE(T, poly_t) p,
TEMPLATE(T, mat_clear) (A, ctx);
TEMPLATE(T, mat_clear) (B, ctx);
TEMPLATE(T, mat_clear) (v, ctx);
TEMPLATE(T, mat_clear) (w, ctx);

TEMPLATE(T, poly_clear) (b, ctx);
TEMPLATE(T, poly_clear) (g, ctx);
Expand Down
2 changes: 1 addition & 1 deletion fq_mat_templates/mul.c
Expand Up @@ -23,7 +23,7 @@ TEMPLATE(T, mat_mul) (TEMPLATE(T, mat_t) C,
TEMPLATE(T, mat_t) TT;
TEMPLATE(T, mat_init) (TT, A->r, B->c, ctx);
TEMPLATE(T, mat_mul) (TT, A, B, ctx);
TEMPLATE(T, mat_swap) (TT, C, ctx);
TEMPLATE(T, mat_swap_entrywise) (TT, C, ctx);
TEMPLATE(T, mat_clear) (TT, ctx);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion fq_mat_templates/mul_classical.c
Expand Up @@ -40,7 +40,7 @@ TEMPLATE(T, mat_mul_classical) (TEMPLATE(T, mat_t) C,
TEMPLATE(T, mat_t) T;
TEMPLATE(T, mat_init) (T, ar, bc, ctx);
TEMPLATE(T, mat_mul_classical) (T, A, B, ctx);
TEMPLATE(T, mat_swap) (C, T, ctx);
TEMPLATE(T, mat_swap_entrywise) (C, T, ctx);
TEMPLATE(T, mat_clear) (T, ctx);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion mpf_mat/gso.c
Expand Up @@ -30,7 +30,7 @@ mpf_mat_gso(mpf_mat_t B, const mpf_mat_t A)
mpf_mat_t T;
mpf_mat_init(T, A->r, A->c, B->prec);
mpf_mat_gso(T, A);
mpf_mat_swap(B, T);
mpf_mat_swap_entrywise(B, T);
mpf_mat_clear(T);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion mpf_mat/mul.c
Expand Up @@ -28,7 +28,7 @@ mpf_mat_mul(mpf_mat_t C, const mpf_mat_t A, const mpf_mat_t B)
mpf_mat_t t;
mpf_mat_init(t, ar, bc, C->prec);
mpf_mat_mul(t, A, B);
mpf_mat_swap(C, t);
mpf_mat_swap_entrywise(C, t);
mpf_mat_clear(t);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion mpf_mat/qr.c
Expand Up @@ -30,7 +30,7 @@ mpf_mat_qr(mpf_mat_t Q, mpf_mat_t R, const mpf_mat_t A)
mpf_mat_t T;
mpf_mat_init(T, A->r, A->c, Q->prec);
mpf_mat_qr(T, R, A);
mpf_mat_swap(Q, T);
mpf_mat_swap_entrywise(Q, T);
mpf_mat_clear(T);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion mpfr_mat/mul_classical.c
Expand Up @@ -30,7 +30,7 @@ mpfr_mat_mul_classical(mpfr_mat_t C, const mpfr_mat_t A, const mpfr_mat_t B,
mpfr_mat_t t;
mpfr_mat_init(t, ar, bc, C->prec);
mpfr_mat_mul_classical(t, A, B, rnd);
mpfr_mat_swap(C, t);
mpfr_mat_swap_entrywise(C, t);
mpfr_mat_clear(t);
return;
}
Expand Down
8 changes: 2 additions & 6 deletions nmod_mat/minpoly.c
Expand Up @@ -21,7 +21,7 @@ void nmod_mat_minpoly_with_gens(nmod_poly_t p, const nmod_mat_t X, ulong * P)
slong n = X->r, i, j, c, c1, c2, r1, r2;
ulong ** A, ** B, ** v, t, h;
slong * P1, * P2, * L1, * L2;
nmod_mat_t matA, matB, matv, matw;
nmod_mat_t matA, matB, matv;
int first_poly = 1, indep = 1;
nmod_poly_t b, g;
TMP_INIT;
Expand Down Expand Up @@ -56,7 +56,6 @@ void nmod_mat_minpoly_with_gens(nmod_poly_t p, const nmod_mat_t X, ulong * P)
nmod_mat_init(matA, n + 1, 2*n + 1, p->mod.n);
nmod_mat_init(matB, n, n, p->mod.n);
nmod_mat_init(matv, n, 1, p->mod.n);
nmod_mat_init(matw, n, 1, p->mod.n);

A = matA->rows;
B = matB->rows;
Expand Down Expand Up @@ -112,9 +111,7 @@ void nmod_mat_minpoly_with_gens(nmod_poly_t p, const nmod_mat_t X, ulong * P)
r1++;
r2 = indep ? r2 + 1 : r2;

/* nmod_mat_mul does not support aliasing, so mul and swap */
nmod_mat_mul(matw, X, matv);
nmod_mat_swap(matv, matw);
nmod_mat_mul(matv, X, matv);
v = matv->rows;

for (i = 0; i < n; i++)
Expand Down Expand Up @@ -189,7 +186,6 @@ void nmod_mat_minpoly_with_gens(nmod_poly_t p, const nmod_mat_t X, ulong * P)
nmod_mat_clear(matA);
nmod_mat_clear(matB);
nmod_mat_clear(matv);
nmod_mat_clear(matw);

nmod_poly_clear(b);
nmod_poly_clear(g);
Expand Down
2 changes: 1 addition & 1 deletion nmod_mat/mul.c
Expand Up @@ -74,7 +74,7 @@ nmod_mat_mul(nmod_mat_t C, const nmod_mat_t A, const nmod_mat_t B)
nmod_mat_t T;
nmod_mat_init(T, m, n, A->mod.n);
nmod_mat_mul(T, A, B);
nmod_mat_swap(C, T);
nmod_mat_swap_entrywise(C, T);
nmod_mat_clear(T);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions nmod_mat/pow.c
Expand Up @@ -55,12 +55,12 @@ _nmod_mat_pow(nmod_mat_t dest, const nmod_mat_t mat, ulong pow)
if(pow%2 == 1)
{
nmod_mat_mul(temp1, dest, temp2);
nmod_mat_swap(temp1, dest);
nmod_mat_swap_entrywise(temp1, dest);
}
if (pow > 1)
{
nmod_mat_mul(temp1, temp2, temp2);
nmod_mat_swap(temp1, temp2);
nmod_mat_swap_entrywise(temp1, temp2);
}
pow /= 2;
}
Expand Down
2 changes: 1 addition & 1 deletion nmod_poly_mat/mul_classical.c
Expand Up @@ -36,7 +36,7 @@ nmod_poly_mat_mul_classical(nmod_poly_mat_t C, const nmod_poly_mat_t A,
nmod_poly_mat_t T;
nmod_poly_mat_init(T, ar, bc, nmod_poly_mat_modulus(A));
nmod_poly_mat_mul_classical(T, A, B);
nmod_poly_mat_swap(C, T);
nmod_poly_mat_swap_entrywise(C, T);
nmod_poly_mat_clear(T);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion padic_mat.h
Expand Up @@ -188,7 +188,7 @@ padic_mat_swap_entrywise(padic_mat_t mat1, padic_mat_t mat2)

for (i = 0; i < padic_mat_nrows(mat1); i++)
for (j = 0; j < padic_mat_ncols(mat1); j++)
padic_swap(padic_mat_entry(mat2, i, j), padic_mat_entry(mat1, i, j));
fmpz_swap(padic_mat_entry(mat2, i, j), padic_mat_entry(mat1, i, j));
}

FLINT_DLL void padic_mat_zero(padic_mat_t A);
Expand Down

0 comments on commit 9b42913

Please sign in to comment.