forked from csc-training/hpc-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
12,137 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.