File: t-cache_insert.c

package info (click to toggle)
calcium 0.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,756 kB
  • sloc: ansic: 62,836; python: 2,827; sh: 518; makefile: 163
file content (118 lines) | stat: -rw-r--r-- 3,026 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
    Copyright (C) 2020 Fredrik Johansson

    This file is part of Calcium.

    Calcium 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 "ca.h"
#include "ca_ext.h"
#include "ca_field.h"

static int _ca_field_equal_ext(const ca_field_t K, ca_ext_struct ** x, slong len, ca_ctx_t ctx)
{
    slong i;

    if (len != CA_FIELD_LENGTH(K))
        return 0;

    for (i = 0; i < len; i++)
        if (CA_FIELD_EXT_ELEM(K, i) != x[i])
            return 0;

    return 1;
}

int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("cache_insert....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000 * calcium_test_multiplier(); iter++)
    {
        ca_ctx_t ctx;
        ca_ext_struct ** ext;
        ca_ext_struct * all_ext;
        ca_field_cache_t cache;
        ca_field_struct *K, *K2;
        qqbar_t x;
        ca_t v;
        slong i, j, steps, len, ext_len;

        ca_ctx_init(ctx);
        qqbar_init(x);
        ca_init(v, ctx);

        ext_len = 1 + n_randint(state, 10);
        steps = n_randint(state, 100);

        all_ext = flint_malloc(sizeof(ca_ext_struct) * ext_len);
        for (j = 0; j < ext_len; j++)
        {
            if (n_randint(state, 10) != 0)
            {
                ca_set_ui(v, j + 2, ctx);
                ca_ext_init_fx(all_ext + j, CA_RiemannZeta, v, ctx);
            }
            else
            {
                qqbar_set_ui(x, j);
                ca_ext_init_qqbar(all_ext + j, x, ctx);
            }
        }

        ca_field_cache_init(cache, ctx);

        for (i = 0; i < steps; i++)
        {
            len = n_randint(state, 10);

            ext = flint_malloc(len * sizeof(ca_ext_struct *));

            for (j = 0; j < len; j++)
                ext[j] = all_ext + n_randint(state, ext_len);

            K = ca_field_cache_insert_ext(cache, ext, len, ctx);
            K2 = ca_field_cache_insert_ext(cache, ext, len, ctx);

            if (!_ca_field_equal_ext(K, ext, len, ctx) || K != K2)
            {
                flint_printf("FAIL\n\n");
                flint_printf("K = "); ca_field_print(K, ctx); flint_printf("\n\n");
                flint_printf("ext = \n\n");
                for (j = 0; j < len; j++)
                {
                    ca_ext_print(ext[j], ctx); flint_printf("\n\n");
                }
                flint_abort();
            }

            flint_free(ext);
        }

        for (j = 0; j < ext_len; j++)
            ca_ext_clear(all_ext + j, ctx);

        flint_free(all_ext);

        ca_field_cache_clear(cache, ctx);
        ca_clear(v, ctx);
        ca_ctx_clear(ctx);
        qqbar_clear(x);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}