Robert Johansson
Source code listings for Numerical Python - Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib (ISBN 979-8-8688-0412-0).
import numba
import pyximport
import cython
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
np.random.seed(0)
data = np.random.randn(50000)
def py_sum(data):
s = 0
for d in data:
s += d
return s
def py_cumsum(data):
out = np.zeros(len(data), dtype=np.float64)
s = 0
for n in range(len(data)):
s += data[n]
out[n] = s
return out
%timeit py_sum(data)
2.99 ms ± 39.3 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
assert abs(py_sum(data) - np.sum(data)) < 1e-10
%timeit np.sum(data)
12.7 μs ± 164 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%timeit py_cumsum(data)
6.44 ms ± 14.1 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
assert np.allclose(np.cumsum(data), py_cumsum(data))
%timeit np.cumsum(data)
106 μs ± 245 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
@numba.jit
def jit_sum(data):
s = 0
for d in data:
s += d
return s
assert abs(jit_sum(data) - np.sum(data)) < 1e-10
%timeit jit_sum(data)
46 μs ± 22.2 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
jit_cumsum = numba.jit()(py_cumsum)
assert np.allclose(np.cumsum(data), jit_cumsum(data))
%timeit jit_cumsum(data)
52.9 μs ± 25.4 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
def py_julia_fractal(z_re, z_im, j):
for m in range(len(z_re)):
for n in range(len(z_im)):
z = z_re[m] + 1j * z_im[n]
for t in range(256):
z = z ** 2 - 0.05 + 0.68j
if np.abs(z) > 2.0:
#if (z.real * z.real + z.imag * z.imag) > 4.0: # a bit faster
j[m, n] = t
break
jit_julia_fractal = numba.jit(nopython=True)(py_julia_fractal)
N = 1024
j = np.zeros((N, N), np.int64)
z_real = np.linspace(-1.5, 1.5, N)
z_imag = np.linspace(-1.5, 1.5, N)
jit_julia_fractal(z_real, z_imag, j)
fig, ax = plt.subplots(figsize=(14, 14))
ax.imshow(j, cmap=plt.cm.RdBu_r,
extent=[-1.5, 1.5, -1.5, 1.5])
ax.set_xlabel("$\mathrm{Re}(z)$", fontsize=18)
ax.set_ylabel("$\mathrm{Im}(z)$", fontsize=18)
fig.tight_layout()
fig.savefig("ch19-numba-julia-fractal.pdf")
%timeit py_julia_fractal(z_real, z_imag, j)
15.6 s ± 82.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit jit_julia_fractal(z_real, z_imag, j)
175 ms ± 567 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)
def py_Heaviside(x):
if x == 0.0:
return 0.5
if x < 0.0:
return 0.0
else:
return 1.0
x = np.linspace(-2, 2, 50001)
%timeit [py_Heaviside(xx) for xx in x]
6.44 ms ± 63.1 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
np_vec_Heaviside = np.vectorize(py_Heaviside)
np_vec_Heaviside(x)
array([0., 0., 0., ..., 1., 1., 1.])
%timeit np_vec_Heaviside(x)
4.93 ms ± 187 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
def np_Heaviside(x):
return (x > 0.0) + (x == 0.0)/2.0
%timeit np_Heaviside(x)
81.3 μs ± 456 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
@numba.vectorize([numba.float32(numba.float32),
numba.float64(numba.float64)])
def jit_Heaviside(x):
if x == 0.0:
return 0.5
if x < 0:
return 0.0
else:
return 1.0
%timeit jit_Heaviside(x)
15.7 μs ± 368 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
jit_Heaviside([-1, -0.5, 0.0, 0.5, 1.0])
array([0. , 0. , 0.5, 1. , 1. ])
!rm cy_sum.*
rm: cannot remove 'cy_sum.*': No such file or directory
%%writefile cy_sum.pyx
def cy_sum(data):
s = 0.0
for d in data:
s += d
return s
Writing cy_sum.pyx
!cython cy_sum.pyx
/opt/conda/lib/python3.11/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/rob/notebooks/cy_sum.pyx tree = Parsing.p_module(s, pxd, full_module_name)
# 5 lines of python code -> 1470 lines of C code ...
!wc cy_sum.c
6126 19777 233611 cy_sum.c
%%writefile setup.py
from distutils.core import setup
from Cython.Build import cythonize
import numpy as np
setup(ext_modules=cythonize('cy_sum.pyx'),
include_dirs=[np.get_include()],
requires=['Cython', 'numpy'] )
Writing setup.py
!/opt/conda/envs/npbook_py310/bin/python setup.py build_ext --inplace > /dev/null
/opt/conda/envs/npbook_py310/lib/python3.10/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/rob/notebooks/cy_sum.pyx tree = Parsing.p_module(s, pxd, full_module_name)
from cy_sum import cy_sum
cy_sum(data)
-189.70046227549025
%timeit cy_sum(data)
2.44 ms ± 115 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit py_sum(data)
2.87 ms ± 71.3 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%%writefile cy_cumsum.pyx
cimport numpy
import numpy
def cy_cumsum(data):
out = numpy.zeros_like(data)
s = 0
for n in range(len(data)):
s += data[n]
out[n] = s
return out
Writing cy_cumsum.pyx
pyximport.install(setup_args={'include_dirs': np.get_include()});
pyximport.install(setup_args=dict(include_dirs=np.get_include()));
from cy_cumsum import cy_cumsum
%timeit cy_cumsum(data)
5.94 ms ± 165 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit py_cumsum(data)
6.47 ms ± 41.1 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%load_ext cython
%%cython -a
def cy_sum(data):
s = 0.0
for d in data:
s += d
return s
Generated by Cython 3.0.11
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
+1: def cy_sum(data):
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_1cy_sum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_1cy_sum = {"cy_sum", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_1cy_sum, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_1cy_sum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyObject *__pyx_v_data = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_sum (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_sum") < 0)) __PYX_ERR(0, 1, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
}
__pyx_v_data = values[0];
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_sum", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c.cy_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_cy_sum(__pyx_self, __pyx_v_data);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_cy_sum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
PyObject *__pyx_v_s = NULL;
PyObject *__pyx_v_d = NULL;
PyObject *__pyx_r = NULL;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c.cy_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_s);
__Pyx_XDECREF(__pyx_v_d);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple_ = PyTuple_Pack(3, __pyx_n_s_data, __pyx_n_s_s, __pyx_n_s_d); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple_);
__Pyx_GIVEREF(__pyx_tuple_);
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_54_cython_magic_3fb89a41dd02054b2ba14111758c0b9f8953837c_1cy_sum, 0, __pyx_n_s_cy_sum, NULL, __pyx_n_s_cython_magic_3fb89a41dd02054b2b, __pyx_d, ((PyObject *)__pyx_codeobj__2)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_cy_sum, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+2: s = 0.0
__Pyx_INCREF(__pyx_float_0_0);
__pyx_v_s = __pyx_float_0_0;
+3: for d in data:
if (likely(PyList_CheckExact(__pyx_v_data)) || PyTuple_CheckExact(__pyx_v_data)) { __pyx_t_1 = __pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { { Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 3, __pyx_L1_error) #endif if (__pyx_t_2 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 3, __pyx_L1_error) #else __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { { Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1); #if !CYTHON_ASSUME_SAFE_MACROS if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 3, __pyx_L1_error) #endif if (__pyx_t_2 >= __pyx_temp) break; } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 3, __pyx_L1_error) #else __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 3, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_4); } __Pyx_XDECREF_SET(__pyx_v_d, __pyx_t_4); __pyx_t_4 = 0; /* … */ } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+4: s += d
__pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_s, __pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_4); __pyx_t_4 = 0;
+5: return s
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_s); __pyx_r = __pyx_v_s; goto __pyx_L0;
%timeit cy_sum(data)
2.57 ms ± 56.3 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit py_sum(data)
2.96 ms ± 107 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
assert np.allclose(np.sum(data), cy_sum(data))
%%cython -a
cimport numpy
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
def cy_sum(numpy.ndarray[numpy.float64_t, ndim=1] data):
cdef numpy.float64_t s = 0.0
#cdef int n, N = data.shape[0]
cdef int n, N = len(data)
for n in range(N):
s += data[n]
return s
Content of stderr:
In file included from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5,
from /home/rob/.cache/ipython/cython/_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1.c:1250:
/opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with " \
| ^~~~~~~
Generated by Cython 3.0.11
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
+01: cimport numpy
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
02: cimport cython
03:
+04: @cython.boundscheck(False)
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_1cy_sum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_1cy_sum = {"cy_sum", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_1cy_sum, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_1cy_sum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyArrayObject *__pyx_v_data = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_sum (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 4, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_sum") < 0)) __PYX_ERR(0, 4, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
}
__pyx_v_data = ((PyArrayObject *)values[0]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_sum", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 4, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1.cy_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) __PYX_ERR(0, 6, __pyx_L1_error)
__pyx_r = __pyx_pf_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_cy_sum(__pyx_self, __pyx_v_data);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_cy_sum(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data) {
__pyx_t_5numpy_float64_t __pyx_v_s;
int __pyx_v_n;
int __pyx_v_N;
__Pyx_LocalBuf_ND __pyx_pybuffernd_data;
__Pyx_Buffer __pyx_pybuffer_data;
PyObject *__pyx_r = NULL;
__pyx_pybuffer_data.pybuffer.buf = NULL;
__pyx_pybuffer_data.refcount = 0;
__pyx_pybuffernd_data.data = NULL;
__pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 4, __pyx_L1_error)
}
__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1.cy_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__3 = PyTuple_Pack(4, __pyx_n_s_data, __pyx_n_s_s, __pyx_n_s_n, __pyx_n_s_N); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 4, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__3);
__Pyx_GIVEREF(__pyx_tuple__3);
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_54_cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1_1cy_sum, 0, __pyx_n_s_cy_sum, NULL, __pyx_n_s_cython_magic_16d506d9dddc3a141b, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_cy_sum, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
05: @cython.wraparound(False)
06: def cy_sum(numpy.ndarray[numpy.float64_t, ndim=1] data):
+07: cdef numpy.float64_t s = 0.0
__pyx_v_s = 0.0;
08: #cdef int n, N = data.shape[0]
+09: cdef int n, N = len(data)
__pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_data)); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 9, __pyx_L1_error) __pyx_v_N = __pyx_t_1;
+10: for n in range(N):
__pyx_t_2 = __pyx_v_N;
__pyx_t_3 = __pyx_t_2;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
+11: s += data[n]
__pyx_t_5 = __pyx_v_n;
__pyx_v_s = (__pyx_v_s + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_data.diminfo[0].strides)));
}
+12: return s
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = PyFloat_FromDouble(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
%timeit cy_sum(data)
46 μs ± 9.16 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit jit_sum(data)
46 μs ± 10.4 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit np.sum(data)
12.7 μs ± 14.4 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%%cython -a
cimport numpy
import numpy
cimport cython
ctypedef numpy.float64_t FTYPE_t
@cython.boundscheck(False)
@cython.wraparound(False)
def cy_cumsum(numpy.ndarray[FTYPE_t, ndim=1] data):
cdef int n, N = data.size
cdef numpy.ndarray[FTYPE_t, ndim=1] out = numpy.zeros(N, dtype=data.dtype)
cdef numpy.float64_t s = 0.0
for n in range(N):
s += data[n]
out[n] = s
return out
Content of stderr:
In file included from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5,
from /home/rob/.cache/ipython/cython/_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747.c:1251:
/opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with " \
| ^~~~~~~
Generated by Cython 3.0.11
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
+01: cimport numpy
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+02: import numpy
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
03: cimport cython
04:
05: ctypedef numpy.float64_t FTYPE_t
06:
+07: @cython.boundscheck(False)
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_1cy_cumsum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_1cy_cumsum = {"cy_cumsum", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_1cy_cumsum, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_1cy_cumsum(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyArrayObject *__pyx_v_data = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_cumsum (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 7, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_cumsum") < 0)) __PYX_ERR(0, 7, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
}
__pyx_v_data = ((PyArrayObject *)values[0]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_cumsum", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 7, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747.cy_cumsum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) __PYX_ERR(0, 9, __pyx_L1_error)
__pyx_r = __pyx_pf_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_cy_cumsum(__pyx_self, __pyx_v_data);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_cy_cumsum(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data) {
int __pyx_v_n;
int __pyx_v_N;
PyArrayObject *__pyx_v_out = 0;
__pyx_t_5numpy_float64_t __pyx_v_s;
__Pyx_LocalBuf_ND __pyx_pybuffernd_data;
__Pyx_Buffer __pyx_pybuffer_data;
__Pyx_LocalBuf_ND __pyx_pybuffernd_out;
__Pyx_Buffer __pyx_pybuffer_out;
PyObject *__pyx_r = NULL;
__pyx_pybuffer_out.pybuffer.buf = NULL;
__pyx_pybuffer_out.refcount = 0;
__pyx_pybuffernd_out.data = NULL;
__pyx_pybuffernd_out.rcbuffer = &__pyx_pybuffer_out;
__pyx_pybuffer_data.pybuffer.buf = NULL;
__pyx_pybuffer_data.refcount = 0;
__pyx_pybuffernd_data.data = NULL;
__pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_FTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 7, __pyx_L1_error)
}
__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_out.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747.cy_cumsum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_out.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__4 = PyTuple_Pack(5, __pyx_n_s_data, __pyx_n_s_n, __pyx_n_s_N, __pyx_n_s_out, __pyx_n_s_s); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__4);
__Pyx_GIVEREF(__pyx_tuple__4);
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_1cy_cumsum, 0, __pyx_n_s_cy_cumsum, NULL, __pyx_n_s_cython_magic_a7031120ac776f6c06, __pyx_d, ((PyObject *)__pyx_codeobj__5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_cy_cumsum, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
08: @cython.wraparound(False)
09: def cy_cumsum(numpy.ndarray[FTYPE_t, ndim=1] data):
+10: cdef int n, N = data.size
__pyx_t_1 = __pyx_f_5numpy_7ndarray_4size_size(((PyArrayObject *)__pyx_v_data)); if (unlikely(__pyx_t_1 == ((npy_intp)-1) && PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L1_error) __pyx_v_N = __pyx_t_1;
+11: cdef numpy.ndarray[FTYPE_t, ndim=1] out = numpy.zeros(N, dtype=data.dtype)
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_data), __pyx_n_s_dtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 11, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_FTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_out.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 11, __pyx_L1_error) } else {__pyx_pybuffernd_out.diminfo[0].strides = __pyx_pybuffernd_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_out.diminfo[0].shape = __pyx_pybuffernd_out.rcbuffer->pybuffer.shape[0]; } } __pyx_t_6 = 0; __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+12: cdef numpy.float64_t s = 0.0
__pyx_v_s = 0.0;
+13: for n in range(N):
__pyx_t_7 = __pyx_v_N;
__pyx_t_8 = __pyx_t_7;
for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
__pyx_v_n = __pyx_t_9;
+14: s += data[n]
__pyx_t_10 = __pyx_v_n;
__pyx_v_s = (__pyx_v_s + (*__Pyx_BufPtrStrided1d(__pyx_t_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_FTYPE_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_data.diminfo[0].strides)));
+15: out[n] = s
__pyx_t_10 = __pyx_v_n;
*__Pyx_BufPtrStrided1d(__pyx_t_54_cython_magic_a7031120ac776f6c06c9d1ee05b4d71edd090747_FTYPE_t *, __pyx_pybuffernd_out.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_out.diminfo[0].strides) = __pyx_v_s;
}
+16: return out
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_out); __pyx_r = ((PyObject *)__pyx_v_out); goto __pyx_L0;
%timeit py_cumsum(data)
6.39 ms ± 28.2 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit cy_cumsum(data)
53.4 μs ± 113 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit jit_cumsum(data)
52.8 μs ± 11.8 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit np.cumsum(data)
107 μs ± 404 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
assert np.allclose(cy_cumsum(data), np.cumsum(data))
py_sum([1.0, 2.0, 3.0, 4.0, 5.0])
15.0
py_sum([1, 2, 3, 4, 5])
15
cy_sum(np.array([1.0, 2.0, 3.0, 4.0, 5.0]))
15.0
cy_sum(np.array([1, 2, 3, 4, 5]))
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[81], line 1 ----> 1 cy_sum(np.array([1, 2, 3, 4, 5])) File _cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1.pyx:4, in _cython_magic_16d506d9dddc3a141b0f412e0228a611fa6c09f1.cy_sum() ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'long'
%%cython -a
cimport numpy
cimport cython
ctypedef fused I_OR_F_t:
numpy.int64_t
numpy.float64_t
@cython.boundscheck(False)
@cython.wraparound(False)
def cy_fused_sum(numpy.ndarray[I_OR_F_t, ndim=1] data):
cdef I_OR_F_t s = 0
cdef int n, N = data.size
for n in range(N):
s += data[n]
return s
Content of stderr:
In file included from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5,
from /home/rob/.cache/ipython/cython/_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.c:1252:
/opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with " \
| ^~~~~~~
Generated by Cython 3.0.11
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
+01: cimport numpy
__pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_4) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
02: cimport cython
03:
04: ctypedef fused I_OR_F_t:
05: numpy.int64_t
06: numpy.float64_t
07:
+08: @cython.boundscheck(False)
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_1cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_1cy_fused_sum = {"cy_fused_sum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_1cy_fused_sum, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_1cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_signatures = 0;
PyObject *__pyx_v_args = 0;
PyObject *__pyx_v_kwargs = 0;
CYTHON_UNUSED PyObject *__pyx_v_defaults = 0;
PyObject *__pyx_v__fused_sigindex = 0;
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pyx_fused_cpdef (wrapper)", 0);
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_signatures,&__pyx_n_s_args,&__pyx_n_s_kwargs,&__pyx_n_s_defaults,&__pyx_n_s_fused_sigindex,0};
PyObject* values[5] = {0,0,0,0,0};
__pyx_defaults *__pyx_dynamic_args = __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self);
values[4] = __Pyx_Arg_NewRef_VARARGS(__pyx_dynamic_args->__pyx_arg__fused_sigindex);
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_signatures)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_args)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[1]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else {
__Pyx_RaiseArgtupleInvalid("__pyx_fused_cpdef", 0, 4, 5, 1); __PYX_ERR(0, 8, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_kwargs)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[2]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else {
__Pyx_RaiseArgtupleInvalid("__pyx_fused_cpdef", 0, 4, 5, 2); __PYX_ERR(0, 8, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 3:
if (likely((values[3] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_defaults)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[3]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else {
__Pyx_RaiseArgtupleInvalid("__pyx_fused_cpdef", 0, 4, 5, 3); __PYX_ERR(0, 8, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 4:
if (kw_args > 0) {
PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_fused_sigindex);
if (value) { values[4] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__pyx_fused_cpdef") < 0)) __PYX_ERR(0, 8, __pyx_L3_error)
}
} else {
switch (__pyx_nargs) {
case 5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
CYTHON_FALLTHROUGH;
case 4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_signatures = values[0];
__pyx_v_args = values[1];
__pyx_v_kwargs = values[2];
__pyx_v_defaults = values[3];
__pyx_v__fused_sigindex = values[4];
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__pyx_fused_cpdef", 0, 4, 5, __pyx_nargs); __PYX_ERR(0, 8, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.__pyx_fused_cpdef", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_cy_fused_sum(__pyx_self, __pyx_v_signatures, __pyx_v_args, __pyx_v_kwargs, __pyx_v_defaults, __pyx_v__fused_sigindex);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_cy_fused_sum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_signatures, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs, CYTHON_UNUSED PyObject *__pyx_v_defaults, PyObject *__pyx_v__fused_sigindex) {
PyObject *__pyx_v_search_list = 0;
PyObject *__pyx_v_sigindex_node = 0;
PyObject *__pyx_v_dest_sig = NULL;
PyTypeObject *__pyx_v_ndarray = 0;
PyObject *__pyx_v_arg_as_memoryview = 0;
__Pyx_memviewslice __pyx_v_memslice;
Py_ssize_t __pyx_v_itemsize;
int __pyx_v_dtype_signed;
Py_UCS4 __pyx_v_kind;
int __pyx_v___pyx_fused_dtype_int64__t_is_signed;
PyObject *__pyx_v_arg = NULL;
PyObject *__pyx_v_dtype = NULL;
PyObject *__pyx_v_arg_base = NULL;
PyObject *__pyx_v_sig = NULL;
PyObject *__pyx_v_sig_series = NULL;
PyObject *__pyx_v_last_type = NULL;
PyObject *__pyx_v_sig_type = NULL;
PyObject *__pyx_v_sigindex_matches = NULL;
PyObject *__pyx_v_sigindex_candidates = NULL;
PyObject *__pyx_v_dst_type = NULL;
PyObject *__pyx_v_found_matches = NULL;
PyObject *__pyx_v_found_candidates = NULL;
PyObject *__pyx_v_sn = NULL;
PyObject *__pyx_v_type_match = NULL;
PyObject *__pyx_v_candidates = NULL;
PyObject *__pyx_r = NULL;
__Pyx_INCREF(__pyx_v_kwargs);
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(Py_None);
__Pyx_GIVEREF(Py_None);
if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, Py_None)) __PYX_ERR(0, 8, __pyx_L1_error);
__pyx_v_dest_sig = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_3 = (__pyx_v_kwargs != Py_None);
if (__pyx_t_3) {
} else {
__pyx_t_2 = __pyx_t_3;
goto __pyx_L4_bool_binop_done;
}
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_4 = (!__pyx_t_3);
__pyx_t_2 = __pyx_t_4;
__pyx_L4_bool_binop_done:;
if (__pyx_t_2) {
__Pyx_INCREF(Py_None);
__Pyx_DECREF_SET(__pyx_v_kwargs, Py_None);
}
__pyx_t_1 = ((PyObject *)__Pyx_ImportNumPyArrayTypeIfAvailable()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_ndarray = ((PyTypeObject*)__pyx_t_1);
__pyx_t_1 = 0;
__pyx_v_itemsize = -1L;
__pyx_v___pyx_fused_dtype_int64__t_is_signed = (!(((__pyx_t_5numpy_int64_t)-1L) > 0));
if (unlikely(__pyx_v_args == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_5 = __Pyx_PyTuple_GET_SIZE(((PyObject*)__pyx_v_args)); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_2 = (0 < __pyx_t_5);
if (__pyx_t_2) {
if (unlikely(__pyx_v_args == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_1 = PyTuple_GET_ITEM(((PyObject*)__pyx_v_args), 0);
__Pyx_INCREF(__pyx_t_1);
__pyx_v_arg = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L6;
}
__pyx_t_4 = (__pyx_v_kwargs != Py_None);
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L7_bool_binop_done;
}
if (unlikely(__pyx_v_kwargs == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_data, ((PyObject*)__pyx_v_kwargs), Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_2 = __pyx_t_4;
__pyx_L7_bool_binop_done:;
if (likely(__pyx_t_2)) {
if (unlikely(__pyx_v_kwargs == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyDict_GetItem(((PyObject*)__pyx_v_kwargs), __pyx_n_s_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_arg = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L6;
}
/*else*/ {
if (unlikely(__pyx_v_args == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_5 = __Pyx_PyTuple_GET_SIZE(((PyObject*)__pyx_v_args)); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_1 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_int_1)) __PYX_ERR(0, 8, __pyx_L1_error);
__Pyx_INCREF(__pyx_kp_s__11);
__Pyx_GIVEREF(__pyx_kp_s__11);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_kp_s__11)) __PYX_ERR(0, 8, __pyx_L1_error);
__Pyx_GIVEREF(__pyx_t_1);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Expected_at_least_d_argument_s_g, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_Raise(__pyx_t_6, 0, 0, 0);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_L6:;
while (1) {
__pyx_t_2 = (__pyx_v_ndarray != ((PyTypeObject*)Py_None));
if (__pyx_t_2) {
__pyx_t_2 = __Pyx_TypeCheck(__pyx_v_arg, __pyx_v_ndarray);
if (__pyx_t_2) {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arg, __pyx_n_s_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_v_dtype = __pyx_t_6;
__pyx_t_6 = 0;
goto __pyx_L12;
}
__pyx_t_2 = __pyx_memoryview_check(__pyx_v_arg);
if (__pyx_t_2) {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arg, __pyx_n_s_base); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_v_arg_base = __pyx_t_6;
__pyx_t_6 = 0;
__pyx_t_2 = __Pyx_TypeCheck(__pyx_v_arg_base, __pyx_v_ndarray);
if (__pyx_t_2) {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arg_base, __pyx_n_s_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_v_dtype = __pyx_t_6;
__pyx_t_6 = 0;
goto __pyx_L13;
}
/*else*/ {
__Pyx_INCREF(Py_None);
__pyx_v_dtype = Py_None;
}
__pyx_L13:;
goto __pyx_L12;
}
/*else*/ {
__Pyx_INCREF(Py_None);
__pyx_v_dtype = Py_None;
}
__pyx_L12:;
__pyx_v_itemsize = -1L;
__pyx_t_2 = (__pyx_v_dtype != Py_None);
if (__pyx_t_2) {
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_dtype, __pyx_n_s_itemsize); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_v_itemsize = __pyx_t_5;
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_dtype, __pyx_n_s_kind); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyObject_Ord(__pyx_t_6); if (unlikely(__pyx_t_7 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_v_kind = __pyx_t_7;
__pyx_v_dtype_signed = (__pyx_v_kind == 0x69);
switch (__pyx_v_kind) {
case 0x69:
case 0x75:
__pyx_t_4 = ((sizeof(__pyx_t_5numpy_int64_t)) == __pyx_v_itemsize);
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L16_bool_binop_done;
}
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arg, __pyx_n_s_ndim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_4 = (((Py_ssize_t)__pyx_t_5) == 1);
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L16_bool_binop_done;
}
__pyx_t_4 = (!(__pyx_v___pyx_fused_dtype_int64__t_is_signed ^ __pyx_v_dtype_signed));
__pyx_t_2 = __pyx_t_4;
__pyx_L16_bool_binop_done:;
if (__pyx_t_2) {
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, __pyx_n_s_int64_t, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
goto __pyx_L10_break;
}
break;
case 0x66:
__pyx_t_4 = ((sizeof(__pyx_t_5numpy_float64_t)) == __pyx_v_itemsize);
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L20_bool_binop_done;
}
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_arg, __pyx_n_s_ndim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_4 = (((Py_ssize_t)__pyx_t_5) == 1);
__pyx_t_2 = __pyx_t_4;
__pyx_L20_bool_binop_done:;
if (__pyx_t_2) {
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, __pyx_n_s_float64_t, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
goto __pyx_L10_break;
}
break;
case 99:
break;
case 79:
break;
default: break;
}
}
}
__pyx_t_2 = (__pyx_v_arg == Py_None);
if (__pyx_t_2) {
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, __pyx_n_s_int64_t, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
goto __pyx_L10_break;
}
{
/*try:*/ {
__pyx_t_6 = PyMemoryView_FromObject(__pyx_v_arg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L23_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_v_arg_as_memoryview = ((PyObject*)__pyx_t_6);
__pyx_t_6 = 0;
}
/*else:*/ {
__pyx_t_4 = (__pyx_v_itemsize == -1L);
if (!__pyx_t_4) {
goto __pyx_L34_next_or;
} else {
}
__pyx_t_5 = __Pyx_PyMemoryView_Get_itemsize(__pyx_v_arg_as_memoryview); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L25_except_error)
__pyx_t_4 = (__pyx_t_5 == (sizeof(__pyx_t_5numpy_int64_t)));
if (!__pyx_t_4) {
} else {
goto __pyx_L33_next_and;
}
__pyx_L34_next_or:;
__pyx_t_4 = (__pyx_v_itemsize == (sizeof(__pyx_t_5numpy_int64_t)));
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L32_bool_binop_done;
}
__pyx_L33_next_and:;
__pyx_t_11 = __Pyx_PyMemoryView_Get_ndim(__pyx_v_arg_as_memoryview); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L25_except_error)
__pyx_t_4 = (__pyx_t_11 == 1);
__pyx_t_2 = __pyx_t_4;
__pyx_L32_bool_binop_done:;
if (__pyx_t_2) {
__pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_int64_t(__pyx_v_arg_as_memoryview, 0);
__pyx_v_memslice = __pyx_t_12;
__pyx_t_2 = (__pyx_v_memslice.memview != 0);
if (__pyx_t_2) {
__PYX_XCLEAR_MEMVIEW((&__pyx_v_memslice), 1);
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, __pyx_n_s_int64_t, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L25_except_error)
goto __pyx_L28_try_break;
}
/*else*/ {
PyErr_Clear();
}
}
__pyx_t_4 = (__pyx_v_itemsize == -1L);
if (!__pyx_t_4) {
goto __pyx_L40_next_or;
} else {
}
__pyx_t_5 = __Pyx_PyMemoryView_Get_itemsize(__pyx_v_arg_as_memoryview); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L25_except_error)
__pyx_t_4 = (__pyx_t_5 == (sizeof(__pyx_t_5numpy_float64_t)));
if (!__pyx_t_4) {
} else {
goto __pyx_L39_next_and;
}
__pyx_L40_next_or:;
__pyx_t_4 = (__pyx_v_itemsize == (sizeof(__pyx_t_5numpy_float64_t)));
if (__pyx_t_4) {
} else {
__pyx_t_2 = __pyx_t_4;
goto __pyx_L38_bool_binop_done;
}
__pyx_L39_next_and:;
__pyx_t_11 = __Pyx_PyMemoryView_Get_ndim(__pyx_v_arg_as_memoryview); if (unlikely(__pyx_t_11 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L25_except_error)
__pyx_t_4 = (__pyx_t_11 == 1);
__pyx_t_2 = __pyx_t_4;
__pyx_L38_bool_binop_done:;
if (__pyx_t_2) {
__pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_5numpy_float64_t(__pyx_v_arg_as_memoryview, 0);
__pyx_v_memslice = __pyx_t_12;
__pyx_t_2 = (__pyx_v_memslice.memview != 0);
if (__pyx_t_2) {
__PYX_XCLEAR_MEMVIEW((&__pyx_v_memslice), 1);
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, __pyx_n_s_float64_t, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L25_except_error)
goto __pyx_L28_try_break;
}
/*else*/ {
PyErr_Clear();
}
}
}
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
goto __pyx_L30_try_end;
__pyx_L23_error:;
__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_11 = __Pyx_PyErr_ExceptionMatches2(__pyx_builtin_ValueError, __pyx_builtin_TypeError);
if (__pyx_t_11) {
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.__pyx_fused_cpdef", __pyx_clineno, __pyx_lineno, __pyx_filename);
if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_1, &__pyx_t_13) < 0) __PYX_ERR(0, 8, __pyx_L25_except_error)
__Pyx_XGOTREF(__pyx_t_6);
__Pyx_XGOTREF(__pyx_t_1);
__Pyx_XGOTREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
goto __pyx_L24_exception_handled;
}
goto __pyx_L25_except_error;
__pyx_L25_except_error:;
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_XGIVEREF(__pyx_t_9);
__Pyx_XGIVEREF(__pyx_t_10);
__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
goto __pyx_L1_error;
__pyx_L28_try_break:;
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_XGIVEREF(__pyx_t_9);
__Pyx_XGIVEREF(__pyx_t_10);
__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
goto __pyx_L10_break;
__pyx_L24_exception_handled:;
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_XGIVEREF(__pyx_t_9);
__Pyx_XGIVEREF(__pyx_t_10);
__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
__pyx_L30_try_end:;
}
if (unlikely((__Pyx_SetItemInt(__pyx_v_dest_sig, 0, Py_None, long, 1, __Pyx_PyInt_From_long, 1, 0, 0) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
goto __pyx_L10_break;
}
__pyx_L10_break:;
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v__fused_sigindex); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_4 = (!__pyx_t_2);
if (__pyx_t_4) {
__pyx_t_5 = 0;
if (unlikely(__pyx_v_signatures == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_dict_iterator(((PyObject*)__pyx_v_signatures), 1, ((PyObject *)NULL), (&__pyx_t_14), (&__pyx_t_11)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_13);
__pyx_t_13 = __pyx_t_1;
__pyx_t_1 = 0;
while (1) {
__pyx_t_15 = __Pyx_dict_iter_next(__pyx_t_13, __pyx_t_14, &__pyx_t_5, &__pyx_t_1, NULL, NULL, __pyx_t_11);
if (unlikely(__pyx_t_15 == 0)) break;
if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_sig, __pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = __pyx_v__fused_sigindex;
__Pyx_INCREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_sigindex_node, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;
__pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_sig, __pyx_n_s_strip); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
__pyx_t_17 = NULL;
__pyx_t_18 = 0;
#if CYTHON_UNPACK_METHODS
if (likely(PyMethod_Check(__pyx_t_16))) {
__pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
if (likely(__pyx_t_17)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
__Pyx_INCREF(__pyx_t_17);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_16, function);
__pyx_t_18 = 1;
}
}
#endif
{
PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_kp_s__12};
__pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_18, 1+__pyx_t_18);
__Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
}
__pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_split); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = NULL;
__pyx_t_18 = 0;
#if CYTHON_UNPACK_METHODS
if (likely(PyMethod_Check(__pyx_t_16))) {
__pyx_t_6 = PyMethod_GET_SELF(__pyx_t_16);
if (likely(__pyx_t_6)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
__Pyx_INCREF(__pyx_t_6);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_16, function);
__pyx_t_18 = 1;
}
}
#endif
{
PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_kp_s__13};
__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_18, 1+__pyx_t_18);
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
}
__pyx_t_16 = __Pyx_PySequence_ListKeepNew(__pyx_t_1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_19 = PyList_GET_SIZE(__pyx_t_16);
if (unlikely(__pyx_t_19 < 1)) {
__Pyx_RaiseNeedMoreValuesError(0+__pyx_t_19); __PYX_ERR(0, 8, __pyx_L1_error)
}
#if CYTHON_COMPILING_IN_CPYTHON
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_19-1);
((PyVarObject*)__pyx_t_16)->ob_size--;
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_16, __pyx_t_19-1);
#endif
__Pyx_GOTREF(__pyx_t_6);
#if !CYTHON_COMPILING_IN_CPYTHON
__pyx_t_17 = PySequence_GetSlice(__pyx_t_16, 0, __pyx_t_19-1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_17);
__Pyx_DECREF(__pyx_t_16);
__pyx_t_16 = __pyx_t_17; __pyx_t_17 = NULL;
#else
CYTHON_UNUSED_VAR(__pyx_t_17);
#endif
__Pyx_XDECREF_SET(__pyx_v_sig_series, ((PyObject*)__pyx_t_16));
__pyx_t_16 = 0;
__Pyx_XDECREF_SET(__pyx_v_last_type, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_1 = __pyx_v_sig_series; __Pyx_INCREF(__pyx_t_1);
__pyx_t_19 = 0;
for (;;) {
{
Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
#if !CYTHON_ASSUME_SAFE_MACROS
if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#endif
if (__pyx_t_19 >= __pyx_temp) break;
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_19); __Pyx_INCREF(__pyx_t_6); __pyx_t_19++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_6 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
__Pyx_XDECREF_SET(__pyx_v_sig_type, __pyx_t_6);
__pyx_t_6 = 0;
if (unlikely(__pyx_v_sigindex_node == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_sig_type, __pyx_v_sigindex_node, Py_NE)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
if (__pyx_t_4) {
__pyx_t_6 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
if (unlikely(__pyx_v_sigindex_node == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
if (unlikely((PyDict_SetItem(__pyx_v_sigindex_node, __pyx_v_sig_type, __pyx_t_6) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_INCREF(__pyx_t_6);
__Pyx_DECREF_SET(__pyx_v_sigindex_node, __pyx_t_6);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
goto __pyx_L50;
}
/*else*/ {
if (unlikely(__pyx_v_sigindex_node == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_sigindex_node, __pyx_v_sig_type); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_16 = __pyx_t_6;
__Pyx_INCREF(__pyx_t_16);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF_SET(__pyx_v_sigindex_node, ((PyObject*)__pyx_t_16));
__pyx_t_16 = 0;
}
__pyx_L50:;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(__pyx_v_sigindex_node == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
if (unlikely((PyDict_SetItem(__pyx_v_sigindex_node, __pyx_v_last_type, __pyx_v_sig) < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
}
__pyx_t_13 = PyList_New(0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__pyx_v_sigindex_matches = ((PyObject*)__pyx_t_13);
__pyx_t_13 = 0;
__pyx_t_13 = PyList_New(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_INCREF(__pyx_v__fused_sigindex);
__Pyx_GIVEREF(__pyx_v__fused_sigindex);
if (__Pyx_PyList_SET_ITEM(__pyx_t_13, 0, __pyx_v__fused_sigindex)) __PYX_ERR(0, 8, __pyx_L1_error);
__pyx_v_sigindex_candidates = ((PyObject*)__pyx_t_13);
__pyx_t_13 = 0;
__pyx_t_13 = __pyx_v_dest_sig; __Pyx_INCREF(__pyx_t_13);
__pyx_t_14 = 0;
for (;;) {
{
Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_13);
#if !CYTHON_ASSUME_SAFE_MACROS
if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#endif
if (__pyx_t_14 >= __pyx_temp) break;
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_13, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_13, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
__Pyx_XDECREF_SET(__pyx_v_dst_type, __pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_found_matches, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_found_candidates, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;
__pyx_t_4 = (__pyx_v_dst_type == Py_None);
if (__pyx_t_4) {
__pyx_t_1 = __pyx_v_sigindex_matches; __Pyx_INCREF(__pyx_t_1);
__pyx_t_5 = 0;
for (;;) {
{
Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
#if !CYTHON_ASSUME_SAFE_MACROS
if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#endif
if (__pyx_t_5 >= __pyx_temp) break;
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_16 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_16); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_16 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
#endif
__Pyx_XDECREF_SET(__pyx_v_sn, __pyx_t_16);
__pyx_t_16 = 0;
if (unlikely(__pyx_v_sn == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_16 = __Pyx_PyDict_Values(((PyObject*)__pyx_v_sn)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
__pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_found_matches, __pyx_t_16); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __pyx_v_sigindex_candidates; __Pyx_INCREF(__pyx_t_1);
__pyx_t_5 = 0;
for (;;) {
{
Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
#if !CYTHON_ASSUME_SAFE_MACROS
if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#endif
if (__pyx_t_5 >= __pyx_temp) break;
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_16 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_16); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_16 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
#endif
__Pyx_XDECREF_SET(__pyx_v_sn, __pyx_t_16);
__pyx_t_16 = 0;
if (unlikely(__pyx_v_sn == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_16 = __Pyx_PyDict_Values(((PyObject*)__pyx_v_sn)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_16);
__pyx_t_20 = __Pyx_PyList_Extend(__pyx_v_found_candidates, __pyx_t_16); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
goto __pyx_L54;
}
/*else*/ {
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_sigindex_matches);
__Pyx_GIVEREF(__pyx_v_sigindex_matches);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sigindex_matches)) __PYX_ERR(0, 8, __pyx_L1_error);
__Pyx_INCREF(__pyx_v_sigindex_candidates);
__Pyx_GIVEREF(__pyx_v_sigindex_candidates);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_sigindex_candidates)) __PYX_ERR(0, 8, __pyx_L1_error);
__pyx_t_16 = __pyx_t_1; __Pyx_INCREF(__pyx_t_16);
__pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
if (__pyx_t_5 >= 2) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_16, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_16, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
__Pyx_XDECREF_SET(__pyx_v_search_list, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;
if (unlikely(__pyx_v_search_list == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_1 = __pyx_v_search_list; __Pyx_INCREF(__pyx_t_1);
__pyx_t_19 = 0;
for (;;) {
{
Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
#if !CYTHON_ASSUME_SAFE_MACROS
if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#endif
if (__pyx_t_19 >= __pyx_temp) break;
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_19); __Pyx_INCREF(__pyx_t_6); __pyx_t_19++; if (unlikely((0 < 0))) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_6 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_19); __pyx_t_19++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
__Pyx_XDECREF_SET(__pyx_v_sn, __pyx_t_6);
__pyx_t_6 = 0;
if (unlikely(__pyx_v_sn == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_6 = __Pyx_PyDict_GetItemDefault(((PyObject*)__pyx_v_sn), __pyx_v_dst_type, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_XDECREF_SET(__pyx_v_type_match, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_4 = (__pyx_v_type_match != Py_None);
if (__pyx_t_4) {
__pyx_t_20 = __Pyx_PyList_Append(__pyx_v_found_matches, __pyx_v_type_match); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
}
__pyx_L54:;
__Pyx_INCREF(__pyx_v_found_matches);
__Pyx_DECREF_SET(__pyx_v_sigindex_matches, __pyx_v_found_matches);
__Pyx_INCREF(__pyx_v_found_candidates);
__Pyx_DECREF_SET(__pyx_v_sigindex_candidates, __pyx_v_found_candidates);
__pyx_t_2 = (PyList_GET_SIZE(__pyx_v_found_matches) != 0);
if (!__pyx_t_2) {
} else {
__pyx_t_4 = __pyx_t_2;
goto __pyx_L69_bool_binop_done;
}
__pyx_t_2 = (PyList_GET_SIZE(__pyx_v_found_candidates) != 0);
__pyx_t_4 = __pyx_t_2;
__pyx_L69_bool_binop_done:;
__pyx_t_2 = (!__pyx_t_4);
if (__pyx_t_2) {
goto __pyx_L53_break;
}
}
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
goto __pyx_L71_for_end;
__pyx_L53_break:;
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
goto __pyx_L71_for_end;
__pyx_L71_for_end:;
__Pyx_INCREF(__pyx_v_sigindex_matches);
__pyx_v_candidates = __pyx_v_sigindex_matches;
__pyx_t_2 = (PyList_GET_SIZE(__pyx_v_candidates) != 0);
__pyx_t_4 = (!__pyx_t_2);
if (unlikely(__pyx_t_4)) {
__pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_Raise(__pyx_t_13, 0, 0, 0);
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_14 = __Pyx_PyList_GET_SIZE(__pyx_v_candidates); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_4 = (__pyx_t_14 > 1);
if (unlikely(__pyx_t_4)) {
/* … */
__pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_No_matching_signature_found); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__14);
__Pyx_GIVEREF(__pyx_tuple__14);
__pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_Raise(__pyx_t_13, 0, 0, 0);
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
__PYX_ERR(0, 8, __pyx_L1_error)
}
/*else*/ {
__Pyx_XDECREF(__pyx_r);
if (unlikely(__pyx_v_signatures == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_t_13 = __Pyx_PyDict_GetItem(((PyObject*)__pyx_v_signatures), PyList_GET_ITEM(__pyx_v_candidates, 0)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__pyx_r = __pyx_t_13;
__pyx_t_13 = 0;
goto __pyx_L0;
}
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_16);
__Pyx_XDECREF(__pyx_t_17);
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.__pyx_fused_cpdef", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_search_list);
__Pyx_XDECREF(__pyx_v_sigindex_node);
__Pyx_XDECREF(__pyx_v_dest_sig);
__Pyx_XDECREF((PyObject *)__pyx_v_ndarray);
__Pyx_XDECREF(__pyx_v_arg_as_memoryview);
__Pyx_XDECREF(__pyx_v_arg);
__Pyx_XDECREF(__pyx_v_dtype);
__Pyx_XDECREF(__pyx_v_arg_base);
__Pyx_XDECREF(__pyx_v_sig);
__Pyx_XDECREF(__pyx_v_sig_series);
__Pyx_XDECREF(__pyx_v_last_type);
__Pyx_XDECREF(__pyx_v_sig_type);
__Pyx_XDECREF(__pyx_v_sigindex_matches);
__Pyx_XDECREF(__pyx_v_sigindex_candidates);
__Pyx_XDECREF(__pyx_v_dst_type);
__Pyx_XDECREF(__pyx_v_found_matches);
__Pyx_XDECREF(__pyx_v_found_candidates);
__Pyx_XDECREF(__pyx_v_sn);
__Pyx_XDECREF(__pyx_v_type_match);
__Pyx_XDECREF(__pyx_v_candidates);
__Pyx_XDECREF(__pyx_v_kwargs);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_fuse_0__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_3cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_fuse_0__pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_3cy_fused_sum = {"__pyx_fuse_0cy_fused_sum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_fuse_0__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_3cy_fused_sum, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_fuse_0__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_3cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_data = 0;
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_fused_sum (wrapper)", 0);
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_fused_sum") < 0)) __PYX_ERR(0, 8, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
}
__pyx_v_data = ((PyArrayObject *)values[0]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_fused_sum", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 8, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.cy_fused_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) __PYX_ERR(0, 10, __pyx_L1_error)
__pyx_r = __pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_2cy_fused_sum(__pyx_self, __pyx_v_data);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_2cy_fused_sum(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data) {
__pyx_t_5numpy_int64_t __pyx_v_s;
int __pyx_v_n;
int __pyx_v_N;
__Pyx_LocalBuf_ND __pyx_pybuffernd_data;
__Pyx_Buffer __pyx_pybuffer_data;
PyObject *__pyx_r = NULL;
__pyx_pybuffer_data.pybuffer.buf = NULL;
__pyx_pybuffer_data.refcount = 0;
__pyx_pybuffernd_data.data = NULL;
__pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.cy_fused_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_fuse_1__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_5cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_fuse_1__pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_5cy_fused_sum = {"__pyx_fuse_1cy_fused_sum", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_fuse_1__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_5cy_fused_sum, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_fuse_1__pyx_pw_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_5cy_fused_sum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyArrayObject *__pyx_v_data = 0;
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_fused_sum (wrapper)", 0);
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) {
(void)__Pyx_Arg_NewRef_VARARGS(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_fused_sum") < 0)) __PYX_ERR(0, 8, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
}
__pyx_v_data = ((PyArrayObject *)values[0]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_fused_sum", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 8, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.cy_fused_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) __PYX_ERR(0, 10, __pyx_L1_error)
__pyx_r = __pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_4cy_fused_sum(__pyx_self, __pyx_v_data);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_4cy_fused_sum(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_data) {
__pyx_t_5numpy_float64_t __pyx_v_s;
int __pyx_v_n;
int __pyx_v_N;
__Pyx_LocalBuf_ND __pyx_pybuffernd_data;
__Pyx_Buffer __pyx_pybuffer_data;
PyObject *__pyx_r = NULL;
__pyx_pybuffer_data.pybuffer.buf = NULL;
__pyx_pybuffer_data.refcount = 0;
__pyx_pybuffernd_data.data = NULL;
__pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 8, __pyx_L1_error)
}
__pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d.cy_fused_sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
__pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Function_call_with_ambiguous_arg); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__15);
__Pyx_GIVEREF(__pyx_tuple__15);
/* … */
__pyx_tuple__27 = PyTuple_Pack(4, __pyx_n_s_data, __pyx_n_s_s, __pyx_n_s_n, __pyx_n_s_N); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__27);
__Pyx_GIVEREF(__pyx_tuple__27);
/* … */
__pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_4 = __pyx_FusedFunction_New(&__pyx_fuse_0__pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_3cy_fused_sum, 0, __pyx_n_s_cy_fused_sum, NULL, __pyx_n_s_cython_magic_c9ea336cdf929fb6c3, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_empty_tuple);
if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_int64_t, __pyx_t_4) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __pyx_FusedFunction_New(&__pyx_fuse_1__pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_5cy_fused_sum, 0, __pyx_n_s_cy_fused_sum, NULL, __pyx_n_s_cython_magic_c9ea336cdf929fb6c3, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_empty_tuple);
if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_float64_t, __pyx_t_4) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __pyx_FusedFunction_New(&__pyx_mdef_54_cython_magic_c9ea336cdf929fb6c33bee737b5729b0932d7e9d_1cy_fused_sum, 0, __pyx_n_s_cy_fused_sum, NULL, __pyx_n_s_cython_magic_c9ea336cdf929fb6c3, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (!__Pyx_CyFunction_InitDefaults(__pyx_t_4, sizeof(__pyx_defaults), 1)) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_t_4)->__pyx_arg__fused_sigindex = __pyx_t_5;
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_empty_tuple);
((__pyx_FusedFunctionObject *) __pyx_t_4)->__signatures__ = __pyx_t_7;
__Pyx_GIVEREF(__pyx_t_7);
__pyx_t_7 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_cy_fused_sum, __pyx_t_4) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
09: @cython.wraparound(False)
10: def cy_fused_sum(numpy.ndarray[I_OR_F_t, ndim=1] data):
+11: cdef I_OR_F_t s = 0
__pyx_v_s = 0; /* … */ __pyx_v_s = 0.0;
+12: cdef int n, N = data.size
__pyx_t_1 = __pyx_f_5numpy_7ndarray_4size_size(((PyArrayObject *)__pyx_v_data)); if (unlikely(__pyx_t_1 == ((npy_intp)-1) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L1_error) __pyx_v_N = __pyx_t_1; /* … */ __pyx_t_1 = __pyx_f_5numpy_7ndarray_4size_size(((PyArrayObject *)__pyx_v_data)); if (unlikely(__pyx_t_1 == ((npy_intp)-1) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L1_error) __pyx_v_N = __pyx_t_1;
+13: for n in range(N):
__pyx_t_2 = __pyx_v_N;
__pyx_t_3 = __pyx_t_2;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
/* … */
__pyx_t_2 = __pyx_v_N;
__pyx_t_3 = __pyx_t_2;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
+14: s += data[n]
__pyx_t_5 = __pyx_v_n;
__pyx_v_s = (__pyx_v_s + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_data.diminfo[0].strides)));
}
/* … */
__pyx_t_5 = __pyx_v_n;
__pyx_v_s = (__pyx_v_s + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_5, __pyx_pybuffernd_data.diminfo[0].strides)));
}
+15: return s
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyInt_From_npy_int64(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0; /* … */ __Pyx_XDECREF(__pyx_r); __pyx_t_6 = PyFloat_FromDouble(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
cy_fused_sum(np.array([1.0, 2.0, 3.0, 4.0, 5.0]))
15.0
cy_fused_sum(np.array([1, 2, 3, 4, 5]))
15
%%cython -a
cimport numpy
cimport cython
ctypedef numpy.int64_t ITYPE_t
ctypedef numpy.float64_t FTYPE_t
cpdef inline double abs2(double complex z):
return z.real * z.real + z.imag * z.imag
@cython.boundscheck(False)
@cython.wraparound(False)
def cy_julia_fractal(numpy.ndarray[FTYPE_t, ndim=1] z_re,
numpy.ndarray[FTYPE_t, ndim=1] z_im,
numpy.ndarray[ITYPE_t, ndim=2] j):
cdef int m, n, t, M = z_re.size, N = z_im.size
cdef double complex z
for m in range(M):
for n in range(N):
z = z_re[m] + 1.0j * z_im[n]
for t in range(256):
z = z ** 2 - 0.05 + 0.68j
if abs2(z) > 4.0:
j[m, n] = t
break
Content of stderr:
In file included from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1929,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5,
from /home/rob/.cache/ipython/cython/_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c.c:1253:
/opt/conda/envs/npbook_py310/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with " \
| ^~~~~~~
Generated by Cython 3.0.11
Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.
+01: cimport numpy
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
02: cimport cython
03:
+04: ctypedef numpy.int64_t ITYPE_t
typedef __pyx_t_5numpy_int64_t __pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_ITYPE_t;
05: ctypedef numpy.float64_t FTYPE_t
06:
+07: cpdef inline double abs2(double complex z):
static PyObject *__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static CYTHON_INLINE double __pyx_f_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_abs2(__pyx_t_double_complex __pyx_v_z, CYTHON_UNUSED int __pyx_skip_dispatch) {
double __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2 = {"abs2", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
__pyx_t_double_complex __pyx_v_z;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("abs2 (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_z,0};
PyObject* values[1] = {0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_z)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 7, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "abs2") < 0)) __PYX_ERR(0, 7, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
}
__pyx_v_z = __Pyx_PyComplex_As___pyx_t_double_complex(values[0]); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 7, __pyx_L3_error)
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("abs2", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 7, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c.abs2", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_abs2(__pyx_self, __pyx_v_z);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_abs2(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_double_complex __pyx_v_z) {
PyObject *__pyx_r = NULL;
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_abs2(__pyx_v_z, 0); if (unlikely(__pyx_t_1 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 7, __pyx_L1_error)
__pyx_t_2 = PyFloat_FromDouble(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c.abs2", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_z); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__3);
__Pyx_GIVEREF(__pyx_tuple__3);
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_1abs2, 0, __pyx_n_s_abs2, NULL, __pyx_n_s_cython_magic_6898fa0f5546b1e451, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_abs2, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_rob_cache_ipython_cytho, __pyx_n_s_abs2, 7, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 7, __pyx_L1_error)
+08: return z.real * z.real + z.imag * z.imag
__pyx_r = ((__Pyx_CREAL(__pyx_v_z) * __Pyx_CREAL(__pyx_v_z)) + (__Pyx_CIMAG(__pyx_v_z) * __Pyx_CIMAG(__pyx_v_z))); goto __pyx_L0;
09:
+10: @cython.boundscheck(False)
/* Python wrapper */
static PyObject *__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_3cy_julia_fractal(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_3cy_julia_fractal = {"cy_julia_fractal", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_3cy_julia_fractal, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_3cy_julia_fractal(PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyArrayObject *__pyx_v_z_re = 0;
PyArrayObject *__pyx_v_z_im = 0;
PyArrayObject *__pyx_v_j = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cy_julia_fractal (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_MACROS
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject **__pyx_pyargnames[] = {&__pyx_n_s_z_re,&__pyx_n_s_z_im,&__pyx_n_s_j,0};
PyObject* values[3] = {0,0,0};
if (__pyx_kwds) {
Py_ssize_t kw_args;
switch (__pyx_nargs) {
case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
switch (__pyx_nargs) {
case 0:
if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_z_re)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L3_error)
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_z_im)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L3_error)
else {
__Pyx_RaiseArgtupleInvalid("cy_julia_fractal", 1, 3, 3, 1); __PYX_ERR(0, 10, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_j)) != 0)) {
(void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
kw_args--;
}
else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L3_error)
else {
__Pyx_RaiseArgtupleInvalid("cy_julia_fractal", 1, 3, 3, 2); __PYX_ERR(0, 10, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "cy_julia_fractal") < 0)) __PYX_ERR(0, 10, __pyx_L3_error)
}
} else if (unlikely(__pyx_nargs != 3)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
}
__pyx_v_z_re = ((PyArrayObject *)values[0]);
__pyx_v_z_im = ((PyArrayObject *)values[1]);
__pyx_v_j = ((PyArrayObject *)values[2]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("cy_julia_fractal", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 10, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_AddTraceback("_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c.cy_julia_fractal", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z_re), __pyx_ptype_5numpy_ndarray, 1, "z_re", 0))) __PYX_ERR(0, 12, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z_im), __pyx_ptype_5numpy_ndarray, 1, "z_im", 0))) __PYX_ERR(0, 13, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_j), __pyx_ptype_5numpy_ndarray, 1, "j", 0))) __PYX_ERR(0, 14, __pyx_L1_error)
__pyx_r = __pyx_pf_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_2cy_julia_fractal(__pyx_self, __pyx_v_z_re, __pyx_v_z_im, __pyx_v_j);
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
{
Py_ssize_t __pyx_temp;
for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
__Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
}
}
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_2cy_julia_fractal(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_z_re, PyArrayObject *__pyx_v_z_im, PyArrayObject *__pyx_v_j) {
int __pyx_v_m;
int __pyx_v_n;
int __pyx_v_t;
int __pyx_v_M;
int __pyx_v_N;
__pyx_t_double_complex __pyx_v_z;
__Pyx_LocalBuf_ND __pyx_pybuffernd_j;
__Pyx_Buffer __pyx_pybuffer_j;
__Pyx_LocalBuf_ND __pyx_pybuffernd_z_im;
__Pyx_Buffer __pyx_pybuffer_z_im;
__Pyx_LocalBuf_ND __pyx_pybuffernd_z_re;
__Pyx_Buffer __pyx_pybuffer_z_re;
PyObject *__pyx_r = NULL;
__pyx_pybuffer_z_re.pybuffer.buf = NULL;
__pyx_pybuffer_z_re.refcount = 0;
__pyx_pybuffernd_z_re.data = NULL;
__pyx_pybuffernd_z_re.rcbuffer = &__pyx_pybuffer_z_re;
__pyx_pybuffer_z_im.pybuffer.buf = NULL;
__pyx_pybuffer_z_im.refcount = 0;
__pyx_pybuffernd_z_im.data = NULL;
__pyx_pybuffernd_z_im.rcbuffer = &__pyx_pybuffer_z_im;
__pyx_pybuffer_j.pybuffer.buf = NULL;
__pyx_pybuffer_j.refcount = 0;
__pyx_pybuffernd_j.data = NULL;
__pyx_pybuffernd_j.rcbuffer = &__pyx_pybuffer_j;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_z_re.rcbuffer->pybuffer, (PyObject*)__pyx_v_z_re, &__Pyx_TypeInfo_nn___pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_FTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 10, __pyx_L1_error)
}
__pyx_pybuffernd_z_re.diminfo[0].strides = __pyx_pybuffernd_z_re.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_z_re.diminfo[0].shape = __pyx_pybuffernd_z_re.rcbuffer->pybuffer.shape[0];
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_z_im.rcbuffer->pybuffer, (PyObject*)__pyx_v_z_im, &__Pyx_TypeInfo_nn___pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_FTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 10, __pyx_L1_error)
}
__pyx_pybuffernd_z_im.diminfo[0].strides = __pyx_pybuffernd_z_im.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_z_im.diminfo[0].shape = __pyx_pybuffernd_z_im.rcbuffer->pybuffer.shape[0];
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_j.rcbuffer->pybuffer, (PyObject*)__pyx_v_j, &__Pyx_TypeInfo_nn___pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_ITYPE_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 10, __pyx_L1_error)
}
__pyx_pybuffernd_j.diminfo[0].strides = __pyx_pybuffernd_j.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_j.diminfo[0].shape = __pyx_pybuffernd_j.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_j.diminfo[1].strides = __pyx_pybuffernd_j.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_j.diminfo[1].shape = __pyx_pybuffernd_j.rcbuffer->pybuffer.shape[1];
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_j.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_z_im.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_z_re.rcbuffer->pybuffer);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c.cy_julia_fractal", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_j.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_z_im.rcbuffer->pybuffer);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_z_re.rcbuffer->pybuffer);
__pyx_L2:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__5 = PyTuple_Pack(9, __pyx_n_s_z_re, __pyx_n_s_z_im, __pyx_n_s_j, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s_t, __pyx_n_s_M, __pyx_n_s_N, __pyx_n_s_z); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 10, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__5);
__Pyx_GIVEREF(__pyx_tuple__5);
/* … */
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_3cy_julia_fractal, 0, __pyx_n_s_cy_julia_fractal, NULL, __pyx_n_s_cython_magic_6898fa0f5546b1e451, __pyx_d, ((PyObject *)__pyx_codeobj__6)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_cy_julia_fractal, __pyx_t_2) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11: @cython.wraparound(False)
12: def cy_julia_fractal(numpy.ndarray[FTYPE_t, ndim=1] z_re,
13: numpy.ndarray[FTYPE_t, ndim=1] z_im,
14: numpy.ndarray[ITYPE_t, ndim=2] j):
+15: cdef int m, n, t, M = z_re.size, N = z_im.size
__pyx_t_1 = __pyx_f_5numpy_7ndarray_4size_size(((PyArrayObject *)__pyx_v_z_re)); if (unlikely(__pyx_t_1 == ((npy_intp)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L1_error) __pyx_v_M = __pyx_t_1; __pyx_t_1 = __pyx_f_5numpy_7ndarray_4size_size(((PyArrayObject *)__pyx_v_z_im)); if (unlikely(__pyx_t_1 == ((npy_intp)-1) && PyErr_Occurred())) __PYX_ERR(0, 15, __pyx_L1_error) __pyx_v_N = __pyx_t_1;
16: cdef double complex z
+17: for m in range(M):
__pyx_t_2 = __pyx_v_M;
__pyx_t_3 = __pyx_t_2;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_m = __pyx_t_4;
+18: for n in range(N):
__pyx_t_5 = __pyx_v_N;
__pyx_t_6 = __pyx_t_5;
for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
__pyx_v_n = __pyx_t_7;
+19: z = z_re[m] + 1.0j * z_im[n]
__pyx_t_8 = __pyx_v_m;
__pyx_t_9 = __pyx_t_double_complex_from_parts(0, 1.0);
__pyx_t_10 = __pyx_v_n;
__pyx_t_11 = __Pyx_c_sum_npy_float64(__pyx_t_npy_float64_complex_from_parts((*__Pyx_BufPtrStrided1d(__pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_FTYPE_t *, __pyx_pybuffernd_z_re.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_z_re.diminfo[0].strides)), 0), __Pyx_c_prod_npy_float64(__pyx_t_npy_float64_complex_from_parts(__Pyx_CREAL(__pyx_t_9), __Pyx_CIMAG(__pyx_t_9)), __pyx_t_npy_float64_complex_from_parts((*__Pyx_BufPtrStrided1d(__pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_FTYPE_t *, __pyx_pybuffernd_z_im.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_z_im.diminfo[0].strides)), 0)));
__pyx_v_z = __pyx_t_double_complex_from_parts(__Pyx_CREAL_CyTypedef(__pyx_t_11), __Pyx_CIMAG_CyTypedef(__pyx_t_11));
+20: for t in range(256):
for (__pyx_t_12 = 0; __pyx_t_12 < 0x100; __pyx_t_12+=1) {
__pyx_v_t = __pyx_t_12;
+21: z = z ** 2 - 0.05 + 0.68j
__pyx_v_z = __Pyx_c_sum_double(__Pyx_c_diff_double(__Pyx_c_pow_double(__pyx_v_z, __pyx_t_double_complex_from_parts(2, 0)), __pyx_t_double_complex_from_parts(0.05, 0)), __pyx_t_double_complex_from_parts(0, 0.68));
+22: if abs2(z) > 4.0:
__pyx_t_13 = __pyx_f_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_abs2(__pyx_v_z, 0); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_t_14 = (__pyx_t_13 > 4.0); if (__pyx_t_14) { /* … */ } } __pyx_L8_break:; } }
+23: j[m, n] = t
__pyx_t_10 = __pyx_v_m;
__pyx_t_8 = __pyx_v_n;
*__Pyx_BufPtrStrided2d(__pyx_t_54_cython_magic_6898fa0f5546b1e4516bdba3309b213764481d6c_ITYPE_t *, __pyx_pybuffernd_j.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_j.diminfo[0].strides, __pyx_t_8, __pyx_pybuffernd_j.diminfo[1].strides) = __pyx_v_t;
+24: break
goto __pyx_L8_break;
N = 1024
j = np.zeros((N, N), dtype=np.int64)
z_real = np.linspace(-1.5, 1.5, N)
z_imag = np.linspace(-1.5, 1.5, N)
%timeit cy_julia_fractal(z_real, z_imag, j)
2.3 s ± 23.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit jit_julia_fractal(z_real, z_imag, j)
169 ms ± 5.53 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
j1 = np.zeros((N, N), dtype=np.int64)
cy_julia_fractal(z_real, z_imag, j1)
j2 = np.zeros((N, N), dtype=np.int64)
jit_julia_fractal(z_real, z_imag, j2)
# assert np.allclose(j1, j2)
fig, axes = plt.subplots(1, 2, figsize=(14, 14))
axes[0].imshow(j1, cmap=plt.cm.RdBu_r,
extent=[-1.5, 1.5, -1.5, 1.5])
axes[0].set_xlabel("$\mathrm{Re}(z)$", fontsize=18)
axes[0].set_ylabel("$\mathrm{Im}(z)$", fontsize=18)
axes[1].imshow(j2, cmap=plt.cm.RdBu_r,
extent=[-1.5, 1.5, -1.5, 1.5])
axes[1].set_xlabel("$\mathrm{Re}(z)$", fontsize=18)
axes[1].set_ylabel("$\mathrm{Im}(z)$", fontsize=18)
fig.tight_layout()
%%cython
cdef extern from "math.h":
double acos(double)
def cy_acos1(double x):
return acos(x)
%timeit cy_acos1(0.5)
32.2 ns ± 0.0402 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
%%cython
from libc.math cimport acos
def cy_acos2(double x):
return acos(x)
%timeit cy_acos2(0.5)
31.5 ns ± 0.0371 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
from numpy import arccos
%timeit arccos(0.5)
444 ns ± 8.64 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
from math import acos
%timeit acos(0.5)
40 ns ± 1.26 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
assert cy_acos1(0.5) == acos(0.5)
assert cy_acos2(0.5) == acos(0.5)
%reload_ext version_information
%version_information numpy, cython, numba, matplotlib
| Software | Version |
|---|---|
| Python | 3.10.12 64bit [Clang 14.0.6 ] |
| IPython | 8.12.0 |
| OS | macOS 10.15.7 x86\_64 i386 64bit |
| numpy | 1.22.3 |
| cython | 3.0.0 |
| numba | 0.58.0 |
| matplotlib | 3.7.1 |
| Sun Nov 03 19:47:42 2024 JST | |