Skip to content

Commit a3e9f87

Browse files
authored
Merge branch 'master' into posdef
2 parents 96f3b4f + db5ea46 commit a3e9f87

File tree

8 files changed

+64
-7
lines changed

8 files changed

+64
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ symengine.egg-info/
4040
genDocs/
4141
docs/_build/
4242
docs/source/
43+
symengine/lib/version_script_symengine_wrapper.txt

bin/test_travis.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ set -e
66
set -x
77

88
# Build inplace so that nosetests can be run inside source directory
9-
python setup.py install build_ext --inplace --symengine-dir=$our_install_dir
9+
python3 setup.py install build_ext --inplace --symengine-dir=$our_install_dir
1010

1111
# Test python wrappers
12-
py.test -s -v $PYTHON_SOURCE_DIR/symengine/tests/test_*.py
12+
python3 -m pip install pytest
13+
python3 -m pytest -s -v $PYTHON_SOURCE_DIR/symengine/tests/test_*.py
1314
mkdir -p empty && cd empty
14-
python $PYTHON_SOURCE_DIR/bin/test_python.py
15+
python3 $PYTHON_SOURCE_DIR/bin/test_python.py
1516
cd ..
1617

1718
if [[ "${TRIGGER_FEEDSTOCK}" == "yes" ]]; then

symengine/lib/symengine.pxd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ cdef extern from "<symengine/matrix.h>" namespace "SymEngine":
835835
DenseMatrix* static_cast_DenseMatrix "static_cast<SymEngine::DenseMatrix*>"(const MatrixBase *a)
836836
void inverse_FFLU "SymEngine::inverse_fraction_free_LU"(const DenseMatrix &A,
837837
DenseMatrix &B) nogil except +
838-
void pivoted_LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U, vector[int] &P) nogil except +
839838
void pivoted_LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x) nogil except +
840839
void inverse_GJ "SymEngine::inverse_gauss_jordan"(const DenseMatrix &A,
841840
DenseMatrix &B) nogil except +
@@ -860,6 +859,9 @@ cdef extern from "<symengine/matrix.h>" namespace "SymEngine":
860859
void dot(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C) nogil
861860
void cross(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C) nogil
862861

862+
cdef extern from "<symengine/matrix.h>":
863+
void pivoted_LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U, vector[pair[int, int]] &P) nogil except +
864+
863865
cdef extern from "<symengine/ntheory.h>" namespace "SymEngine":
864866
int probab_prime_p(const Integer &a, int reps)
865867
RCP[const Integer] nextprime (const Integer &a) nogil
@@ -911,6 +913,7 @@ cdef extern from "<symengine/ntheory.h>" namespace "SymEngine":
911913
void powermod_list(vec_integer &powm, RCP[const Integer] a,
912914
RCP[const Number] b, RCP[const Integer] m) nogil
913915

916+
cdef extern from "<symengine/prime_sieve.h>" namespace "SymEngine":
914917
void sieve_generate_primes "SymEngine::Sieve::generate_primes"(vector[unsigned] &primes, unsigned limit) nogil
915918

916919
cdef cppclass sieve_iterator "SymEngine::Sieve::iterator":

symengine/lib/symengine_wrapper.pyx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ def _sympify(a, raise_error=True):
562562
return Integer(a)
563563
elif isinstance(a, float):
564564
return RealDouble(a)
565+
elif have_numpy and isinstance(a, (np.float16, np.float32)):
566+
return RealDouble(a)
565567
elif isinstance(a, complex):
566568
return ComplexDouble(a)
567569
elif hasattr(a, '_symengine_'):
@@ -3192,7 +3194,7 @@ cdef class DenseMatrixBase(MatrixBase):
31923194
self.thisptr = new symengine.DenseMatrix(row, col)
31933195
return
31943196
if col is None:
3195-
v = row
3197+
v = sympify(row)
31963198
row = 0
31973199
cdef symengine.vec_basic v_
31983200
cdef DenseMatrixBase A
@@ -3706,6 +3708,17 @@ cdef class DenseMatrixBase(MatrixBase):
37063708
deref(self.thisptr).LU(deref(L.thisptr), deref(U.thisptr))
37073709
return L, U
37083710

3711+
def LUdecomposition(self):
3712+
cdef DenseMatrixBase L = self.__class__(self.nrows(), self.ncols())
3713+
cdef DenseMatrixBase U = self.__class__(self.nrows(), self.ncols())
3714+
cdef vector[pair[int, int]] perm
3715+
symengine.pivoted_LU(
3716+
deref(symengine.static_cast_DenseMatrix(self.thisptr)),
3717+
deref(symengine.static_cast_DenseMatrix(L.thisptr)),
3718+
deref(symengine.static_cast_DenseMatrix(U.thisptr)),
3719+
perm)
3720+
return L, U, perm
3721+
37093722
def LDL(self):
37103723
cdef DenseMatrixBase L = self.__class__(self.nrows(), self.ncols())
37113724
cdef DenseMatrixBase D = self.__class__(self.nrows(), self.ncols())

symengine/tests/test_matrices.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,15 @@ def test_atoms():
699699
b = Symbol("b")
700700
X = DenseMatrix([[a, 2], [b, 4]])
701701
assert X.atoms(Symbol) == set([a, b])
702+
703+
704+
def test_LUdecomp():
705+
testmat = DenseMatrix([[0, 2, 5, 3],
706+
[3, 3, 7, 4],
707+
[8, 4, 0, 2],
708+
[-2, 6, 3, 4]])
709+
L, U, p = testmat.LUdecomposition()
710+
res = L*U
711+
for orig, new in p:
712+
res.row_swap(orig, new)
713+
assert res - testmat == zeros(4)

symengine/tests/test_subs.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import unittest
2+
13
from symengine.utilities import raises
2-
from symengine import Symbol, sin, cos, sqrt, Add, function_symbol
4+
from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy
35

46

57
def test_basic():
@@ -56,3 +58,19 @@ def test_xreplace():
5658
y = Symbol("y")
5759
f = sin(cos(x))
5860
assert f.xreplace({x: y}) == sin(cos(y))
61+
62+
63+
@unittest.skipUnless(have_numpy, "Numpy not installed")
64+
def test_float32():
65+
import numpy as np
66+
x = Symbol("x")
67+
expr = x * 2
68+
assert expr.subs({x: np.float32(2)}) == 4.0
69+
70+
71+
@unittest.skipUnless(have_numpy, "Numpy not installed")
72+
def test_float16():
73+
import numpy as np
74+
x = Symbol("x")
75+
expr = x * 2
76+
assert expr.subs({x: np.float16(2)}) == 4.0

symengine/tests/test_sympy_conv.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,12 @@ def test_pynumber():
786786

787787
b = b / x
788788
assert isinstance(b, PyNumber)
789+
790+
791+
@unittest.skipIf(not have_sympy, "SymPy not installed")
792+
def test_construct_dense_matrix():
793+
# Test for issue #347
794+
A = sympy.Matrix([[1, 2], [3, 5]])
795+
B = DenseMatrix(A)
796+
assert B.shape == (2, 2)
797+
assert list(B) == [1, 2, 3, 5]

symengine_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.7.0
1+
bb386f47369500d76cda07e6e9f014bfe6339f64

0 commit comments

Comments
 (0)