Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c6846bdf
Commit
c6846bdf
authored
Apr 12, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move complex type support into a utility code file.
parent
efda3095
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
284 additions
and
288 deletions
+284
-288
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+11
-6
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+18
-282
Cython/Utility/Complex.c
Cython/Utility/Complex.c
+255
-0
No files found.
Cython/Compiler/Code.py
View file @
c6846bdf
...
@@ -137,16 +137,19 @@ class UtilityCodeBase(object):
...
@@ -137,16 +137,19 @@ class UtilityCodeBase(object):
if type == 'proto':
if type == 'proto':
utility[0] = code
utility[0] = code
elif type.startswith('proto.'):
utility[0] = code
utility[1] = type[6:]
elif type == 'impl':
elif type == 'impl':
utility[
1
] = code
utility[
2
] = code
else:
else:
all_tags = utility[
2
]
all_tags = utility[
3
]
if KEYWORDS_MUST_BE_BYTES:
if KEYWORDS_MUST_BE_BYTES:
type = type.encode('ASCII')
type = type.encode('ASCII')
all_tags[type] = code
all_tags[type] = code
if tags:
if tags:
all_tags = utility[
2
]
all_tags = utility[
3
]
for name, values in tags.items():
for name, values in tags.items():
if KEYWORDS_MUST_BE_BYTES:
if KEYWORDS_MUST_BE_BYTES:
name = name.encode('ASCII')
name = name.encode('ASCII')
...
@@ -172,12 +175,12 @@ class UtilityCodeBase(object):
...
@@ -172,12 +175,12 @@ class UtilityCodeBase(object):
(r'^%(C)s{5,30}
\
s*(?P<
n
ame>(?:
\
w|
\
.)+)
\
s*%(C)s{
5
,30}|'
(r'^%(C)s{5,30}
\
s*(?P<
n
ame>(?:
\
w|
\
.)+)
\
s*%(C)s{
5
,30}|'
r'^%(C)s+@(?P<tag>
\
w+)
\
s*:
\
s*(?P<
v
alue>(?:
\
w|[.:])+)
'
) %
r'^%(C)s+@(?P<tag>
\
w+)
\
s*:
\
s*(?P<
v
alue>(?:
\
w|[.:])+)
'
) %
{'C': comment}).match
{'C': comment}).match
match_type = re.compile('(.+)[.](proto|impl|init|cleanup)$').match
match_type = re.compile('(.+)[.](proto
(?:[.]
\
S+)?
|impl|i
n
it|cleanup)$').match
with closing(Utils.open_source_file(filename, encoding='UTF-8')) as f:
with closing(Utils.open_source_file(filename, encoding='UTF-8')) as f:
all_lines = f.readlines()
all_lines = f.readlines()
utilities = defaultdict(lambda: [None, None, {}])
utilities = defaultdict(lambda: [None, None,
None,
{}])
lines = []
lines = []
tags = defaultdict(set)
tags = defaultdict(set)
utility = type = None
utility = type = None
...
@@ -251,7 +254,7 @@ class UtilityCodeBase(object):
...
@@ -251,7 +254,7 @@ class UtilityCodeBase(object):
from_file = files[0]
from_file = files[0]
utilities = cls.load_utilities_from_file(from_file)
utilities = cls.load_utilities_from_file(from_file)
proto, impl, tags = utilities[util_code_name]
proto,
proto_block,
impl, tags = utilities[util_code_name]
if tags:
if tags:
orig_kwargs = kwargs.copy()
orig_kwargs = kwargs.copy()
...
@@ -275,6 +278,8 @@ class UtilityCodeBase(object):
...
@@ -275,6 +278,8 @@ class UtilityCodeBase(object):
if proto is not None:
if proto is not None:
kwargs['proto'] = proto
kwargs['proto'] = proto
if proto_block is not None:
kwargs['proto_block'] = proto_block
if impl is not None:
if impl is not None:
kwargs['impl'] = impl
kwargs['impl'] = impl
...
...
Cython/Compiler/PyrexTypes.py
View file @
c6846bdf
...
@@ -2037,41 +2037,36 @@ class CComplexType(CNumericType):
...
@@ -2037,41 +2037,36 @@ class CComplexType(CNumericType):
return
True
return
True
def
_utility_code_context
(
self
):
return
{
'type'
:
self
.
empty_declaration_code
(),
'type_name'
:
self
.
specialization_name
(),
'real_type'
:
self
.
real_type
.
empty_declaration_code
(),
'm'
:
self
.
funcsuffix
,
'is_float'
:
int
(
self
.
real_type
.
is_float
)
}
def
create_declaration_utility_code
(
self
,
env
):
def
create_declaration_utility_code
(
self
,
env
):
# This must always be run, because a single CComplexType instance can be shared
# This must always be run, because a single CComplexType instance can be shared
# across multiple compilations (the one created in the module scope)
# across multiple compilations (the one created in the module scope)
env
.
use_utility_code
(
complex_header_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
'Header'
,
'Complex.c'
))
env
.
use_utility_code
(
complex_real_imag_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
'RealImag'
,
'Complex.c'
))
for
utility_code
in
(
complex_type_utility_code
,
env
.
use_utility_code
(
TempitaUtilityCode
.
load_cached
(
complex_from_parts_utility_code
,
'Declarations'
,
'Complex.c'
,
self
.
_utility_code_context
()))
complex_arithmetic_utility_code
):
env
.
use_utility_code
(
TempitaUtilityCode
.
load_cached
(
env
.
use_utility_code
(
'Arithmetic'
,
'Complex.c'
,
self
.
_utility_code_context
()))
utility_code
.
specialize
(
self
,
real_type
=
self
.
real_type
.
empty_declaration_code
(),
m
=
self
.
funcsuffix
,
is_float
=
self
.
real_type
.
is_float
))
return
True
return
True
def
can_coerce_to_pyobject
(
self
,
env
):
def
can_coerce_to_pyobject
(
self
,
env
):
return
True
return
True
def
create_to_py_utility_code
(
self
,
env
):
def
create_to_py_utility_code
(
self
,
env
):
env
.
use_utility_code
(
complex_real_imag_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
'ToPy'
,
'Complex.c'
))
env
.
use_utility_code
(
complex_to_py_utility_code
)
return
True
return
True
def
create_from_py_utility_code
(
self
,
env
):
def
create_from_py_utility_code
(
self
,
env
):
self
.
real_type
.
create_from_py_utility_code
(
env
)
env
.
use_utility_code
(
TempitaUtilityCode
.
load_cached
(
'FromPy'
,
'Complex.c'
,
self
.
_utility_code_context
()))
for
utility_code
in
(
complex_from_parts_utility_code
,
complex_from_py_utility_code
):
env
.
use_utility_code
(
utility_code
.
specialize
(
self
,
real_type
=
self
.
real_type
.
empty_declaration_code
(),
m
=
self
.
funcsuffix
,
is_float
=
self
.
real_type
.
is_float
))
self
.
from_py_function
=
"__Pyx_PyComplex_As_"
+
self
.
specialization_name
()
self
.
from_py_function
=
"__Pyx_PyComplex_As_"
+
self
.
specialization_name
()
return
True
return
True
...
@@ -2109,265 +2104,6 @@ complex_ops = {
...
@@ -2109,265 +2104,6 @@ complex_ops = {
(
2
,
'=='
):
'eq'
,
(
2
,
'=='
):
'eq'
,
}
}
complex_header_utility_code
=
UtilityCode
(
proto_block
=
'h_code'
,
proto
=
"""
#if !defined(CYTHON_CCOMPLEX)
#if defined(__cplusplus)
#define CYTHON_CCOMPLEX 1
#elif defined(_Complex_I)
#define CYTHON_CCOMPLEX 1
#else
#define CYTHON_CCOMPLEX 0
#endif
#endif
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#include <complex>
#else
#include <complex.h>
#endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
#undef _Complex_I
#define _Complex_I 1.0fj
#endif
"""
)
complex_real_imag_utility_code
=
UtilityCode
(
proto
=
"""
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#define __Pyx_CREAL(z) ((z).real())
#define __Pyx_CIMAG(z) ((z).imag())
#else
#define __Pyx_CREAL(z) (__real__(z))
#define __Pyx_CIMAG(z) (__imag__(z))
#endif
#else
#define __Pyx_CREAL(z) ((z).real)
#define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(__cplusplus) && CYTHON_CCOMPLEX
\
&& (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
#define __Pyx_SET_CREAL(z,x) ((z).real(x))
#define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
#define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
#define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif
"""
)
complex_type_utility_code
=
UtilityCode
(
proto_block
=
'complex_type_declarations'
,
proto
=
"""
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
typedef ::std::complex< %(real_type)s > %(type_name)s;
#else
typedef %(real_type)s _Complex %(type_name)s;
#endif
#else
typedef struct { %(real_type)s real, imag; } %(type_name)s;
#endif
"""
)
complex_from_parts_utility_code
=
UtilityCode
(
proto_block
=
'utility_code_proto'
,
proto
=
"""
static CYTHON_INLINE %(type)s %(type_name)s_from_parts(%(real_type)s, %(real_type)s);
"""
,
impl
=
"""
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
static CYTHON_INLINE %(type)s %(type_name)s_from_parts(%(real_type)s x, %(real_type)s y) {
return ::std::complex< %(real_type)s >(x, y);
}
#else
static CYTHON_INLINE %(type)s %(type_name)s_from_parts(%(real_type)s x, %(real_type)s y) {
return x + y*(%(type)s)_Complex_I;
}
#endif
#else
static CYTHON_INLINE %(type)s %(type_name)s_from_parts(%(real_type)s x, %(real_type)s y) {
%(type)s z;
z.real = x;
z.imag = y;
return z;
}
#endif
"""
)
complex_to_py_utility_code
=
UtilityCode
(
proto
=
"""
#define __pyx_PyComplex_FromComplex(z)
\
\
PyComplex_FromDoubles((double)__Pyx_CREAL(z),
\
\
(double)__Pyx_CIMAG(z))
"""
)
complex_from_py_utility_code
=
UtilityCode
(
proto
=
"""
static %(type)s __Pyx_PyComplex_As_%(type_name)s(PyObject*);
"""
,
impl
=
"""
static %(type)s __Pyx_PyComplex_As_%(type_name)s(PyObject* o) {
Py_complex cval;
#if CYTHON_COMPILING_IN_CPYTHON
if (PyComplex_CheckExact(o))
cval = ((PyComplexObject *)o)->cval;
else
#endif
cval = PyComplex_AsCComplex(o);
return %(type_name)s_from_parts(
(%(real_type)s)cval.real,
(%(real_type)s)cval.imag);
}
"""
)
complex_arithmetic_utility_code
=
UtilityCode
(
proto
=
"""
#if CYTHON_CCOMPLEX
#define __Pyx_c_eq%(m)s(a, b) ((a)==(b))
#define __Pyx_c_sum%(m)s(a, b) ((a)+(b))
#define __Pyx_c_diff%(m)s(a, b) ((a)-(b))
#define __Pyx_c_prod%(m)s(a, b) ((a)*(b))
#define __Pyx_c_quot%(m)s(a, b) ((a)/(b))
#define __Pyx_c_neg%(m)s(a) (-(a))
#ifdef __cplusplus
#define __Pyx_c_is_zero%(m)s(z) ((z)==(%(real_type)s)0)
#define __Pyx_c_conj%(m)s(z) (::std::conj(z))
#if %(is_float)s
#define __Pyx_c_abs%(m)s(z) (::std::abs(z))
#define __Pyx_c_pow%(m)s(a, b) (::std::pow(a, b))
#endif
#else
#define __Pyx_c_is_zero%(m)s(z) ((z)==0)
#define __Pyx_c_conj%(m)s(z) (conj%(m)s(z))
#if %(is_float)s
#define __Pyx_c_abs%(m)s(z) (cabs%(m)s(z))
#define __Pyx_c_pow%(m)s(a, b) (cpow%(m)s(a, b))
#endif
#endif
#else
static CYTHON_INLINE int __Pyx_c_eq%(m)s(%(type)s, %(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_sum%(m)s(%(type)s, %(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_diff%(m)s(%(type)s, %(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_prod%(m)s(%(type)s, %(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_quot%(m)s(%(type)s, %(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_neg%(m)s(%(type)s);
static CYTHON_INLINE int __Pyx_c_is_zero%(m)s(%(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_conj%(m)s(%(type)s);
#if %(is_float)s
static CYTHON_INLINE %(real_type)s __Pyx_c_abs%(m)s(%(type)s);
static CYTHON_INLINE %(type)s __Pyx_c_pow%(m)s(%(type)s, %(type)s);
#endif
#endif
"""
,
impl
=
"""
#if CYTHON_CCOMPLEX
#else
static CYTHON_INLINE int __Pyx_c_eq%(m)s(%(type)s a, %(type)s b) {
return (a.real == b.real) && (a.imag == b.imag);
}
static CYTHON_INLINE %(type)s __Pyx_c_sum%(m)s(%(type)s a, %(type)s b) {
%(type)s z;
z.real = a.real + b.real;
z.imag = a.imag + b.imag;
return z;
}
static CYTHON_INLINE %(type)s __Pyx_c_diff%(m)s(%(type)s a, %(type)s b) {
%(type)s z;
z.real = a.real - b.real;
z.imag = a.imag - b.imag;
return z;
}
static CYTHON_INLINE %(type)s __Pyx_c_prod%(m)s(%(type)s a, %(type)s b) {
%(type)s z;
z.real = a.real * b.real - a.imag * b.imag;
z.imag = a.real * b.imag + a.imag * b.real;
return z;
}
static CYTHON_INLINE %(type)s __Pyx_c_quot%(m)s(%(type)s a, %(type)s b) {
%(type)s z;
%(real_type)s denom = b.real * b.real + b.imag * b.imag;
z.real = (a.real * b.real + a.imag * b.imag) / denom;
z.imag = (a.imag * b.real - a.real * b.imag) / denom;
return z;
}
static CYTHON_INLINE %(type)s __Pyx_c_neg%(m)s(%(type)s a) {
%(type)s z;
z.real = -a.real;
z.imag = -a.imag;
return z;
}
static CYTHON_INLINE int __Pyx_c_is_zero%(m)s(%(type)s a) {
return (a.real == 0) && (a.imag == 0);
}
static CYTHON_INLINE %(type)s __Pyx_c_conj%(m)s(%(type)s a) {
%(type)s z;
z.real = a.real;
z.imag = -a.imag;
return z;
}
#if %(is_float)s
static CYTHON_INLINE %(real_type)s __Pyx_c_abs%(m)s(%(type)s z) {
#if !defined(HAVE_HYPOT) || defined(_MSC_VER)
return sqrt%(m)s(z.real*z.real + z.imag*z.imag);
#else
return hypot%(m)s(z.real, z.imag);
#endif
}
static CYTHON_INLINE %(type)s __Pyx_c_pow%(m)s(%(type)s a, %(type)s b) {
%(type)s z;
%(real_type)s r, lnr, theta, z_r, z_theta;
if (b.imag == 0 && b.real == (int)b.real) {
if (b.real < 0) {
%(real_type)s denom = a.real * a.real + a.imag * a.imag;
a.real = a.real / denom;
a.imag = -a.imag / denom;
b.real = -b.real;
}
switch ((int)b.real) {
case 0:
z.real = 1;
z.imag = 0;
return z;
case 1:
return a;
case 2:
z = __Pyx_c_prod%(m)s(a, a);
return __Pyx_c_prod%(m)s(a, a);
case 3:
z = __Pyx_c_prod%(m)s(a, a);
return __Pyx_c_prod%(m)s(z, a);
case 4:
z = __Pyx_c_prod%(m)s(a, a);
return __Pyx_c_prod%(m)s(z, z);
}
}
if (a.imag == 0) {
if (a.real == 0) {
return a;
}
r = a.real;
theta = 0;
} else {
r = __Pyx_c_abs%(m)s(a);
theta = atan2%(m)s(a.imag, a.real);
}
lnr = log%(m)s(r);
z_r = exp%(m)s(lnr * b.real - theta * b.imag);
z_theta = theta * b.real + lnr * b.imag;
z.real = z_r * cos%(m)s(z_theta);
z.imag = z_r * sin%(m)s(z_theta);
return z;
}
#endif
#endif
"""
)
class
CPointerBaseType
(
CType
):
class
CPointerBaseType
(
CType
):
# common base type for pointer/array types
# common base type for pointer/array types
...
...
Cython/Utility/Complex.c
0 → 100644
View file @
c6846bdf
/////////////// Header.proto.h_code ///////////////
#if !defined(CYTHON_CCOMPLEX)
#if defined(__cplusplus)
#define CYTHON_CCOMPLEX 1
#elif defined(_Complex_I)
#define CYTHON_CCOMPLEX 1
#else
#define CYTHON_CCOMPLEX 0
#endif
#endif
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#include <complex>
#else
#include <complex.h>
#endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
#undef _Complex_I
#define _Complex_I 1.0fj
#endif
/////////////// RealImag.proto ///////////////
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#define __Pyx_CREAL(z) ((z).real())
#define __Pyx_CIMAG(z) ((z).imag())
#else
#define __Pyx_CREAL(z) (__real__(z))
#define __Pyx_CIMAG(z) (__imag__(z))
#endif
#else
#define __Pyx_CREAL(z) ((z).real)
#define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(__cplusplus) && CYTHON_CCOMPLEX \
&& (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
#define __Pyx_SET_CREAL(z,x) ((z).real(x))
#define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
#define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
#define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif
/////////////// Declarations.proto.complex_type_declarations ///////////////
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
typedef
::
std
::
complex
<
{{
real_type
}}
>
{{
type_name
}};
#else
typedef
{{
real_type
}}
_Complex
{{
type_name
}};
#endif
#else
typedef
struct
{
{{
real_type
}}
real
,
imag
;
}
{{
type_name
}};
#endif
static
CYTHON_INLINE
{{
type
}}
{{
type_name
}}
_from_parts
({{
real_type
}},
{{
real_type
}});
/////////////// Declarations ///////////////
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
static
CYTHON_INLINE
{{
type
}}
{{
type_name
}}
_from_parts
({{
real_type
}}
x
,
{{
real_type
}}
y
)
{
return
::
std
::
complex
<
{{
real_type
}}
>
(
x
,
y
);
}
#else
static
CYTHON_INLINE
{{
type
}}
{{
type_name
}}
_from_parts
({{
real_type
}}
x
,
{{
real_type
}}
y
)
{
return
x
+
y
*
({{
type
}})
_Complex_I
;
}
#endif
#else
static
CYTHON_INLINE
{{
type
}}
{{
type_name
}}
_from_parts
({{
real_type
}}
x
,
{{
real_type
}}
y
)
{
{{
type
}}
z
;
z
.
real
=
x
;
z
.
imag
=
y
;
return
z
;
}
#endif
/////////////// ToPy.proto ///////////////
#define __pyx_PyComplex_FromComplex(z) \
PyComplex_FromDoubles((double)__Pyx_CREAL(z), \
(double)__Pyx_CIMAG(z))
/////////////// FromPy.proto ///////////////
static
{{
type
}}
__Pyx_PyComplex_As_
{{
type_name
}}(
PyObject
*
);
/////////////// FromPy ///////////////
static
{{
type
}}
__Pyx_PyComplex_As_
{{
type_name
}}(
PyObject
*
o
)
{
Py_complex
cval
;
#if CYTHON_COMPILING_IN_CPYTHON
if
(
PyComplex_CheckExact
(
o
))
cval
=
((
PyComplexObject
*
)
o
)
->
cval
;
else
#endif
cval
=
PyComplex_AsCComplex
(
o
);
return
{{
type_name
}}
_from_parts
(
({{
real_type
}})
cval
.
real
,
({{
real_type
}})
cval
.
imag
);
}
/////////////// Arithmetic.proto ///////////////
#if CYTHON_CCOMPLEX
#define __Pyx_c_eq{{m}}(a, b) ((a)==(b))
#define __Pyx_c_sum{{m}}(a, b) ((a)+(b))
#define __Pyx_c_diff{{m}}(a, b) ((a)-(b))
#define __Pyx_c_prod{{m}}(a, b) ((a)*(b))
#define __Pyx_c_quot{{m}}(a, b) ((a)/(b))
#define __Pyx_c_neg{{m}}(a) (-(a))
#ifdef __cplusplus
#define __Pyx_c_is_zero{{m}}(z) ((z)==({{real_type}})0)
#define __Pyx_c_conj{{m}}(z) (::std::conj(z))
#if {{is_float}}
#define __Pyx_c_abs{{m}}(z) (::std::abs(z))
#define __Pyx_c_pow{{m}}(a, b) (::std::pow(a, b))
#endif
#else
#define __Pyx_c_is_zero{{m}}(z) ((z)==0)
#define __Pyx_c_conj{{m}}(z) (conj{{m}}(z))
#if {{is_float}}
#define __Pyx_c_abs{{m}}(z) (cabs{{m}}(z))
#define __Pyx_c_pow{{m}}(a, b) (cpow{{m}}(a, b))
#endif
#endif
#else
static
CYTHON_INLINE
int
__Pyx_c_eq
{{
m
}}({{
type
}},
{{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_sum
{{
m
}}({{
type
}},
{{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_diff
{{
m
}}({{
type
}},
{{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_prod
{{
m
}}({{
type
}},
{{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_quot
{{
m
}}({{
type
}},
{{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_neg
{{
m
}}({{
type
}});
static
CYTHON_INLINE
int
__Pyx_c_is_zero
{{
m
}}({{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_conj
{{
m
}}({{
type
}});
#if {{is_float}}
static
CYTHON_INLINE
{{
real_type
}}
__Pyx_c_abs
{{
m
}}({{
type
}});
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_pow
{{
m
}}({{
type
}},
{{
type
}});
#endif
#endif
/////////////// Arithmetic ///////////////
#if CYTHON_CCOMPLEX
#else
static
CYTHON_INLINE
int
__Pyx_c_eq
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
return
(
a
.
real
==
b
.
real
)
&&
(
a
.
imag
==
b
.
imag
);
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_sum
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
{{
type
}}
z
;
z
.
real
=
a
.
real
+
b
.
real
;
z
.
imag
=
a
.
imag
+
b
.
imag
;
return
z
;
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_diff
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
{{
type
}}
z
;
z
.
real
=
a
.
real
-
b
.
real
;
z
.
imag
=
a
.
imag
-
b
.
imag
;
return
z
;
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_prod
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
{{
type
}}
z
;
z
.
real
=
a
.
real
*
b
.
real
-
a
.
imag
*
b
.
imag
;
z
.
imag
=
a
.
real
*
b
.
imag
+
a
.
imag
*
b
.
real
;
return
z
;
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_quot
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
{{
type
}}
z
;
{{
real_type
}}
denom
=
b
.
real
*
b
.
real
+
b
.
imag
*
b
.
imag
;
z
.
real
=
(
a
.
real
*
b
.
real
+
a
.
imag
*
b
.
imag
)
/
denom
;
z
.
imag
=
(
a
.
imag
*
b
.
real
-
a
.
real
*
b
.
imag
)
/
denom
;
return
z
;
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_neg
{{
m
}}({{
type
}}
a
)
{
{{
type
}}
z
;
z
.
real
=
-
a
.
real
;
z
.
imag
=
-
a
.
imag
;
return
z
;
}
static
CYTHON_INLINE
int
__Pyx_c_is_zero
{{
m
}}({{
type
}}
a
)
{
return
(
a
.
real
==
0
)
&&
(
a
.
imag
==
0
);
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_conj
{{
m
}}({{
type
}}
a
)
{
{{
type
}}
z
;
z
.
real
=
a
.
real
;
z
.
imag
=
-
a
.
imag
;
return
z
;
}
#if {{is_float}}
static
CYTHON_INLINE
{{
real_type
}}
__Pyx_c_abs
{{
m
}}({{
type
}}
z
)
{
#if !defined(HAVE_HYPOT) || defined(_MSC_VER)
return
sqrt
{{
m
}}(
z
.
real
*
z
.
real
+
z
.
imag
*
z
.
imag
);
#else
return
hypot
{{
m
}}(
z
.
real
,
z
.
imag
);
#endif
}
static
CYTHON_INLINE
{{
type
}}
__Pyx_c_pow
{{
m
}}({{
type
}}
a
,
{{
type
}}
b
)
{
{{
type
}}
z
;
{{
real_type
}}
r
,
lnr
,
theta
,
z_r
,
z_theta
;
if
(
b
.
imag
==
0
&&
b
.
real
==
(
int
)
b
.
real
)
{
if
(
b
.
real
<
0
)
{
{{
real_type
}}
denom
=
a
.
real
*
a
.
real
+
a
.
imag
*
a
.
imag
;
a
.
real
=
a
.
real
/
denom
;
a
.
imag
=
-
a
.
imag
/
denom
;
b
.
real
=
-
b
.
real
;
}
switch
((
int
)
b
.
real
)
{
case
0
:
z
.
real
=
1
;
z
.
imag
=
0
;
return
z
;
case
1
:
return
a
;
case
2
:
z
=
__Pyx_c_prod
{{
m
}}(
a
,
a
);
return
__Pyx_c_prod
{{
m
}}(
a
,
a
);
case
3
:
z
=
__Pyx_c_prod
{{
m
}}(
a
,
a
);
return
__Pyx_c_prod
{{
m
}}(
z
,
a
);
case
4
:
z
=
__Pyx_c_prod
{{
m
}}(
a
,
a
);
return
__Pyx_c_prod
{{
m
}}(
z
,
z
);
}
}
if
(
a
.
imag
==
0
)
{
if
(
a
.
real
==
0
)
{
return
a
;
}
r
=
a
.
real
;
theta
=
0
;
}
else
{
r
=
__Pyx_c_abs
{{
m
}}(
a
);
theta
=
atan2
{{
m
}}(
a
.
imag
,
a
.
real
);
}
lnr
=
log
{{
m
}}(
r
);
z_r
=
exp
{{
m
}}(
lnr
*
b
.
real
-
theta
*
b
.
imag
);
z_theta
=
theta
*
b
.
real
+
lnr
*
b
.
imag
;
z
.
real
=
z_r
*
cos
{{
m
}}(
z_theta
);
z
.
imag
=
z_r
*
sin
{{
m
}}(
z_theta
);
return
z
;
}
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment