Skip to content

Commit 88c026d

Browse files
authored
Merge branch 'master' into python
2 parents ae1d8f7 + 5ed8c0b commit 88c026d

13 files changed

+86
-41
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ build*
2929
MANIFEST
3030
*.egg-info
3131
dist/
32-
.cache/
32+
.*cache/
3333
symengine.egg-info/
3434

3535
# Temp files

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ See License section for information about wheels
2323

2424
conda install python-symengine -c symengine -c conda-forge
2525

26+
optionally, you may choose to install an early [developer preview](https://github.com/symengine/python-symengine-feedstock):
27+
28+
conda install python-symengine -c symengine/label/dev -c conda-forge
29+
2630
### Build from source
2731

2832
Install prerequisites.
2933

3034
CMake >= 2.8.7
31-
Python2 >= 2.7 or Python3 >= 3.3
35+
Python2 >= 2.7 or Python3 >= 3.4
3236
Cython >= 0.19.1
3337
SymEngine >= 0.2.0
3438

symengine/__init__.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
from .lib.symengine_wrapper import (Symbol, S, sympify,
2-
SympifyError, Add, Mul, Pow, function_symbol, I, E, pi, oo,
3-
zoo, nan, have_mpfr, have_mpc, have_flint, have_piranha,
4-
have_llvm, Integer, Rational, Float, Number, RealNumber,
5-
RealDouble, ComplexDouble, Max, Min, DenseMatrix, Matrix,
6-
ImmutableMatrix, ImmutableDenseMatrix, MutableDenseMatrix,
7-
MatrixBase, Basic, DictBasic, symarray, series, diff, zeros,
8-
eye, diag, ones, Derivative, Subs, add, expand, has_symbol,
9-
UndefFunction, Function, FunctionSymbol as AppliedUndef,
10-
have_numpy, true, false, Equality, Unequality, GreaterThan,
11-
LessThan, StrictGreaterThan, StrictLessThan, Eq, Ne, Ge, Le,
12-
Gt, Lt, golden_ratio as GoldenRatio, catalan as Catalan,
13-
eulergamma as EulerGamma, Dummy, perfect_power, integer_nthroot,
14-
isprime, sqrt_mod, Expr, cse, count_ops)
1+
from .lib.symengine_wrapper import (
2+
have_mpfr, have_mpc, have_flint, have_piranha, have_llvm,
3+
I, E, pi, oo, zoo, nan, Symbol, Dummy, S, sympify, SympifyError,
4+
Integer, Rational, Float, Number, RealNumber, RealDouble, ComplexDouble,
5+
add, Add, Mul, Pow, function_symbol,
6+
Max, Min, DenseMatrix, Matrix,
7+
ImmutableMatrix, ImmutableDenseMatrix, MutableDenseMatrix,
8+
MatrixBase, Basic, DictBasic, symarray, series, diff, zeros,
9+
eye, diag, ones, Derivative, Subs, expand, has_symbol,
10+
UndefFunction, Function,
11+
have_numpy, true, false, Equality, Unequality, GreaterThan,
12+
LessThan, StrictGreaterThan, StrictLessThan, Eq, Ne, Ge, Le,
13+
Gt, Lt, And, Or, Not, Nand, Nor, Xor, Xnor, perfect_power, integer_nthroot,
14+
isprime, sqrt_mod, Expr, cse, count_ops, ccode, Piecewise, Contains, Interval, FiniteSet,
15+
FunctionSymbol as AppliedUndef,
16+
golden_ratio as GoldenRatio,
17+
catalan as Catalan,
18+
eulergamma as EulerGamma
19+
)
1520
from .utilities import var, symbols
1621
from .functions import *
1722

symengine/lib/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ install(FILES __init__.py
3232
${CMAKE_CURRENT_BINARY_DIR}/config.pxi
3333
symengine.pxd
3434
symengine_wrapper.pxd
35-
DESTINATION ${PY_PATH}
36-
)
37-
38-
install(FILES
3935
pywrapper.h
40-
DESTINATION ${PYTHON_INSTALL_PATH}/symengine/lib
36+
DESTINATION ${PY_PATH}
4137
)

symengine/lib/symengine_wrapper.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cdef object c2py(rcp_const_basic o):
6363
elif (symengine.is_a_Symbol(deref(o))):
6464
if (symengine.is_a_PySymbol(deref(o))):
6565
return <object>(deref(symengine.rcp_static_cast_PySymbol(o)).get_py_object())
66-
r = Expr.__new__(Symbol)
66+
r = Symbol.__new__(Symbol)
6767
elif (symengine.is_a_Constant(deref(o))):
6868
r = S.Pi
6969
if (symengine.eq(deref(o), deref(r.thisptr))):
@@ -1110,7 +1110,7 @@ cdef class Expr(Basic):
11101110
pass
11111111

11121112

1113-
class Symbol(Expr):
1113+
cdef class Symbol(Expr):
11141114

11151115
"""
11161116
Symbol is a class to store a symbolic variable with a given name.
@@ -1155,7 +1155,7 @@ class Symbol(Expr):
11551155
return self.__class__
11561156

11571157

1158-
class Dummy(Symbol):
1158+
cdef class Dummy(Symbol):
11591159

11601160
def __init__(Basic self, name=None, *args, **kwargs):
11611161
if name is None:
@@ -3164,7 +3164,7 @@ cdef class DenseMatrixBase(MatrixBase):
31643164
row_iter = [item[0]]
31653165

31663166
if isinstance(item[1], slice):
3167-
col_iter = range(*item[1].indices(self.rows))
3167+
col_iter = range(*item[1].indices(self.cols))
31683168
elif is_sequence(item[1]):
31693169
col_iter = item[1]
31703170
else:
@@ -3213,7 +3213,7 @@ cdef class DenseMatrixBase(MatrixBase):
32133213
row_iter = [key[0]]
32143214

32153215
if isinstance(key[1], slice):
3216-
col_iter = range(*key[1].indices(self.rows))
3216+
col_iter = range(*key[1].indices(self.cols))
32173217
elif is_sequence(key[1]):
32183218
col_iter = key[1]
32193219
else:

symengine/tests/test_functions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from symengine import (Symbol, sin, cos, sqrt, Add, Mul, function_symbol, Integer, log, E, symbols, I,
2-
Rational, EulerGamma, Function)
3-
from symengine.lib.symengine_wrapper import (Subs, Derivative, LambertW, zeta, dirichlet_eta,
4-
zoo, pi, KroneckerDelta, LeviCivita, erf, erfc,
5-
oo, lowergamma, uppergamma, exp, loggamma, beta,
6-
polygamma, digamma, trigamma, sign, floor, ceiling,
7-
conjugate, nan, Float)
1+
from symengine import (
2+
Symbol, sin, cos, sqrt, Add, Mul, function_symbol, Integer, log, E, symbols, I,
3+
Rational, EulerGamma, Function, Subs, Derivative, LambertW, zeta, dirichlet_eta,
4+
zoo, pi, KroneckerDelta, LeviCivita, erf, erfc, oo, lowergamma, uppergamma, exp,
5+
loggamma, beta, polygamma, digamma, trigamma, sign, floor, ceiling, conjugate,
6+
nan, Float
7+
)
88

99
import unittest
1010

symengine/tests/test_lambdify.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def test_Lambdify():
7676
[3*n+3, n**2, -1/(n+2), n*(n+1)*(n+2)])
7777

7878

79+
@unittest.skipUnless(have_numpy, "Numpy not installed")
80+
def test_Lambdify_Piecewise():
81+
x = se.symbols('x')
82+
p = se.Piecewise((-x, x<0), (x*x*x, True))
83+
f = se.Lambdify([x], [p])
84+
arr = np.linspace(3, 7)
85+
assert np.allclose(f(-arr).flat, arr, atol=1e-14, rtol=1e-15)
86+
assert np.allclose(f(arr).flat, arr**3, atol=1e-14, rtol=1e-15)
87+
88+
7989
@unittest.skipUnless(have_numpy, "Numpy not installed")
8090
def test_Lambdify_LLVM():
8191
n = 7

symengine/tests/test_matrices.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ def test_get_item():
7373
raises(IndexError, lambda: A[1:3, 3])
7474
raises(IndexError, lambda: A[1:3, -4])
7575

76+
A = zeros(3, 4)
77+
assert list(A[0, :]) == [0, 0, 0, 0]
78+
assert list(A[:, 0]) == [0, 0, 0]
79+
80+
A = zeros(4, 3)
81+
assert list(A[:, 0]) == [0, 0, 0, 0]
82+
assert list(A[0, :]) == [0, 0, 0]
83+
7684

7785
def test_set_item():
7886
A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
@@ -129,6 +137,16 @@ def test_set_item():
129137
B[[0, 1], [0, 2]] = -1
130138
assert B == DenseMatrix(3, 3, [-1, 2, -1, -1, 14, -1, 4, 5, 6])
131139

140+
A = zeros(3, 4)
141+
B = ones(1, 4)
142+
A[0, :] = B
143+
assert A[0, :] == B
144+
145+
A = zeros(3, 4)
146+
B = ones(3, 1)
147+
A[:, 0] = B
148+
assert A[:, 0] == B
149+
132150

133151
def test_set():
134152
i7 = Integer(7)

symengine/tests/test_printing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
from symengine import (ccode, Symbol, sqrt, Pow, Max, sin, Integer, MutableDenseMatrix)
12
from symengine.utilities import raises
2-
from symengine.lib.symengine_wrapper import (ccode, Symbol, sqrt, Pow, Max, sin, Integer, MutableDenseMatrix)
33
from symengine.printing import CCodePrinter
44

55
def test_ccode():
@@ -24,4 +24,3 @@ def test_CCodePrinter():
2424
assert myprinter.doprint(MutableDenseMatrix(1, 2, [x, y]), "larry") == "larry[0] = x;\nlarry[1] = y;"
2525
raises(TypeError, lambda: myprinter.doprint(sin(x), Integer))
2626
raises(RuntimeError, lambda: myprinter.doprint(MutableDenseMatrix(1, 2, [x, y])))
27-

symengine/tests/test_symbol.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ def test_symbol():
88
assert str(x) == "x"
99
assert str(x) != "y"
1010
assert repr(x) == str(x)
11+
# Verify the successful use of slots.
12+
assert not hasattr(x, "__dict__")
13+
assert not hasattr(x, "__weakref__")
1114

1215

1316
def test_symbols():
@@ -148,6 +151,7 @@ def test_has_symbol():
148151
assert not has_symbol(c, a)
149152
assert has_symbol(a+b, b)
150153

154+
151155
def test_dummy():
152156
x1 = Symbol('x')
153157
x2 = Symbol('x')
@@ -159,3 +163,6 @@ def test_dummy():
159163
assert xdummy1 != xdummy2
160164
assert Dummy() != Dummy()
161165
assert Dummy('x') != Dummy('x')
166+
# Verify the successful use of slots.
167+
assert not hasattr(xdummy1, "__dict__")
168+
assert not hasattr(xdummy1, "__weakref__")

0 commit comments

Comments
 (0)