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

Introduce submodules into python-flint #61

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
aade052
update imports to include utils
GiacomoPope Aug 17, 2023
5ffb83e
refactor out some util functions from pyflint
GiacomoPope Aug 17, 2023
a4511c9
Refactor out context class from pyflint
GiacomoPope Aug 17, 2023
304dd67
remove some globals from pyflint
GiacomoPope Aug 17, 2023
b5b1831
include DS_Store to gitignore
GiacomoPope Aug 17, 2023
06064b0
EOF
GiacomoPope Aug 17, 2023
f36b681
Add submodule
GiacomoPope Aug 17, 2023
7b7d2d2
EOF
GiacomoPope Aug 17, 2023
622c671
Reverse old formatting
GiacomoPope Aug 17, 2023
2dee3db
Fix relative imports and now get a proper error
GiacomoPope Aug 17, 2023
0f5d236
Factor out into submodule
GiacomoPope Aug 18, 2023
726a699
ensure submodule c files are skipped
GiacomoPope Aug 18, 2023
b3e5ec9
Refactor out more conversions
GiacomoPope Aug 18, 2023
b8be99b
move away from depreciated properties
GiacomoPope Aug 18, 2023
f7c3bfc
Refactor set up for inclusion of submodules
GiacomoPope Aug 18, 2023
4e5310b
move context into new submodule
GiacomoPope Aug 18, 2023
4d7ad87
Import thectx from module and set ctx
GiacomoPope Aug 18, 2023
039e687
Import precision / cap inline functions previously defined as global
GiacomoPope Aug 18, 2023
e76daf4
Global context need not be an extension, as its not defining a new class
GiacomoPope Aug 18, 2023
f09b791
remove template classes
GiacomoPope Aug 18, 2023
522c50a
Add templates as a submodule
GiacomoPope Aug 18, 2023
8b1190f
delete unneeded file
GiacomoPope Aug 18, 2023
718b1fc
Include needed classes for each flint type
GiacomoPope Aug 18, 2023
38c9ffd
Actually include the new files
GiacomoPope Aug 18, 2023
3ab97f6
Make flint_poly a global until issue #62 is resolved
GiacomoPope Aug 18, 2023
a4d3a85
Remove imports until they're ready
GiacomoPope Aug 18, 2023
9a3fd0b
remove old pxd
GiacomoPope Aug 18, 2023
457f429
remove old pxd
GiacomoPope Aug 18, 2023
4a16f0e
Update imports
GiacomoPope Aug 18, 2023
644b5bb
Add all global context into this file
GiacomoPope Aug 18, 2023
da48588
Merge pull request #61 from GiacomoPope/introduce-submodules
oscarbenjamin Aug 18, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ MANIFEST
.coverage
*.swp
.python-version
*.DS_Store
82 changes: 46 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
from distutils.sysconfig import get_config_vars


if sys.platform == 'win32':
if sys.platform == "win32":
#
# This is used in CI to build wheels with mingw64
#
if os.getenv('PYTHON_FLINT_MINGW64'):
if os.getenv("PYTHON_FLINT_MINGW64"):
libraries = ["arb", "flint", "mpfr", "gmp"]
includedir = os.path.join(os.path.dirname(__file__), '.local', 'include')
librarydir1 = os.path.join(os.path.dirname(__file__), '.local', 'bin')
librarydir2 = os.path.join(os.path.dirname(__file__), '.local', 'lib')
includedir = os.path.join(os.path.dirname(__file__), ".local", "include")
librarydir1 = os.path.join(os.path.dirname(__file__), ".local", "bin")
librarydir2 = os.path.join(os.path.dirname(__file__), ".local", "lib")
librarydirs = [librarydir1, librarydir2]
default_include_dirs += [includedir]
default_lib_dirs += librarydirs
# Add gcc to the PATH in GitHub Actions when this setup.py is called by
# cibuildwheel.
os.environ['PATH'] += r';C:\msys64\mingw64\bin'
elif os.getenv('PYTHON_FLINT_MINGW64_TMP'):
os.environ["PATH"] += r";C:\msys64\mingw64\bin"
elif os.getenv("PYTHON_FLINT_MINGW64_TMP"):
# This would be used to build under Windows against these libraries if
# they have been installed somewhere other than .local
libraries = ["arb", "flint", "mpfr", "gmp"]
Expand All @@ -35,60 +35,70 @@
libraries = ["arb", "flint", "mpir", "mpfr", "pthreads"]
else:
# On Ubuntu libarb.so is called libflint-arb.so
if os.getenv('PYTHON_FLINT_LIBFLINT_ARB'):
arb = 'flint-arb'
if os.getenv("PYTHON_FLINT_LIBFLINT_ARB"):
arb = "flint-arb"
else:
arb = 'arb'
arb = "arb"

libraries = [arb, "flint"]
(opt,) = get_config_vars('OPT')
os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes')
(opt,) = get_config_vars("OPT")
os.environ["OPT"] = " ".join(
flag for flag in opt.split() if flag != "-Wstrict-prototypes"
)
GiacomoPope marked this conversation as resolved.
Show resolved Hide resolved


default_include_dirs += [
os.path.join(d, "flint") for d in default_include_dirs
]
default_include_dirs += [os.path.join(d, "flint") for d in default_include_dirs]


define_macros = []
compiler_directives = {
'language_level': 3,
'binding': False,
"language_level": 3,
"binding": False,
}


# Enable coverage tracing
if os.getenv('PYTHON_FLINT_COVERAGE'):
define_macros.append(('CYTHON_TRACE', 1))
compiler_directives['linetrace'] = True
if os.getenv("PYTHON_FLINT_COVERAGE"):
define_macros.append(("CYTHON_TRACE", 1))
compiler_directives["linetrace"] = True


ext_modules = [
Extension(
"flint._flint", ["src/flint/pyflint.pyx"],
"flint._flint",
["src/flint/pyflint.pyx"],
libraries=libraries,
library_dirs=default_lib_dirs,
include_dirs=default_include_dirs,
define_macros=define_macros,
),
Extension(
"flint.flint_base.flint_context",
["src/flint/flint_base/flint_context.pyx"],
libraries=libraries,
library_dirs=default_lib_dirs,
include_dirs=default_include_dirs,
define_macros=define_macros,
)
),
]

for e in ext_modules:
e.cython_directives = {"embedsignature": True}

setup(
name='python-flint',
cmdclass={'build_ext': build_ext},
name="python-flint",
cmdclass={"build_ext": build_ext},
ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives),
#ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives, annotate=True),
packages=['flint', 'flint.test'],
package_dir={'': 'src'},
description='Bindings for FLINT and Arb',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
version='0.4.1',
url='https://github.com/python-flint/python-flint',
author='Fredrik Johansson',
author_email='[email protected]',
license='MIT',
classifiers=['Topic :: Scientific/Engineering :: Mathematics'])
# ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives, annotate=True),
packages=["flint", "flint.test"],
package_dir={"": "src"},
description="Bindings for FLINT and Arb",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
version="0.4.1",
url="https://github.com/python-flint/python-flint",
author="Fredrik Johansson",
author_email="[email protected]",
license="MIT",
classifiers=["Topic :: Scientific/Engineering :: Mathematics"],
)
2 changes: 2 additions & 0 deletions src/flint/arf.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .utils.conversion cimport prec_to_dps

cdef class arf:

cdef arf_t val
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions src/flint/flint_base/flint_context.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cdef class FlintContext:
pass
78 changes: 78 additions & 0 deletions src/flint/flint_base/flint_context.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from ._flint cimport (
ARF_RND_DOWN,
arf_rnd_t,
flint_cleanup,
flint_get_num_threads,
flint_set_num_threads
)
from .utils.conversion cimport prec_to_dps, dps_to_prec

cdef class FlintContext:
cdef public bint pretty
cdef public long _prec
cdef public long _dps
cdef arf_rnd_t rnd
cdef public bint unicode
cdef public long _cap

def __init__(self):
self.default()

def default(self):
self.pretty = True
self.rnd = ARF_RND_DOWN
self.prec = 53
self.unicode = False
self.threads = 1
self.cap = 10

property prec:

def __set__(self, prec):
cdef long cprec = prec
if cprec < 2:
raise ValueError("prec must be >= 2")
self._prec = cprec
self._dps = prec_to_dps(cprec)

def __get__(self):
return self._prec

property dps:

def __set__(self, prec):
self.prec = dps_to_prec(prec)

def __get__(self):
return self._dps

property cap:

def __set__(self, long cap):
if cap < 0:
raise ValueError("cap must be >= 0")
self._cap = cap

def __get__(self):
return self._cap

property threads:

def __set__(self, long num):
assert num >= 1 and num <= 64
flint_set_num_threads(num)

def __get__(self):
return flint_get_num_threads()

def __repr__(self):
return "pretty = %-8s # pretty-print repr() output\n" \
"unicode = %-8s # use unicode characters in output\n" \
"prec = %-8s # real/complex precision (in bits)\n" \
"dps = %-8s # real/complex precision (in digits)\n" \
"cap = %-8s # power series precision\n" \
"threads = %-8s # max number of threads used internally\n" % \
(self.pretty, self.unicode, self.prec, self.dps, self.cap, self.threads)

def cleanup(self):
flint_cleanup()
2 changes: 2 additions & 0 deletions src/flint/functions.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .utils.conversion cimport dps_to_prec

# xxx: this doesn't work when changed to a cdef function. why?
def __goodness(x, bint parts=True, metric=None):
if metric is not None:
Expand Down
79 changes: 2 additions & 77 deletions src/flint/pyflint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cimport flint
cimport libc.stdlib
cimport cython

from .flint_base.flint_context cimport FlintContext

cdef flint_rand_t global_random_state
flint_randinit(global_random_state)

Expand Down Expand Up @@ -56,83 +58,6 @@ DEF FMPZ_UNKNOWN = 0
DEF FMPZ_REF = 1
DEF FMPZ_TMP = 2


cdef long prec_to_dps(n):
return max(1, int(round(int(n)/3.3219280948873626)-1))

cdef long dps_to_prec(n):
return max(1, int(round((int(n)+1)*3.3219280948873626)))

cdef class FlintContext:
cdef public bint pretty
cdef public long _prec
cdef public long _dps
cdef arf_rnd_t rnd
cdef public bint unicode
cdef public long _cap

def __init__(self):
self.default()

def default(self):
self.pretty = True
self.rnd = ARF_RND_DOWN
self.prec = 53
self.unicode = False
self.threads = 1
self.cap = 10

property prec:

def __set__(self, prec):
cdef long cprec = prec
if cprec < 2:
raise ValueError("prec must be >= 2")
self._prec = cprec
self._dps = prec_to_dps(cprec)

def __get__(self):
return self._prec

property dps:

def __set__(self, prec):
self.prec = dps_to_prec(prec)

def __get__(self):
return self._dps

property cap:

def __set__(self, long cap):
if cap < 0:
raise ValueError("cap must be >= 0")
self._cap = cap

def __get__(self):
return self._cap

property threads:

def __set__(self, long num):
assert num >= 1 and num <= 64
flint_set_num_threads(num)

def __get__(self):
return flint_get_num_threads()

def __repr__(self):
return "pretty = %-8s # pretty-print repr() output\n" \
"unicode = %-8s # use unicode characters in output\n" \
"prec = %-8s # real/complex precision (in bits)\n" \
"dps = %-8s # real/complex precision (in digits)\n" \
"cap = %-8s # power series precision\n" \
"threads = %-8s # max number of threads used internally\n" % \
(self.pretty, self.unicode, self.prec, self.dps, self.cap, self.threads)

def cleanup(self):
flint_cleanup()

cdef FlintContext thectx = FlintContext()

ctx = thectx
Expand Down
Empty file added src/flint/utils/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions src/flint/utils/conversion.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cdef inline long prec_to_dps(n):
return max(1, int(round(int(n)/3.3219280948873626)-1))

cdef inline long dps_to_prec(n):
return max(1, int(round((int(n)+1)*3.3219280948873626)))