File: mul.c

package info (click to toggle)
flint-arb 1%3A2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,028 kB
  • sloc: ansic: 177,109; sh: 553; makefile: 288; python: 268
file content (95 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    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/>.
*/

#include "acb_mat.h"

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;
}

void
acb_mat_mul(acb_mat_t C, const acb_mat_t A, const acb_mat_t B, slong prec)
{
    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);

    if (n >= 20)
    {
        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;
        }
    }

    if (flint_get_num_threads() > 1 &&
        ((double) ar * (double) ac * (double) bc * (double) prec > 100000))
    {
        acb_mat_mul_threaded(C, A, B, prec);
    }
    else
    {
        acb_mat_mul_classical(C, A, B, prec);
    }
}