Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
made numpy an optional install
Browse files Browse the repository at this point in the history
  • Loading branch information
rjdbcm committed Nov 12, 2021
1 parent 57a6a47 commit 7cb64dc
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 99 deletions.
9 changes: 6 additions & 3 deletions Aspidites/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from math import inf, isinf, nan, isnan
from math import factorial
import numbers
import numpy as np
from .api import Warn
try:
import numpy as np
Numeric = Union[int, float, complex, np.number]
except ModuleNotFoundError:
Numeric = Union[int, float, complex]

Numeric = Union[int, float, complex, np.number]
from .api import Warn


class Undefined:
Expand Down
8 changes: 6 additions & 2 deletions Aspidites/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
from setuptools import setup, Extension
from Cython.Build import cythonize, BuildExecutable
from Cython.Compiler import Options
import numpy
try:
from numpy import get_include
except:
def get_include():
return sysconfig.get_config_vars()['CONFINCLUDEPY']
Options.annotate=$annotate
Options.annotate_coverage_xml=$annotate_coverage_xml
Options.buffer_max_dims=$buffer_max_dims
Expand All @@ -128,7 +132,7 @@
Options.lookup_module_cpdef=$lookup_module_cpdef
Options.embed=$embed
exts=[Extension('$app_name',['$src_file'],include_dirs=$inc_dirs,libraries=$libs,extra_compile_args=['-Wall','-O2'],library_dirs=$lib_dirs),]
setup(name='$app_name',ext_modules=cythonize(exts,include_path=[numpy.get_include()]))
setup(name='$app_name',ext_modules=cythonize(exts,include_path=[get_include()]))
if Options.embed: BuildExecutable.build('$src_file')
""")
Expand Down
10 changes: 7 additions & 3 deletions Aspidites/tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ def test_undefined_sanity():
with pytest.raises(TypeError):
from math import isnan
assert isnan(complex(Undefined())) == isnan(complex(nan))
from numpy import isnan
assert isnan(complex(Undefined())) == isnan(complex(nan))
del isnan
try:
from numpy import isnan
except:
pass
else:
assert isnan(complex(Undefined())) == isnan(complex(nan))
del isnan
from math import isnan
assert isnan(float(Undefined())) == isnan(float(nan))
assert Surely() == Surely()
Expand Down
3 changes: 3 additions & 0 deletions Aspidites/woma/library.wom
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@

(mul(x = 0 -> number; y = 0 -> number)) number
<*> x * y

(neg(x = 0 -> number)) number
<*> -x
19 changes: 19 additions & 0 deletions dev/scripts/cprofile_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cProfile
import pstats
import io
import csv


def prof_to_csv(prof):
out_stream = io.StringIO()
pstats.Stats(prof, stream=out_stream).print_stats()
result = out_stream.getvalue()
# chop off header lines
result = 'ncalls' + result.split('ncalls')[-1]
lines = [','.join(line.rstrip().split(None, 5)) for line in result.split('\n')]
return '\n'.join(lines)


if __name__ == '__main__':
with open('combined.csv', 'w') as out:
print(prof_to_csv('combined.prof'), file=out)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "Cython", "numpy", "pytest", "future"]
requires = ["setuptools", "wheel", "Cython", "pytest", "future"]
268 changes: 178 additions & 90 deletions setup.py

Large diffs are not rendered by default.

0 comments on commit 7cb64dc

Please sign in to comment.