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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
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"
void
_ca_ctx_init_mctx(ca_ctx_t ctx, slong len)
{
while (ctx->mctx_len < len)
{
slong i, alloc;
alloc = FLINT_MAX(1, 2 * ctx->mctx_len);
ctx->mctx = flint_realloc(ctx->mctx, alloc * sizeof(fmpz_mpoly_ctx_struct *));
for (i = ctx->mctx_len; i < alloc; i++)
{
ctx->mctx[i] = flint_malloc(sizeof(fmpz_mpoly_ctx_struct));
fmpz_mpoly_ctx_init(ctx->mctx[i], i + 1, ctx->options[CA_OPT_MPOLY_ORD]);
}
ctx->mctx_len = alloc;
}
}
void
ca_field_init_qq(ca_field_t K, ca_ctx_t ctx)
{
CA_FIELD_LENGTH(K) = 0;
CA_FIELD_EXT(K) = NULL;
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = 0;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = 0;
}
void
ca_field_init_nf(ca_field_t K, const qqbar_t x, ca_ctx_t ctx)
{
ca_ext_ptr ext;
ca_ext_t tmp;
/* todo: avoid unnecessary work (especially the nf_t init) */
ca_ext_init_qqbar(tmp, x, ctx);
ext = ca_ext_cache_insert(CA_CTX_EXT_CACHE(ctx), tmp, ctx);
ca_ext_clear(tmp, ctx);
CA_FIELD_LENGTH(K) = 1;
CA_FIELD_EXT(K) = flint_malloc(sizeof(ca_ext_ptr));
CA_FIELD_EXT_ELEM(K, 0) = ext;
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = -1;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = CA_EXT_HASH(ext);
}
void
ca_field_init_const(ca_field_t K, calcium_func_code func, ca_ctx_t ctx)
{
ca_ext_ptr ext;
ca_ext_t tmp;
/* todo: avoid unnecessary work */
ca_ext_init_const(tmp, func, ctx);
ext = ca_ext_cache_insert(CA_CTX_EXT_CACHE(ctx), tmp, ctx);
ca_ext_clear(tmp, ctx);
CA_FIELD_LENGTH(K) = 1;
CA_FIELD_EXT(K) = flint_malloc(sizeof(ca_ext_ptr));
CA_FIELD_EXT_ELEM(K, 0) = ext;
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = 0;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = CA_EXT_HASH(ext);
_ca_ctx_init_mctx(ctx, 1);
}
void ca_field_init_fx(ca_field_t K, calcium_func_code func, const ca_t x, ca_ctx_t ctx)
{
ca_ext_ptr ext;
ca_ext_t tmp;
/* todo: avoid unnecessary work */
ca_ext_init_fx(tmp, func, x, ctx);
ext = ca_ext_cache_insert(CA_CTX_EXT_CACHE(ctx), tmp, ctx);
ca_ext_clear(tmp, ctx);
CA_FIELD_LENGTH(K) = 1;
CA_FIELD_EXT(K) = flint_malloc(sizeof(ca_ext_ptr));
CA_FIELD_EXT_ELEM(K, 0) = ext;
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = 0;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = CA_EXT_HASH(ext);
_ca_ctx_init_mctx(ctx, 1);
}
void ca_field_init_fxy(ca_field_t K, calcium_func_code func, const ca_t x, const ca_t y, ca_ctx_t ctx)
{
ca_ext_ptr ext;
ca_ext_t tmp;
/* todo: avoid unnecessary work */
ca_ext_init_fxy(tmp, func, x, y, ctx);
ext = ca_ext_cache_insert(CA_CTX_EXT_CACHE(ctx), tmp, ctx);
ca_ext_clear(tmp, ctx);
CA_FIELD_LENGTH(K) = 1;
CA_FIELD_EXT(K) = flint_malloc(sizeof(ca_ext_ptr));
CA_FIELD_EXT_ELEM(K, 0) = ext;
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = 0;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = CA_EXT_HASH(ext);
_ca_ctx_init_mctx(ctx, 2);
}
void
ca_field_init_multi(ca_field_t K, slong len, ca_ctx_t ctx)
{
CA_FIELD_LENGTH(K) = len;
CA_FIELD_EXT(K) = flint_malloc(len * sizeof(ca_ext_ptr));
CA_FIELD_IDEAL_P(K) = NULL;
CA_FIELD_IDEAL_LENGTH(K) = 0;
CA_FIELD_IDEAL_ALLOC(K) = 0;
CA_FIELD_HASH(K) = 0;
_ca_ctx_init_mctx(ctx, len);
}
|