Skip to content

Commit e205694

Browse files
authored
Merge pull request #99 from isuruf/cython
Workarounds for Cython v0.24 bugs
2 parents 1cc9229 + 44bb10c commit e205694

File tree

4 files changed

+52
-64
lines changed

4 files changed

+52
-64
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ install:
6262

6363
- set PATH=C:\Python%PYTHON_VERSION%;C:\Python%PYTHON_VERSION%\Scripts;%PATH%
6464
- pip install nose pytest sympy
65-
- pip install --install-option="--no-cython-compile" cython==0.23
65+
- pip install --install-option="--no-cython-compile" cython
6666

6767
- set /p commit=<symengine_version.txt
6868
- cd symengine-cpp

bin/install_travis.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ if [[ "${WITH_SAGE}" != "yes" ]]; then
1212
conda config --set always_yes yes --set changeps1 no;
1313
conda update -q conda;
1414
conda info -a;
15-
CYTHON_VERSION=0.23
16-
if [[ "${PYTHON_VERSION}" == "2.6" ]] || [[ "${PYTHON_VERSION}" == "3.3" ]]; then
17-
CYTHON_VERSION=0.22
18-
fi
19-
CONDA_PKGS="pip cython=${CYTHON_VERSION} sympy nose pytest"
15+
CONDA_PKGS="pip cython sympy nose pytest"
2016
if [[ "${WITH_NUMPY}" == "yes" ]]; then
2117
CONDA_PKGS="${CONDA_PKGS} numpy";
2218
fi

symengine/lib/symengine.pxd

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ cdef extern from "<symengine/symengine_rcp.h>" namespace "SymEngine":
121121
null
122122

123123
cdef cppclass RCP[T]:
124-
T& operator*() nogil except +
124+
T& operator*() nogil
125125
# Not yet supported in Cython:
126126
# RCP[T]& operator=(RCP[T] &r_ptr) nogil except +
127127
void reset() nogil except +
@@ -134,7 +134,6 @@ cdef extern from "<symengine/symengine_rcp.h>" namespace "SymEngine":
134134
RCP[const Rational] rcp_static_cast_Rational "SymEngine::rcp_static_cast<const SymEngine::Rational>"(RCP[const Basic] &b) nogil
135135
RCP[const Complex] rcp_static_cast_Complex "SymEngine::rcp_static_cast<const SymEngine::Complex>"(RCP[const Basic] &b) nogil
136136
RCP[const Number] rcp_static_cast_Number "SymEngine::rcp_static_cast<const SymEngine::Number>"(RCP[const Basic] &b) nogil
137-
const RCP[const Number] rcp_static_cast_Number_Int "SymEngine::rcp_static_cast<const SymEngine::Number>"(RCP[const Integer] &b) nogil
138137
RCP[const Add] rcp_static_cast_Add "SymEngine::rcp_static_cast<const SymEngine::Add>"(RCP[const Basic] &b) nogil
139138
RCP[const Mul] rcp_static_cast_Mul "SymEngine::rcp_static_cast<const SymEngine::Mul>"(RCP[const Basic] &b) nogil
140139
RCP[const Pow] rcp_static_cast_Pow "SymEngine::rcp_static_cast<const SymEngine::Pow>"(RCP[const Basic] &b) nogil
@@ -352,7 +351,7 @@ cdef extern from "<symengine/mul.h>" namespace "SymEngine":
352351
void as_two_terms(const Ptr[RCP[Basic]] &a, const Ptr[RCP[Basic]] &b)
353352
RCP[const Number] get_coef()
354353
const map_basic_basic &get_dict()
355-
cdef RCP[const Mul] mul_from_dict "SymEngine::Mul::from_dict"(const RCP[const Number] &coef, map_basic_basic &&d) nogil
354+
cdef RCP[const Mul] mul_from_dict "SymEngine::Mul::from_dict"(RCP[const Number] coef, map_basic_basic &&d) nogil
356355

357356
cdef extern from "<symengine/pow.h>" namespace "SymEngine":
358357
cdef RCP[const Basic] pow(RCP[const Basic] &a, RCP[const Basic] &b) nogil except+
@@ -375,20 +374,20 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
375374
RCP[const Basic] make_rcp_Constant "SymEngine::make_rcp<const SymEngine::Constant>"(string name) nogil
376375
RCP[const Basic] make_rcp_Integer "SymEngine::make_rcp<const SymEngine::Integer>"(int i) nogil
377376
RCP[const Basic] make_rcp_Integer "SymEngine::make_rcp<const SymEngine::Integer>"(integer_class i) nogil
378-
RCP[const Basic] make_rcp_Subs "SymEngine::make_rcp<const SymEngine::Subs>"(const RCP[const Basic] &arg, const map_basic_basic &x) nogil
379-
RCP[const Basic] make_rcp_Derivative "SymEngine::make_rcp<const SymEngine::Derivative>"(const RCP[const Basic] &arg, const multiset_basic &x) nogil
377+
RCP[const Basic] make_rcp_Subs "SymEngine::make_rcp<const SymEngine::Subs>"(RCP[const Basic] arg, const map_basic_basic &x) nogil
378+
RCP[const Basic] make_rcp_Derivative "SymEngine::make_rcp<const SymEngine::Derivative>"(RCP[const Basic] arg, const multiset_basic &x) nogil
380379
RCP[const Basic] make_rcp_FunctionWrapper "SymEngine::make_rcp<const SymEngine::FunctionWrapper>"(void* obj, string name, string hash_, const vec_basic &arg, \
381380
void (*dec_ref)(void *), int (*comp)(void *, void *)) nogil
382381
RCP[const Basic] make_rcp_RealDouble "SymEngine::make_rcp<const SymEngine::RealDouble>"(double x) nogil
383382
RCP[const Basic] make_rcp_ComplexDouble "SymEngine::make_rcp<const SymEngine::ComplexDouble>"(double complex x) nogil
384383
RCP[const PyModule] make_rcp_PyModule "SymEngine::make_rcp<const SymEngine::PyModule>"(PyObject* (*) (RCP[const Basic] x), \
385384
RCP[const Basic] (*)(PyObject*), RCP[const Number] (*)(PyObject*, long bits),
386385
RCP[const Basic] (*)(PyObject*, RCP[const Basic])) nogil
387-
RCP[const Basic] make_rcp_PyNumber "SymEngine::make_rcp<const SymEngine::PyNumber>"(PyObject*, const RCP[const PyModule] &x) nogil
386+
RCP[const Basic] make_rcp_PyNumber "SymEngine::make_rcp<const SymEngine::PyNumber>"(PyObject*, RCP[const PyModule] x) nogil
388387
RCP[const PyFunctionClass] make_rcp_PyFunctionClass "SymEngine::make_rcp<const SymEngine::PyFunctionClass>"(PyObject* pyobject,
389-
string name, const RCP[const PyModule] &pymodule) nogil
388+
string name, RCP[const PyModule] pymodule) nogil
390389
RCP[const Basic] make_rcp_PyFunction "SymEngine::make_rcp<const SymEngine::PyFunction>" (const vec_basic &vec,
391-
const RCP[const PyFunctionClass] &pyfunc_class, const PyObject* pyobject) nogil
390+
RCP[const PyFunctionClass] pyfunc_class, const PyObject* pyobject) nogil
392391

393392
cdef extern from "<symengine/functions.h>" namespace "SymEngine":
394393
cdef RCP[const Basic] sin(RCP[const Basic] &arg) nogil except+
@@ -579,15 +578,15 @@ cdef extern from "<symengine/matrix.h>" namespace "SymEngine":
579578
const unsigned nrows() nogil
580579
const unsigned ncols() nogil
581580
RCP[const Basic] get(unsigned i, unsigned j) nogil
582-
RCP[const Basic] set(unsigned i, unsigned j, const RCP[const Basic] &e) nogil
581+
RCP[const Basic] set(unsigned i, unsigned j, RCP[const Basic] e) nogil
583582
string __str__() nogil except+
584583
bool eq(const MatrixBase &) nogil
585584
RCP[const Basic] det() nogil
586585
void inv(MatrixBase &)
587586
void add_matrix(const MatrixBase &other, MatrixBase &result) nogil
588587
void mul_matrix(const MatrixBase &other, MatrixBase &result) nogil
589-
void add_scalar(const RCP[const Basic] &k, MatrixBase &result) nogil
590-
void mul_scalar(const RCP[const Basic] &k, MatrixBase &result) nogil
588+
void add_scalar(RCP[const Basic] k, MatrixBase &result) nogil
589+
void mul_scalar(RCP[const Basic] k, MatrixBase &result) nogil
591590
void transpose(MatrixBase &result) nogil
592591
void submatrix(MatrixBase &result,
593592
unsigned row_start, unsigned col_start,
@@ -662,21 +661,21 @@ cdef extern from "<symengine/ntheory.h>" namespace "SymEngine":
662661
RCP[const Number] bernoulli(unsigned long n) nogil except +
663662
bool primitive_root(const Ptr[RCP[Integer]] &g, const Integer &n) nogil
664663
void primitive_root_list(vec_integer &roots, const Integer &n) nogil
665-
RCP[const Integer] totient(const RCP[const Integer] &n) nogil
666-
RCP[const Integer] carmichael(const RCP[const Integer] &n) nogil
667-
bool multiplicative_order(const Ptr[RCP[Integer]] &o, const RCP[const Integer] &a,
668-
const RCP[const Integer] &n) nogil
664+
RCP[const Integer] totient(RCP[const Integer] n) nogil
665+
RCP[const Integer] carmichael(RCP[const Integer] n) nogil
666+
bool multiplicative_order(const Ptr[RCP[Integer]] &o, RCP[const Integer] a,
667+
RCP[const Integer] n) nogil
669668
int legendre(const Integer &a, const Integer &n) nogil
670669
int jacobi(const Integer &a, const Integer &n) nogil
671670
int kronecker(const Integer &a, const Integer &n) nogil
672-
void nthroot_mod_list(vec_integer &roots, const RCP[const Integer] &n,
673-
const RCP[const Integer] &a, const RCP[const Integer] &m) nogil
674-
bool nthroot_mod(const Ptr[RCP[Integer]] &root, const RCP[const Integer] &n,
675-
const RCP[const Integer] &a, const RCP[const Integer] &m) nogil
676-
bool powermod(const Ptr[RCP[Integer]] &powm, const RCP[const Integer] &a,
677-
const RCP[const Number] &b, const RCP[const Integer] &m) nogil
678-
void powermod_list(vec_integer &powm, const RCP[const Integer] &a,
679-
const RCP[const Number] &b, const RCP[const Integer] &m) nogil
671+
void nthroot_mod_list(vec_integer &roots, RCP[const Integer] n,
672+
RCP[const Integer] a, RCP[const Integer] m) nogil
673+
bool nthroot_mod(const Ptr[RCP[Integer]] &root, RCP[const Integer] n,
674+
RCP[const Integer] a, RCP[const Integer] m) nogil
675+
bool powermod(const Ptr[RCP[Integer]] &powm, RCP[const Integer] a,
676+
RCP[const Number] b, RCP[const Integer] m) nogil
677+
void powermod_list(vec_integer &powm, RCP[const Integer] a,
678+
RCP[const Number] b, RCP[const Integer] m) nogil
680679

681680
void sieve_generate_primes "SymEngine::Sieve::generate_primes"(vector[unsigned] &primes, unsigned limit) nogil
682681

symengine/lib/symengine_wrapper.pyx

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ cdef class Mul(Basic):
10261026
cdef map_basic_basic dict = deref(X).get_dict()
10271027
d = collections.defaultdict(int)
10281028
d[c2py(<RCP[const symengine.Basic]>symengine.mul_from_dict(\
1029-
symengine.rcp_static_cast_Number_Int(one),
1029+
<RCP[const symengine.Number]>(one),
10301030
symengine.std_move_map_basic_basic(dict)))] =\
10311031
c2py(<RCP[const symengine.Basic]>deref(X).get_coef())
10321032
return d
@@ -1196,7 +1196,7 @@ cdef class PyNumber(Number):
11961196
if obj is None:
11971197
return
11981198
Py_XINCREF(<PyObject*>(obj))
1199-
self.thisptr = symengine.make_rcp_PyNumber(<PyObject*>(obj), <const RCP[const symengine.PyModule]>module.thisptr)
1199+
self.thisptr = symengine.make_rcp_PyNumber(<PyObject*>(obj), module.thisptr)
12001200

12011201
def _sympy_(self):
12021202
import sympy
@@ -1223,7 +1223,7 @@ cdef class PyFunction(FunctionSymbol):
12231223
cdef PyFunctionClass _pyfunction_class = get_function_class(pyfunction_class, module)
12241224
cdef PyObject* _pyfunction = <PyObject*>pyfunction
12251225
Py_XINCREF(_pyfunction)
1226-
self.thisptr = symengine.make_rcp_PyFunction(v, <const RCP[const symengine.PyFunctionClass]>(_pyfunction_class.thisptr), _pyfunction)
1226+
self.thisptr = symengine.make_rcp_PyFunction(v, _pyfunction_class.thisptr, _pyfunction)
12271227

12281228
def _sympy_(self):
12291229
import sympy
@@ -1240,7 +1240,7 @@ cdef class PyFunctionClass(object):
12401240

12411241
def __cinit__(self, function, PyModule module not None):
12421242
self.thisptr = symengine.make_rcp_PyFunctionClass(<PyObject*>(function), str(function).encode("utf-8"),
1243-
<const RCP[const symengine.PyModule]>module.thisptr)
1243+
module.thisptr)
12441244

12451245
# TODO: remove this once SymEngine conversions are available in Sage.
12461246
def wrap_sage_function(func):
@@ -1288,7 +1288,7 @@ cdef class Derivative(Basic):
12881288
for s in symbols:
12891289
s_ = sympify(s, True)
12901290
m.insert(<RCP[symengine.const_Basic]>(s_.thisptr))
1291-
self.thisptr = symengine.make_rcp_Derivative(<const RCP[const symengine.Basic]>expr_.thisptr, m)
1291+
self.thisptr = symengine.make_rcp_Derivative(expr_.thisptr, m)
12921292

12931293
def _sympy_(self):
12941294
cdef RCP[const symengine.Derivative] X = \
@@ -1324,7 +1324,7 @@ cdef class Subs(Basic):
13241324
v_ = sympify(v, True)
13251325
p_ = sympify(p, True)
13261326
m[v_.thisptr] = p_.thisptr
1327-
self.thisptr = symengine.make_rcp_Subs(<const RCP[const symengine.Basic]>expr_.thisptr, m)
1327+
self.thisptr = symengine.make_rcp_Subs(expr_.thisptr, m)
13281328

13291329
def _sympy_(self):
13301330
cdef RCP[const symengine.Subs] X = symengine.rcp_static_cast_Subs(self.thisptr)
@@ -1664,7 +1664,7 @@ cdef class DenseMatrix(MatrixBase):
16641664
# No error checking is done
16651665
cdef Basic e_ = sympify(e)
16661666
if e_ is not None:
1667-
deref(self.thisptr).set(i, j, <const RCP[const symengine.Basic] &>(e_.thisptr))
1667+
deref(self.thisptr).set(i, j, e_.thisptr)
16681668

16691669
def det(self):
16701670
if self.nrows() != self.ncols():
@@ -1702,13 +1702,13 @@ cdef class DenseMatrix(MatrixBase):
17021702
def add_scalar(self, k):
17031703
cdef Basic k_ = sympify(k)
17041704
result = DenseMatrix(self.nrows(), self.ncols())
1705-
deref(self.thisptr).add_scalar(<const RCP[const symengine.Basic] &>(k_.thisptr), deref(result.thisptr))
1705+
deref(self.thisptr).add_scalar(k_.thisptr, deref(result.thisptr))
17061706
return result
17071707

17081708
def mul_scalar(self, k):
17091709
cdef Basic k_ = sympify(k)
17101710
result = DenseMatrix(self.nrows(), self.ncols())
1711-
deref(self.thisptr).mul_scalar(<const RCP[const symengine.Basic] &>(k_.thisptr), deref(result.thisptr))
1711+
deref(self.thisptr).mul_scalar(k_.thisptr, deref(result.thisptr))
17121712
return result
17131713

17141714
def transpose(self):
@@ -2392,12 +2392,12 @@ def primitive_root_list(n):
23922392
def totient(n):
23932393
cdef Integer _n = sympify(n)
23942394
cdef RCP[const symengine.Integer] m = symengine.rcp_static_cast_Integer(_n.thisptr)
2395-
return c2py(<RCP[const symengine.Basic]>symengine.totient(<const RCP[const symengine.Integer]>m))
2395+
return c2py(<RCP[const symengine.Basic]>symengine.totient(m))
23962396

23972397
def carmichael(n):
23982398
cdef Integer _n = sympify(n)
23992399
cdef RCP[const symengine.Integer] m = symengine.rcp_static_cast_Integer(_n.thisptr)
2400-
return c2py(<RCP[const symengine.Basic]>symengine.carmichael(<const RCP[const symengine.Integer]>m))
2400+
return c2py(<RCP[const symengine.Basic]>symengine.carmichael(m))
24012401

24022402
def multiplicative_order(a, n):
24032403
cdef Integer _n = sympify(n)
@@ -2406,7 +2406,7 @@ def multiplicative_order(a, n):
24062406
cdef RCP[const symengine.Integer] a1 = symengine.rcp_static_cast_Integer(_a.thisptr)
24072407
cdef RCP[const symengine.Integer] o
24082408
cdef bool c = symengine.multiplicative_order(symengine.outArg_Integer(o),
2409-
<const RCP[const symengine.Integer]>a1, <const RCP[const symengine.Integer]>n1)
2409+
a1, n1)
24102410
if not c:
24112411
return None
24122412
return c2py(<RCP[const symengine.Basic]>o)
@@ -2437,9 +2437,7 @@ def nthroot_mod(a, n, m):
24372437
cdef RCP[const symengine.Integer] n1 = symengine.rcp_static_cast_Integer(_n.thisptr)
24382438
cdef RCP[const symengine.Integer] a1 = symengine.rcp_static_cast_Integer(_a.thisptr)
24392439
cdef RCP[const symengine.Integer] m1 = symengine.rcp_static_cast_Integer(_m.thisptr)
2440-
cdef bool ret_val = symengine.nthroot_mod(symengine.outArg_Integer(root),
2441-
<const RCP[const symengine.Integer]>a1, <const RCP[const symengine.Integer]>n1,
2442-
<const RCP[const symengine.Integer]>m1)
2440+
cdef bool ret_val = symengine.nthroot_mod(symengine.outArg_Integer(root), a1, n1, m1)
24432441
if not ret_val:
24442442
return None
24452443
return c2py(<RCP[const symengine.Basic]>root)
@@ -2452,8 +2450,7 @@ def nthroot_mod_list(a, n, m):
24522450
cdef RCP[const symengine.Integer] n1 = symengine.rcp_static_cast_Integer(_n.thisptr)
24532451
cdef RCP[const symengine.Integer] a1 = symengine.rcp_static_cast_Integer(_a.thisptr)
24542452
cdef RCP[const symengine.Integer] m1 = symengine.rcp_static_cast_Integer(_m.thisptr)
2455-
symengine.nthroot_mod_list(root_list, <const RCP[const symengine.Integer]>a1,
2456-
<const RCP[const symengine.Integer]>n1, <const RCP[const symengine.Integer]>m1)
2453+
symengine.nthroot_mod_list(root_list, a1, n1, m1)
24572454
s = []
24582455
for i in range(root_list.size()):
24592456
s.append(c2py(<RCP[const symengine.Basic]>(root_list[i])))
@@ -2468,9 +2465,7 @@ def powermod(a, b, m):
24682465
cdef RCP[const symengine.Number] b1 = symengine.rcp_static_cast_Number(_b.thisptr)
24692466
cdef RCP[const symengine.Integer] root
24702467

2471-
cdef bool ret_val = symengine.powermod(symengine.outArg_Integer(root),
2472-
<const RCP[const symengine.Integer]>a1, <const RCP[const symengine.Number]>b1,
2473-
<const RCP[const symengine.Integer]>m1)
2468+
cdef bool ret_val = symengine.powermod(symengine.outArg_Integer(root), a1, b1, m1)
24742469
if ret_val == 0:
24752470
return None
24762471
return c2py(<RCP[const symengine.Basic]>root)
@@ -2484,9 +2479,7 @@ def powermod_list(a, b, m):
24842479
cdef RCP[const symengine.Number] b1 = symengine.rcp_static_cast_Number(_b.thisptr)
24852480
cdef symengine.vec_integer v
24862481

2487-
symengine.powermod_list(v,
2488-
<const RCP[const symengine.Integer]>a1, <const RCP[const symengine.Number]>b1,
2489-
<const RCP[const symengine.Integer]>m1)
2482+
symengine.powermod_list(v, a1, b1, m1)
24902483
s = []
24912484
for i in range(v.size()):
24922485
s.append(c2py(<RCP[const symengine.Basic]>(v[i])))
@@ -2545,8 +2538,8 @@ def with_buffer(iterable, real=True):
25452538
try:
25462539
real_view = iterable
25472540
except (ValueError, TypeError):
2548-
real_view = cython.view.array(shape=(_size(iterable),),
2549-
itemsize=sizeof(double), format='d')
2541+
real_view = cython.view.array((_size(iterable),),
2542+
sizeof(double), format='d')
25502543
for i in range(_size(iterable)):
25512544
real_view[i] = iterable[i]
25522545
return real_view
@@ -2556,8 +2549,8 @@ def with_buffer(iterable, real=True):
25562549
try:
25572550
cmplx_view = iterable
25582551
except (ValueError, TypeError):
2559-
cmplx_view = cython.view.array(shape=(_size(iterable),),
2560-
itemsize=sizeof(double complex), format='Zd')
2552+
cmplx_view = cython.view.array((_size(iterable),),
2553+
sizeof(double complex), format='Zd')
25612554
for i in range(_size(iterable)):
25622555
cmplx_view[i] = iterable[i]
25632556
return cmplx_view
@@ -2762,11 +2755,11 @@ cdef class Lambdify(object):
27622755
self.real else np.complex128)
27632756
else:
27642757
if self.real:
2765-
out = cython.view.array(shape=(new_out_size,),
2766-
itemsize=sizeof(double), format='d')
2758+
out = cython.view.array((new_out_size,),
2759+
sizeof(double), format='d')
27672760
else:
2768-
out = cython.view.array(shape=(new_out_size,),
2769-
itemsize=sizeof(double complex), format='Zd')
2761+
out = cython.view.array((new_out_size,),
2762+
sizeof(double complex), format='Zd')
27702763
reshape_out = len(new_out_shape) > 1
27712764
else:
27722765
if use_numpy:
@@ -2812,15 +2805,15 @@ cdef class Lambdify(object):
28122805
out = out.reshape(new_out_shape)
28132806
elif reshape_out:
28142807
if self.real:
2815-
tmp = cython.view.array(shape=new_out_shape,
2816-
itemsize=sizeof(double), format='d')
2808+
tmp = cython.view.array(new_out_shape,
2809+
sizeof(double), format='d')
28172810
real_out_view = out
28182811
memcpy(<double *>tmp.data, &real_out_view[0],
28192812
sizeof(double)*new_out_size)
28202813
out = tmp
28212814
else:
2822-
tmp = cython.view.array(shape=new_out_shape,
2823-
itemsize=sizeof(double complex), format='Zd')
2815+
tmp = cython.view.array(new_out_shape,
2816+
sizeof(double complex), format='Zd')
28242817
cmplx_out_view = tmp
28252818
memcpy(<double complex*>tmp.data, &cmplx_out_view[0],
28262819
sizeof(double complex)*new_out_size)

0 commit comments

Comments
 (0)