1 /*
2 Copyright (C) 2018 Daniel Schultz
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <https://www.gnu.org/licenses/>.
10 */
11
12 #include "mpoly.h"
13
14 /* this file does not need to change with new orderings */
15
16 /* unpack the field-wise maximum of poly_exps into max_fields */
mpoly_max_fields_ui_sp(ulong * max_fields,const ulong * poly_exps,slong len,flint_bitcnt_t bits,const mpoly_ctx_t mctx)17 void mpoly_max_fields_ui_sp(ulong * max_fields, const ulong * poly_exps,
18 slong len, flint_bitcnt_t bits, const mpoly_ctx_t mctx)
19 {
20 slong i, N;
21 ulong * pmax, mask;
22 TMP_INIT;
23
24 FLINT_ASSERT(bits <= FLINT_BITS);
25
26 N = mpoly_words_per_exp_sp(bits, mctx);
27
28 mask = 0;
29 for (i = 0; i < FLINT_BITS/bits; i++)
30 mask = (mask << bits) + (UWORD(1) << (bits - 1));
31
32 TMP_START;
33
34 pmax = (ulong *) TMP_ALLOC(N*sizeof(ulong));
35 for (i = 0; i < N; i++)
36 pmax[i] = 0;
37 for (i = 0; i < len; i++)
38 mpoly_monomial_max(pmax, pmax, poly_exps + N*i, bits, N, mask);
39
40 mpoly_unpack_vec_ui(max_fields, pmax, bits, mctx->nfields, 1);
41
42 TMP_END;
43 }
44
45
mpoly_max_fields_fmpz(fmpz * max_fields,const ulong * poly_exps,slong len,flint_bitcnt_t bits,const mpoly_ctx_t mctx)46 void mpoly_max_fields_fmpz(fmpz * max_fields, const ulong * poly_exps,
47 slong len, flint_bitcnt_t bits, const mpoly_ctx_t mctx)
48 {
49 slong i, N;
50 ulong * pmax, mask;
51 TMP_INIT;
52
53 TMP_START;
54
55 N = mpoly_words_per_exp(bits, mctx);
56 pmax = (ulong *) TMP_ALLOC(N*sizeof(ulong));
57 for (i = 0; i < N; i++)
58 pmax[i] = 0;
59
60 if (bits <= FLINT_BITS)
61 {
62 mask = 0;
63 for (i = 0; i < FLINT_BITS/bits; i++)
64 mask = (mask << bits) + (UWORD(1) << (bits - 1));
65
66 for (i = 0; i < len; i++)
67 mpoly_monomial_max(pmax, pmax, poly_exps + N*i, bits, N, mask);
68 }
69 else
70 {
71 for (i = 0; i < len; i++)
72 mpoly_monomial_max_mp(pmax, pmax, poly_exps + N*i, bits, N);
73 }
74
75 mpoly_unpack_vec_fmpz(max_fields, pmax, bits, mctx->nfields, 1);
76
77 TMP_END;
78 }
79