forked from flintlib/python-flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflint.pxd
85 lines (67 loc) · 2.49 KB
/
flint.pxd
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
# _flint.pxd
#
# Define fundamental types and constants
cdef extern from "Python.h":
ctypedef void PyObject
cdef enum:
FMPZ_UNKNOWN = 0
FMPZ_REF = 1
FMPZ_TMP = 2
#
# Note: ulong and slong are used throughout Flint/Arb. They are expected to be
# 32 bit unsigned and signed integer types on a 32 bit system and 64 bit on a
# 64 bit system. We denote them as unsigned long and long here which would be
# incorrect on 64 bit Windows but the definition here does not matter because
# their actual sizes will be determined by the values from gmp.h and
# flint/flint.h. Their size in bits (32 or 64) is recorded in the FLINT_BITS
# macro which is defined in flint/flint.h.
#
cdef extern from "gmp.h":
ctypedef unsigned long ulong
ctypedef unsigned long mp_limb_t
ctypedef long mp_size_t
ctypedef long mp_exp_t
ctypedef mp_limb_t* mp_ptr
ctypedef mp_limb_t* mp_srcptr
ctypedef unsigned long mp_bitcnt_t
cdef extern from "flint/fmpz.h":
ctypedef long slong
ctypedef ulong flint_bitcnt_t
ctypedef slong fmpz_struct
cdef extern from "flint/flint.h":
const char * FLINT_VERSION
const int __FLINT_RELEASE
const int FLINT_BITS
ctypedef void * flint_rand_t
void flint_randinit(flint_rand_t state)
void flint_randclear(flint_rand_t state)
void flint_set_num_threads(long)
long flint_get_num_threads()
void flint_cleanup()
cdef extern from *:
"""
/* FLINT_BITS is not known until C compile time. We need to check if long
* or long long matches FLINT_BITS to know which CPython function to call.
*/
#if FLINT_BITS == 32 && LONG_MAX == 2147483647
#define pylong_as_slong PyLong_AsLongAndOverflow
#elif FLINT_BITS == 64 && LLONG_MAX == 9223372036854775807
#define pylong_as_slong PyLong_AsLongLongAndOverflow
#else
#error FLINT_BITS does not match width of long or long long.
#endif
"""
slong pylong_as_slong(PyObject *pylong, int *overflow)
"""
cdef extern from "flint/fmpz_mpoly_factor.h":
ctypedef struct fmpz_mpoly_factor_struct:
fmpz_t content
fmpz_mpoly_struct * poly
fmpz_struct * exp
slong length
slong alloc
ctypedef fmpz_mpoly_factor_struct fmpz_mpoly_factor_t[1]
void fmpz_mpoly_factor_init(fmpz_mpoly_factor_t fac, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_factor_clear(fmpz_mpoly_factor_t fac, const fmpz_mpoly_ctx_t ctx)
int fmpz_mpoly_factor(fmpz_mpoly_factor_t fac, const fmpz_mpoly_t A, int full, const fmpz_mpoly_ctx_t ctx)
"""