arb/acb_mat/mul.c

96 lines
2 KiB
C
Raw Normal View History

/*
2014-05-15 19:56:11 +02:00
Copyright (C) 2012 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
2014-05-15 19:56:11 +02:00
#include "acb_mat.h"
2018-07-02 22:06:53 +02:00
static slong
acb_mat_bits(const acb_mat_t A)
{
slong b, t, i, ar, ac;
ar = acb_mat_nrows(A);
ac = acb_mat_ncols(A);
b = 0;
for (i = 0; i < ar; i++)
{
t = _arb_vec_bits((arb_srcptr) A->rows[i], 2 * ac);
b = FLINT_MAX(b, t);
}
return b;
}
int acb_mat_is_lagom(const acb_mat_t A)
{
slong i, j, M, N;
M = acb_mat_nrows(A);
N = acb_mat_ncols(A);
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
{
if (!ARB_IS_LAGOM(acb_realref(acb_mat_entry(A, i, j))) ||
!ARB_IS_LAGOM(acb_imagref(acb_mat_entry(A, i, j))))
return 0;
}
}
return 1;
}
2014-05-15 19:56:11 +02:00
void
acb_mat_mul(acb_mat_t C, const acb_mat_t A, const acb_mat_t B, slong prec)
2014-05-15 19:56:11 +02:00
{
2018-07-02 22:06:53 +02:00
slong ar, ac, br, bc, n, abits, bbits, bits;
ar = acb_mat_nrows(A);
ac = acb_mat_ncols(A);
br = acb_mat_nrows(B);
bc = acb_mat_ncols(B);
if (ac != br || ar != acb_mat_nrows(C) || bc != acb_mat_ncols(C))
{
flint_printf("acb_mat_mul: incompatible dimensions\n");
flint_abort();
}
n = FLINT_MIN(ar, ac);
n = FLINT_MIN(ac, bc);
2018-09-04 15:27:37 +02:00
if (n >= 20)
2018-07-02 22:06:53 +02:00
{
abits = acb_mat_bits(A);
bbits = acb_mat_bits(B);
bits = FLINT_MIN(prec, FLINT_MAX(abits, bbits));
if (bits < 8000 && n >= 5 + bits / 64)
{
acb_mat_mul_reorder(C, A, B, prec);
return;
}
}
2017-08-01 14:01:05 +02:00
if (flint_get_num_threads() > 1 &&
2018-07-02 22:06:53 +02:00
((double) ar * (double) ac * (double) bc * (double) prec > 100000))
2014-05-15 19:56:11 +02:00
{
2017-08-01 14:01:05 +02:00
acb_mat_mul_threaded(C, A, B, prec);
2014-05-15 19:56:11 +02:00
}
2017-08-01 14:01:05 +02:00
else
2014-05-15 19:56:11 +02:00
{
2017-08-01 14:01:05 +02:00
acb_mat_mul_classical(C, A, B, prec);
2014-05-15 19:56:11 +02:00
}
}
2017-08-01 14:01:05 +02:00