Skip to content

Commit

Permalink
a lot of test
Browse files Browse the repository at this point in the history
  • Loading branch information
lrmor committed Nov 16, 2020
1 parent 4e6f3d9 commit b7293d8
Show file tree
Hide file tree
Showing 21 changed files with 12,137 additions and 6 deletions.
Binary file added demos/cython/__pycache__/mandel.cpython-36.pyc
Binary file not shown.
Binary file not shown.
8,382 changes: 8,382 additions & 0 deletions demos/cython/mandel_cyt.c

Large diffs are not rendered by default.

Binary file not shown.
832 changes: 832 additions & 0 deletions demos/cython/mandel_cyt.html

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions demos/cython/mandel_main_cp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np
import matplotlib.pyplot as plt
import sys
from mandel import compute_mandel as compute_mandel_py
try:
from mandel_cyt import compute_mandel as compute_mandel_cyt
except ImportError:
pass

def plot_mandel(mandel):
plt.imshow(mandel)
plt.axis('off')
plt.show()

def main(version='py'):
kwargs = dict(cr=0.285, ci=0.01,
N=200,
bound=1.5)

# choose pure Python or Cython version
if version == 'py':
print("Using pure Python")
mandel_func = compute_mandel_py
elif version == 'cyt':
print("Using Cython")
try:
mandel_func = compute_mandel_cyt
except NameError as ex:
raise RuntimeError("Cython extension missing") from ex
else:
raise RuntimeError("Unknown version")

mandel_set, runtime = mandel_func(**kwargs)
return mandel_set, runtime

if __name__ == '__main__':
if len(sys.argv) == 2:
mandel_set, runtime = main('cyt')
else:
mandel_set, runtime = main()
print('Mandelbrot set generated in {0:9.4f} seconds'.format(runtime))
plot_mandel(mandel_set)


3 changes: 2 additions & 1 deletion demos/cython/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

setup(
ext_modules=cythonize("mandel_cyt.pyx"),
ext_modules=cythonize("mandel_cyt.pyx",compiler_directives = {'language_level': 3}),include_dirs = [numpy.get_include()],
)

10 changes: 5 additions & 5 deletions demos/memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ def maxmem():

a = np.random.random((1024, 1024, 10))
b = np.random.random((1024, 1024, 10))
c = a - b
#c = a - b
#c = 2.0 * a - 4.5 * b
#c = 2.0 * a - 4.5 * b + np.sin(a) - np.cos(b)
#c = 2.0 * a - 4.5 * b + (np.sin(a) - np.cos(b))
#c = (np.sin(a) - np.cos(b)) + 2.0 * a - 4.5 * b

#c = 2.0 * a
#c -= 4.5 * b
#c += np.sin(a)
#c -= np.cos(b)
c = 2.0 * a
c -= 4.5 * b
c += np.sin(a)
c -= np.cos(b)

mem = maxmem() - overhead

Expand Down
Binary file added myfile/.linagtst.py.swp
Binary file not shown.
Binary file added myfile/build/temp.linux-x86_64-3.6/cyt_module.o
Binary file not shown.
Loading

0 comments on commit b7293d8

Please sign in to comment.