Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fmpz mod mpoly and nmod mpoly #164

Merged
merged 32 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4a72a37
Initial addition of fmpz_mod_mpoly and nmod_mpoly
Jake-Moss Jul 15, 2024
a82d4ed
First pass at a copy-paste of fmpz_mpoly -> fmpz_mod_mpoly
Jake-Moss Jul 15, 2024
8c073ae
Catch a failed factorisation, using runtime error for now
Jake-Moss Jul 18, 2024
d2e8a00
Add fmpz_mod_mpoly_factor and nmod_mpoly_factor
Jake-Moss Jul 18, 2024
53a5dbb
Copy-paste error
Jake-Moss Jul 18, 2024
e8be1e3
Add fmpz_mod_mpoly. Based on fmpz_mpoly
Jake-Moss Jul 18, 2024
89c088b
Cram fmpz_mod_mpoly into existing mpoly tests for now
Jake-Moss Jul 18, 2024
004ae4b
Update get_context call signature in doc strings
Jake-Moss Jul 18, 2024
a24ea8d
Initial nmod_mpoly work, not complete
Jake-Moss Jul 25, 2024
e0512bc
Second pass at nmod_mpoly, better int handling, update tests
Jake-Moss Jul 28, 2024
805fd34
Replace numpy + memoryview with malloc
Jake-Moss Jul 28, 2024
5a7de35
Merge remote-tracking branch 'origin/master' into fmpz_mod_mpoly_and_…
Jake-Moss Jul 28, 2024
51a572e
Mirror f24f9aa
Jake-Moss Jul 28, 2024
accffa9
Support comparisons with more literals
Jake-Moss Aug 7, 2024
48136d1
More nmod interop
Jake-Moss Aug 7, 2024
84fbf91
Fix Windows specific memory error (32 vs 64 bit issue)
Jake-Moss Aug 13, 2024
3989b50
Merge remote-tracking branch 'origin/master' into fmpz_mod_mpoly_and_…
Jake-Moss Aug 13, 2024
f15b55a
Add missing argument to `flint_scalar._any_as_self`
Jake-Moss Aug 13, 2024
e3120cf
Add modules to setup.py
Jake-Moss Aug 13, 2024
abe80c1
Remove duplicated ctypedef for nmod_t
Jake-Moss Aug 14, 2024
0cf8237
Merge remote-tracking branch 'origin/master' into fmpz_mod_mpoly_and_…
Aug 16, 2024
c740fec
Doc changes
Aug 16, 2024
72e220e
sizeof(ulong) fix
Aug 16, 2024
4526d2b
Simplify call argument checks
Aug 16, 2024
043ca9d
Add support for fmpz_mod and nmod interop
Aug 16, 2024
f2fa712
Wrong variable
Aug 17, 2024
9abc8d2
Generic add and divmod POC methods
Aug 17, 2024
e2b6369
Significantly clean up nmod_mpoly type conversion
Aug 17, 2024
c08fdb0
Fix nmod type errors, no clue how this worked at all
Aug 17, 2024
789ad00
Reverse changes to fmpz_vec
Aug 17, 2024
a2573c1
Refactor fmpz_mod_mpoly
Aug 17, 2024
1358a67
Update tests, make "division not support" exception lowest priority
Aug 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@
("flint.types.nmod_poly", ["src/flint/types/nmod_poly.pyx"]),
("flint.types.nmod_mat", ["src/flint/types/nmod_mat.pyx"]),
("flint.types.nmod_series", ["src/flint/types/nmod_series.pyx"]),
("flint.types.nmod_mpoly", ["src/flint/types/nmod_mpoly.pyx"]),

("flint.types.fmpz_mod", ["src/flint/types/fmpz_mod.pyx"]),
("flint.types.fmpz_mod_poly", ["src/flint/types/fmpz_mod_poly.pyx"]),
("flint.types.fmpz_mod_mpoly", ["src/flint/types/fmpz_mod_mpoly.pyx"]),
("flint.types.fmpz_mod_mat", ["src/flint/types/fmpz_mod_mat.pyx"]),

("flint.types.fmpq_mpoly", ["src/flint/types/fmpq_mpoly.pyx"]),
Expand Down
2 changes: 2 additions & 0 deletions src/flint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

from .types.nmod import *
from .types.nmod_poly import *
from .types.nmod_mpoly import nmod_mpoly_ctx, nmod_mpoly, nmod_mpoly_vec
from .types.nmod_mat import *
from .types.nmod_series import *

from .types.fmpz_mpoly import fmpz_mpoly_ctx, fmpz_mpoly, fmpz_mpoly_vec
from .types.fmpz_mod import *
from .types.fmpz_mod_poly import *
from .types.fmpz_mod_mpoly import fmpz_mod_mpoly_ctx, fmpz_mod_mpoly, fmpz_mod_mpoly_vec
from .types.fmpz_mod_mat import fmpz_mod_mat

from .types.fmpq_mpoly import fmpq_mpoly_ctx, fmpq_mpoly, fmpq_mpoly_vec
Expand Down
20 changes: 14 additions & 6 deletions src/flint/flint_base/flint_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef class flint_scalar(flint_elem):
def is_zero(self):
return False

def _any_as_self(self):
def _any_as_self(self, other):
return NotImplemented

def _neg_(self):
Expand Down Expand Up @@ -329,14 +329,13 @@ cdef class flint_mpoly_context(flint_elem):
return nametup

@classmethod
def get_context(cls, slong nvars=1, ordering=Ordering.lex, names: Optional[str] = "x", nametup: Optional[tuple] = None):
def create_context_key(cls, slong nvars=1, ordering=Ordering.lex, names: Optional[str] = "x", nametup: Optional[tuple] = None):
"""
Retrieve a context via the number of variables, `nvars`, the ordering, `ordering`, and either a variable
name string, `names`, or a tuple of variable names, `nametup`.
Create a key for the context cache via the number of variables, the ordering, and
either a variable name string, or a tuple of variable names.
"""

# A type hint of `ordering: Ordering` results in the error "TypeError: an integer is required" if a Ordering
# object is not provided. This is pretty obtuse so we check it's type ourselves
# object is not provided. This is pretty obtuse so we check its type ourselves
if not isinstance(ordering, Ordering):
raise TypeError(f"`ordering` ('{ordering}') is not an instance of flint.Ordering")

Expand All @@ -346,6 +345,15 @@ cdef class flint_mpoly_context(flint_elem):
key = nvars, ordering, cls.create_variable_names(nvars, names)
else:
raise ValueError("must provide either `names` or `nametup`")
return key

@classmethod
def get_context(cls, *args, **kwargs):
"""
Retrieve a context via the number of variables, `nvars`, the ordering, `ordering`, and either a variable
name string, `names`, or a tuple of variable names, `nametup`.
"""
key = cls.create_context_key(*args, **kwargs)

ctx = cls._ctx_cache.get(key)
if ctx is None:
Expand Down
9 changes: 9 additions & 0 deletions src/flint/flintlib/flint.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ cdef extern from *:
"""

cdef extern from "flint/flint.h":
"""
#define SIZEOF_ULONG sizeof(ulong)
"""
int SIZEOF_ULONG
const char * FLINT_VERSION
const int __FLINT_RELEASE
const int FLINT_BITS
Expand All @@ -60,6 +64,11 @@ cdef extern from "flint/flint.h":
long flint_get_num_threads()
void flint_cleanup()

ctypedef struct nmod_t:
mp_limb_t n
mp_limb_t ninv
flint_bitcnt_t norm
Jake-Moss marked this conversation as resolved.
Show resolved Hide resolved

cdef extern from *:
"""
/* FLINT_BITS is not known until C compile time. We need to check if long
Expand Down
176 changes: 176 additions & 0 deletions src/flint/flintlib/fmpz_mod_mpoly.pxd

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/flint/flintlib/fmpz_mod_mpoly_factor.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flint.flintlib.flint cimport slong
from flint.flintlib.fmpz cimport fmpz_t, fmpz_struct
from flint.flintlib.fmpz_mod_mpoly cimport fmpz_mod_mpoly_ctx_t, fmpz_mod_mpoly_t, fmpz_mod_mpoly_struct


cdef extern from "flint/fmpz_mod_mpoly_factor.h":
ctypedef struct fmpz_mod_mpoly_factor_struct:
fmpz_t constant
fmpz_mod_mpoly_struct * poly
fmpz_struct * exp
slong num
slong alloc

ctypedef fmpz_mod_mpoly_factor_struct fmpz_mod_mpoly_factor_t[1]

void fmpz_mod_mpoly_factor_init(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_clear(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_swap(fmpz_mod_mpoly_factor_t f, fmpz_mod_mpoly_factor_t g, const fmpz_mod_mpoly_ctx_t ctx)
slong fmpz_mod_mpoly_factor_length(const fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_get_constant_fmpz(fmpz_t c, const fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_get_base(fmpz_mod_mpoly_t B, const fmpz_mod_mpoly_factor_t f, slong i, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_swap_base(fmpz_mod_mpoly_t B, fmpz_mod_mpoly_factor_t f, slong i, const fmpz_mod_mpoly_ctx_t ctx)
slong fmpz_mod_mpoly_factor_get_exp_si(fmpz_mod_mpoly_factor_t f, slong i, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_factor_sort(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_ctx_t ctx)
int fmpz_mod_mpoly_factor_squarefree(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_t A, const fmpz_mod_mpoly_ctx_t ctx)
int fmpz_mod_mpoly_factor(fmpz_mod_mpoly_factor_t f, const fmpz_mod_mpoly_t A, const fmpz_mod_mpoly_ctx_t ctx)
2 changes: 0 additions & 2 deletions src/flint/flintlib/fmpz_mpoly_factor.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ from flint.flintlib.flint cimport slong, fmpz_struct
from flint.flintlib.fmpq cimport fmpq_t


# unimported types set()

cdef extern from "flint/fmpz_mpoly_factor.h":

ctypedef struct fmpz_mpoly_factor_struct:
Expand Down
6 changes: 1 addition & 5 deletions src/flint/flintlib/nmod.pxd
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from flint.flintlib.flint cimport mp_limb_t, mp_bitcnt_t, ulong
from flint.flintlib.flint cimport mp_limb_t, mp_bitcnt_t, ulong, nmod_t
from flint.flintlib.fmpz cimport fmpz_t

cdef extern from "flint/nmod.h":
ctypedef struct nmod_t:
mp_limb_t n
mp_limb_t ninv
mp_bitcnt_t norm
# TODO add macros

# from here on is parsed
Expand Down
Loading
Loading