forked from IntelPython/BlackScholes_bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bs_erf_cython.py
44 lines (35 loc) · 1.15 KB
/
bs_erf_cython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (C) 2019 Intel Corporation
#
# SPDX-License-Identifier: MIT
import base_bs_erf
def build_ext():
try:
from distutils.core import setup
from Cython.Build import cythonize
import os, subprocess, numpy
subprocess.call(['icc', '--version'])
except:
print("error building the extension module: Cython and Intel compiler are required")
return False
else:
os.environ['CC'] = "icc"
os.environ['LDSHARED'] = "icc -shared"
# use high accuracy precision
os.environ['CFLAGS'] = "-fimf-precision=high -prec-sqrt -qopt-report=5 -fno-alias -xhost -qopenmp -pthread -fno-strict-aliasing"
setup(
name = "bs_erf_cython_impl",
ext_modules = cythonize("bs_erf_cython_impl.pyx"),
include_dirs = [numpy.get_include()],
script_args = ["build_ext", "--inplace"]
)
import bs_erf_cython_impl as bsc
return bsc
try:
import bs_erf_cython_impl as bsc
except:
bsc = build_ext()
if not bsc:
print("Skipping Cython version")
else:
base_bs_erf.run("Cython-parallel", bsc.black_scholes_par, pass_args=True)
base_bs_erf.run("Cython-serial", bsc.black_scholes_ser, pass_args=True)