symengine 0.9.2__cp38-cp38-win_amd64.whl → 0.11.0__cp38-cp38-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- symengine/lib/{flint-16.dll → flint-17.dll} +0 -0
- symengine/lib/mpc.dll +0 -0
- symengine/lib/mpfr.dll +0 -0
- symengine/lib/pywrapper.h +22 -5
- symengine/lib/symengine.pxd +274 -432
- symengine/lib/symengine_wrapper.cp38-win_amd64.lib +0 -0
- symengine/lib/symengine_wrapper.cp38-win_amd64.pyd +0 -0
- symengine/lib/symengine_wrapper.pxd +77 -86
- symengine/lib/zlib.dll +0 -0
- symengine/lib/zstd.dll +0 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/__init__.py +9 -3
- {symengine → symengine-0.11.0.data/purelib/symengine}/printing.py +3 -3
- symengine-0.11.0.data/purelib/symengine/test_utilities.py +95 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_arit.py +21 -10
- symengine-0.11.0.data/purelib/symengine/tests/test_cse.py +17 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_dict_basic.py +4 -4
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_eval.py +2 -2
- symengine-0.11.0.data/purelib/symengine/tests/test_expr.py +28 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_functions.py +2 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_lambdify.py +1 -6
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_logic.py +4 -2
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_matrices.py +22 -10
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_ntheory.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_number.py +1 -1
- symengine-0.11.0.data/purelib/symengine/tests/test_pickling.py +59 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_printing.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_series_expansion.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sets.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_solve.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_subs.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_symbol.py +5 -5
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympify.py +2 -2
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympy_compat.py +2 -2
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympy_conv.py +40 -3
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_var.py +1 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/utilities.py +0 -93
- {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/AUTHORS +1 -0
- {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/METADATA +31 -33
- symengine-0.11.0.dist-info/RECORD +49 -0
- {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/WHEEL +1 -1
- symengine-0.11.0.dist-info/top_level.txt +1 -0
- symengine/__pycache__/__init__.cpython-38.pyc +0 -0
- symengine/__pycache__/functions.cpython-38.pyc +0 -0
- symengine/__pycache__/printing.cpython-38.pyc +0 -0
- symengine/__pycache__/sympy_compat.cpython-38.pyc +0 -0
- symengine/__pycache__/utilities.cpython-38.pyc +0 -0
- symengine/lib/__pycache__/__init__.cpython-38.pyc +0 -0
- symengine/lib/config.pxi +0 -6
- symengine/tests/__pycache__/__init__.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_arit.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_dict_basic.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_eval.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_expr.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_functions.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_lambdify.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_logic.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_matrices.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_ntheory.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_number.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_printing.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_sage.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_series_expansion.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_sets.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_solve.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_subs.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_symbol.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_sympify.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_sympy_compat.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_sympy_conv.cpython-38.pyc +0 -0
- symengine/tests/__pycache__/test_var.cpython-38.pyc +0 -0
- symengine/tests/test_expr.py +0 -14
- symengine-0.9.2.dist-info/RECORD +0 -74
- symengine-0.9.2.dist-info/top_level.txt +0 -1
- {symengine → symengine-0.11.0.data/purelib/symengine}/functions.py +0 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/lib/__init__.py +0 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/sympy_compat.py +0 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/__init__.py +0 -0
- {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sage.py +0 -0
- {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/LICENSE +0 -0
Binary file
|
Binary file
|
@@ -1,86 +1,77 @@
|
|
1
|
-
#cython: language_level=3
|
2
|
-
|
3
|
-
cimport symengine
|
4
|
-
from symengine cimport RCP, map_basic_basic, rcp_const_basic
|
5
|
-
from libcpp.vector cimport vector
|
6
|
-
from libcpp.string cimport string
|
7
|
-
from libcpp cimport bool as cppbool
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
cdef
|
27
|
-
cdef map_basic_basic.iterator begin
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
cdef
|
32
|
-
|
33
|
-
cdef
|
34
|
-
cdef
|
35
|
-
cdef
|
36
|
-
cdef
|
37
|
-
cdef
|
38
|
-
cdef
|
39
|
-
|
40
|
-
cdef
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
cpdef
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
cdef
|
49
|
-
|
50
|
-
|
51
|
-
cpdef
|
52
|
-
cpdef
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
cdef
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
cdef
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
cdef
|
76
|
-
|
77
|
-
|
78
|
-
cdef _load(self, const string &s)
|
79
|
-
cpdef unsafe_real(self, float[::1] inp, float[::1] out, int inp_offset=*, int out_offset=*)
|
80
|
-
|
81
|
-
IF HAVE_SYMENGINE_LLVM_LONG_DOUBLE:
|
82
|
-
cdef class LLVMLongDouble(_LLVMLambdify):
|
83
|
-
cdef vector[symengine.LLVMLongDoubleVisitor] lambda_double
|
84
|
-
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
85
|
-
cdef _load(self, const string &s)
|
86
|
-
cpdef unsafe_real(self, long double[::1] inp, long double[::1] out, int inp_offset=*, int out_offset=*)
|
1
|
+
#cython: language_level=3
|
2
|
+
|
3
|
+
cimport symengine
|
4
|
+
from symengine cimport RCP, map_basic_basic, rcp_const_basic
|
5
|
+
from libcpp.vector cimport vector
|
6
|
+
from libcpp.string cimport string
|
7
|
+
from libcpp cimport bool as cppbool
|
8
|
+
|
9
|
+
cdef class Basic(object):
|
10
|
+
cdef rcp_const_basic thisptr
|
11
|
+
|
12
|
+
cdef class MatrixBase(object):
|
13
|
+
cdef symengine.MatrixBase* thisptr
|
14
|
+
|
15
|
+
cdef class PyFunctionClass(object):
|
16
|
+
cdef RCP[const symengine.PyFunctionClass] thisptr
|
17
|
+
|
18
|
+
cdef class PyModule(object):
|
19
|
+
cdef RCP[const symengine.PyModule] thisptr
|
20
|
+
|
21
|
+
cdef class _DictBasic(object):
|
22
|
+
cdef map_basic_basic c
|
23
|
+
|
24
|
+
cdef class DictBasicIter(object):
|
25
|
+
cdef map_basic_basic.iterator begin
|
26
|
+
cdef map_basic_basic.iterator end
|
27
|
+
cdef init(self, map_basic_basic.iterator begin, map_basic_basic.iterator end)
|
28
|
+
|
29
|
+
cdef object c2py(rcp_const_basic o)
|
30
|
+
|
31
|
+
cdef class _Lambdify(object):
|
32
|
+
cdef size_t args_size, tot_out_size
|
33
|
+
cdef list out_shapes
|
34
|
+
cdef readonly bint real
|
35
|
+
cdef readonly size_t n_exprs
|
36
|
+
cdef public str order
|
37
|
+
cdef vector[int] accum_out_sizes
|
38
|
+
cdef object numpy_dtype
|
39
|
+
|
40
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
41
|
+
cdef _load(self, const string &s)
|
42
|
+
cpdef eval_real(self, inp, out)
|
43
|
+
cpdef eval_complex(self, inp, out)
|
44
|
+
cpdef unsafe_eval(sef, inp, out, unsigned nbroadcast=*)
|
45
|
+
|
46
|
+
cdef class LambdaDouble(_Lambdify):
|
47
|
+
cdef vector[symengine.LambdaRealDoubleVisitor] lambda_double
|
48
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
49
|
+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
|
50
|
+
cpdef as_scipy_low_level_callable(self)
|
51
|
+
cpdef as_ctypes(self)
|
52
|
+
cpdef unsafe_real(self,
|
53
|
+
double[::1] inp, double[::1] out,
|
54
|
+
int inp_offset=*, int out_offset=*)
|
55
|
+
|
56
|
+
cdef class LambdaComplexDouble(_Lambdify):
|
57
|
+
cdef vector[symengine.LambdaComplexDoubleVisitor] lambda_double
|
58
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
59
|
+
cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out, int inp_offset=*, int out_offset=*)
|
60
|
+
|
61
|
+
cdef class _LLVMLambdify(_Lambdify):
|
62
|
+
cdef int opt_level
|
63
|
+
|
64
|
+
cdef class LLVMDouble(_LLVMLambdify):
|
65
|
+
cdef vector[symengine.LLVMDoubleVisitor] lambda_double
|
66
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
67
|
+
cdef _load(self, const string &s)
|
68
|
+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
|
69
|
+
cpdef as_scipy_low_level_callable(self)
|
70
|
+
cpdef as_ctypes(self)
|
71
|
+
|
72
|
+
cdef class LLVMFloat(_LLVMLambdify):
|
73
|
+
cdef vector[symengine.LLVMFloatVisitor] lambda_double
|
74
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
75
|
+
cdef _load(self, const string &s)
|
76
|
+
cpdef unsafe_real(self, float[::1] inp, float[::1] out, int inp_offset=*, int out_offset=*)
|
77
|
+
|
symengine/lib/zlib.dll
CHANGED
Binary file
|
symengine/lib/zstd.dll
ADDED
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import os
|
2
2
|
import sys
|
3
3
|
|
4
|
-
if sys.
|
4
|
+
if sys.platform == 'win32' \
|
5
5
|
and 'SYMENGINE_PY_ADD_PATH_TO_SEARCH_DIRS' in os.environ:
|
6
6
|
for directory in os.environ['PATH'].split(';'):
|
7
7
|
if os.path.isdir(directory):
|
@@ -26,7 +26,7 @@ from .lib.symengine_wrapper import (
|
|
26
26
|
Gt, Lt, And, Or, Not, Nand, Nor, Xor, Xnor, perfect_power, integer_nthroot,
|
27
27
|
isprime, sqrt_mod, Expr, cse, count_ops, ccode, Piecewise, Contains, Interval, FiniteSet,
|
28
28
|
linsolve,
|
29
|
-
FunctionSymbol
|
29
|
+
FunctionSymbol,
|
30
30
|
golden_ratio as GoldenRatio,
|
31
31
|
catalan as Catalan,
|
32
32
|
eulergamma as EulerGamma,
|
@@ -37,6 +37,7 @@ from .functions import *
|
|
37
37
|
from .printing import init_printing
|
38
38
|
|
39
39
|
|
40
|
+
AppliedUndef = FunctionSymbol # an alias
|
40
41
|
EmptySet = wrapper.S.EmptySet
|
41
42
|
UniversalSet = wrapper.S.UniversalSet
|
42
43
|
Reals = wrapper.S.Reals
|
@@ -55,9 +56,14 @@ if have_numpy:
|
|
55
56
|
|
56
57
|
def lambdify(args, exprs, **kwargs):
|
57
58
|
return Lambdify(args, *exprs, **kwargs)
|
59
|
+
else:
|
60
|
+
def __getattr__(name):
|
61
|
+
if name == 'lambdify':
|
62
|
+
raise AttributeError("Cannot import numpy, which is required for `lambdify` to work")
|
63
|
+
raise AttributeError(f"module 'symengine' has no attribute '{name}'")
|
58
64
|
|
59
65
|
|
60
|
-
__version__ = "0.
|
66
|
+
__version__ = "0.11.0"
|
61
67
|
|
62
68
|
|
63
69
|
# To not expose internals
|
@@ -4,7 +4,7 @@ class CCodePrinter:
|
|
4
4
|
|
5
5
|
def doprint(self, expr, assign_to=None):
|
6
6
|
if not isinstance(assign_to, (Basic, type(None), str)):
|
7
|
-
raise TypeError("{
|
7
|
+
raise TypeError("{} cannot assign to object of type {}".format(
|
8
8
|
type(self).__name__, type(assign_to)))
|
9
9
|
|
10
10
|
expr = sympify(expr)
|
@@ -15,11 +15,11 @@ class CCodePrinter:
|
|
15
15
|
|
16
16
|
assign_to = str(assign_to)
|
17
17
|
if not expr.is_Matrix:
|
18
|
-
return "{} = {
|
18
|
+
return f"{assign_to} = {ccode(expr)};"
|
19
19
|
|
20
20
|
code_lines = []
|
21
21
|
for i, element in enumerate(expr):
|
22
|
-
code_line = '{}[{}] = {};'
|
22
|
+
code_line = f'{assign_to}[{i}] = {element};'
|
23
23
|
code_lines.append(code_line)
|
24
24
|
return '\n'.join(code_lines)
|
25
25
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import sys
|
2
|
+
|
3
|
+
try:
|
4
|
+
import py
|
5
|
+
from py.test import skip, raises
|
6
|
+
USE_PYTEST = getattr(sys, '_running_pytest', False)
|
7
|
+
except ImportError:
|
8
|
+
USE_PYTEST = False
|
9
|
+
|
10
|
+
if not USE_PYTEST:
|
11
|
+
def raises(expectedException, code=None):
|
12
|
+
"""
|
13
|
+
Tests that ``code`` raises the exception ``expectedException``.
|
14
|
+
|
15
|
+
``code`` may be a callable, such as a lambda expression or function
|
16
|
+
name.
|
17
|
+
|
18
|
+
If ``code`` is not given or None, ``raises`` will return a context
|
19
|
+
manager for use in ``with`` statements; the code to execute then
|
20
|
+
comes from the scope of the ``with``.
|
21
|
+
|
22
|
+
``raises()`` does nothing if the callable raises the expected
|
23
|
+
exception, otherwise it raises an AssertionError.
|
24
|
+
|
25
|
+
Examples
|
26
|
+
========
|
27
|
+
|
28
|
+
>>> from symengine.pytest import raises
|
29
|
+
|
30
|
+
>>> raises(ZeroDivisionError, lambda: 1/0)
|
31
|
+
>>> raises(ZeroDivisionError, lambda: 1/2)
|
32
|
+
Traceback (most recent call last):
|
33
|
+
...
|
34
|
+
AssertionError: DID NOT RAISE
|
35
|
+
|
36
|
+
>>> with raises(ZeroDivisionError):
|
37
|
+
... n = 1/0
|
38
|
+
>>> with raises(ZeroDivisionError):
|
39
|
+
... n = 1/2
|
40
|
+
Traceback (most recent call last):
|
41
|
+
...
|
42
|
+
AssertionError: DID NOT RAISE
|
43
|
+
|
44
|
+
Note that you cannot test multiple statements via
|
45
|
+
``with raises``:
|
46
|
+
|
47
|
+
>>> with raises(ZeroDivisionError):
|
48
|
+
... n = 1/0 # will execute and raise, aborting the ``with``
|
49
|
+
... n = 9999/0 # never executed
|
50
|
+
|
51
|
+
This is just what ``with`` is supposed to do: abort the
|
52
|
+
contained statement sequence at the first exception and let
|
53
|
+
the context manager deal with the exception.
|
54
|
+
|
55
|
+
To test multiple statements, you'll need a separate ``with``
|
56
|
+
for each:
|
57
|
+
|
58
|
+
>>> with raises(ZeroDivisionError):
|
59
|
+
... n = 1/0 # will execute and raise
|
60
|
+
>>> with raises(ZeroDivisionError):
|
61
|
+
... n = 9999/0 # will also execute and raise
|
62
|
+
|
63
|
+
"""
|
64
|
+
if code is None:
|
65
|
+
return RaisesContext(expectedException)
|
66
|
+
elif callable(code):
|
67
|
+
try:
|
68
|
+
code()
|
69
|
+
except expectedException:
|
70
|
+
return
|
71
|
+
raise AssertionError("DID NOT RAISE")
|
72
|
+
elif isinstance(code, str):
|
73
|
+
raise TypeError(
|
74
|
+
'\'raises(xxx, "code")\' has been phased out; '
|
75
|
+
'change \'raises(xxx, "expression")\' '
|
76
|
+
'to \'raises(xxx, lambda: expression)\', '
|
77
|
+
'\'raises(xxx, "statement")\' '
|
78
|
+
'to \'with raises(xxx): statement\'')
|
79
|
+
else:
|
80
|
+
raise TypeError(
|
81
|
+
'raises() expects a callable for the 2nd argument.')
|
82
|
+
|
83
|
+
class RaisesContext:
|
84
|
+
def __init__(self, expectedException):
|
85
|
+
self.expectedException = expectedException
|
86
|
+
|
87
|
+
def __enter__(self):
|
88
|
+
return None
|
89
|
+
|
90
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
91
|
+
if exc_type is None:
|
92
|
+
raise AssertionError("DID NOT RAISE")
|
93
|
+
return issubclass(exc_type, self.expectedException)
|
94
|
+
|
95
|
+
|
@@ -1,7 +1,7 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
|
3
3
|
from symengine import (Symbol, Integer, Add, Mul, Pow, Rational, sqrt,
|
4
|
-
symbols, S, I, count_ops)
|
4
|
+
symbols, S, I, count_ops, floor)
|
5
5
|
|
6
6
|
|
7
7
|
def test_arit1():
|
@@ -133,27 +133,27 @@ def test_args():
|
|
133
133
|
y = Symbol("y")
|
134
134
|
assert (x**2).args == (x, 2)
|
135
135
|
assert (x**2 + 5).args == (5, x**2)
|
136
|
-
assert set((x**2 + 2*x*y + 5).args) ==
|
136
|
+
assert set((x**2 + 2*x*y + 5).args) == {x**2, 2*x*y, Integer(5)}
|
137
137
|
assert (2*x**2).args == (2, x**2)
|
138
|
-
assert set((2*x**2*y).args) ==
|
138
|
+
assert set((2*x**2*y).args) == {Integer(2), x**2, y}
|
139
139
|
|
140
140
|
|
141
141
|
def test_atoms():
|
142
142
|
x = Symbol("x")
|
143
143
|
y = Symbol("y")
|
144
144
|
z = Symbol("z")
|
145
|
-
assert (x**2).atoms() ==
|
146
|
-
assert (x**2).atoms(Symbol) ==
|
147
|
-
assert (x ** y + z).atoms() ==
|
148
|
-
assert (x**y + z).atoms(Symbol) ==
|
145
|
+
assert (x**2).atoms() == {x}
|
146
|
+
assert (x**2).atoms(Symbol) == {x}
|
147
|
+
assert (x ** y + z).atoms() == {x, y, z}
|
148
|
+
assert (x**y + z).atoms(Symbol) == {x, y, z}
|
149
149
|
|
150
150
|
|
151
151
|
def test_free_symbols():
|
152
152
|
x = Symbol("x")
|
153
153
|
y = Symbol("y")
|
154
154
|
z = Symbol("z")
|
155
|
-
assert (x**2).free_symbols ==
|
156
|
-
assert (x**y + z).free_symbols ==
|
155
|
+
assert (x**2).free_symbols == {x}
|
156
|
+
assert (x**y + z).free_symbols == {x, y, z}
|
157
157
|
|
158
158
|
|
159
159
|
def test_as_numer_denom():
|
@@ -165,12 +165,23 @@ def test_as_numer_denom():
|
|
165
165
|
assert x == Integer(-5)
|
166
166
|
assert y == Integer(1)
|
167
167
|
|
168
|
+
|
169
|
+
def test_floor():
|
170
|
+
exprs = [Symbol("x"), Symbol("y"), Integer(2), Rational(-3, 5), Integer(-3)]
|
171
|
+
|
172
|
+
for x in exprs:
|
173
|
+
for y in exprs:
|
174
|
+
assert x // y == floor(x / y)
|
175
|
+
assert x == y * (x // y) + x % y
|
176
|
+
|
177
|
+
|
168
178
|
def test_as_real_imag():
|
169
179
|
x, y = (5 + 6 * I).as_real_imag()
|
170
180
|
|
171
181
|
assert x == 5
|
172
182
|
assert y == 6
|
173
183
|
|
184
|
+
|
174
185
|
def test_from_args():
|
175
186
|
x = Symbol("x")
|
176
187
|
y = Symbol("y")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from symengine import cse, sqrt, symbols
|
2
|
+
|
3
|
+
def test_cse_single():
|
4
|
+
x, y, x0 = symbols("x, y, x0")
|
5
|
+
e = pow(x + y, 2) + sqrt(x + y)
|
6
|
+
substs, reduced = cse([e])
|
7
|
+
assert substs == [(x0, x + y)]
|
8
|
+
assert reduced == [sqrt(x0) + x0**2]
|
9
|
+
|
10
|
+
|
11
|
+
def test_multiple_expressions():
|
12
|
+
w, x, y, z, x0 = symbols("w, x, y, z, x0")
|
13
|
+
e1 = (x + y)*z
|
14
|
+
e2 = (x + y)*w
|
15
|
+
substs, reduced = cse([e1, e2])
|
16
|
+
assert substs == [(x0, x + y)]
|
17
|
+
assert reduced == [x0*z, x0*w]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
|
3
3
|
from symengine import symbols, DictBasic, sin, Integer
|
4
4
|
|
@@ -18,11 +18,11 @@ def test_DictBasic():
|
|
18
18
|
assert d[2*z] == x
|
19
19
|
if 2*z not in d:
|
20
20
|
assert False
|
21
|
-
assert set(d.items()) ==
|
21
|
+
assert set(d.items()) == {(2*z, x), (x, Integer(2)), (y, z)}
|
22
22
|
|
23
23
|
del d[x]
|
24
|
-
assert set(d.keys()) ==
|
25
|
-
assert set(d.values()) ==
|
24
|
+
assert set(d.keys()) == {2*z, y}
|
25
|
+
assert set(d.values()) == {x, z}
|
26
26
|
|
27
27
|
e = y + sin(2*z)
|
28
28
|
assert e.subs(d) == z + sin(x)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
from symengine import (Symbol, sin, cos, Integer, Add, I, RealDouble, ComplexDouble, sqrt)
|
3
3
|
|
4
4
|
from unittest.case import SkipTest
|
@@ -16,7 +16,7 @@ def test_eval_double2():
|
|
16
16
|
x = Symbol("x")
|
17
17
|
e = sin(x)**2 + sqrt(2)
|
18
18
|
raises(RuntimeError, lambda: e.n(real=True))
|
19
|
-
assert abs(e.n() - x**2 - 1.414) < 1e-3
|
19
|
+
assert abs(e.n() - sin(x)**2.0 - 1.414) < 1e-3
|
20
20
|
|
21
21
|
def test_n():
|
22
22
|
x = Symbol("x")
|
@@ -0,0 +1,28 @@
|
|
1
|
+
from symengine import Symbol, Integer, oo
|
2
|
+
from symengine.test_utilities import raises
|
3
|
+
|
4
|
+
|
5
|
+
def test_as_coefficients_dict():
|
6
|
+
x = Symbol('x')
|
7
|
+
y = Symbol('y')
|
8
|
+
check = [x, y, x*y, Integer(1)]
|
9
|
+
assert [(3*x + 2*x + y + 3).as_coefficients_dict()[i] for i in check] == \
|
10
|
+
[5, 1, 0, 3]
|
11
|
+
assert [(3*x*y).as_coefficients_dict()[i] for i in check] == \
|
12
|
+
[0, 0, 3, 0]
|
13
|
+
assert (3.0*x*y).as_coefficients_dict()[3.0*x*y] == 0
|
14
|
+
assert (3.0*x*y).as_coefficients_dict()[x*y] == 3.0
|
15
|
+
|
16
|
+
|
17
|
+
def test_as_powers_dict():
|
18
|
+
x = Symbol('x')
|
19
|
+
y = Symbol('y')
|
20
|
+
|
21
|
+
assert (2*x**y).as_powers_dict() == {2: 1, x: y}
|
22
|
+
assert (2*x**2*y**3).as_powers_dict() == {2: 1, x: 2, y: 3}
|
23
|
+
assert (-oo).as_powers_dict() == {Integer(-1): 1, oo: 1}
|
24
|
+
assert (x**y).as_powers_dict() == {x: y}
|
25
|
+
assert ((1/Integer(2))**y).as_powers_dict() == {Integer(2): -y}
|
26
|
+
assert (x*(1/Integer(2))**y).as_powers_dict() == {x: Integer(1), Integer(2): -y}
|
27
|
+
assert (2**y).as_powers_dict() == {2: y}
|
28
|
+
assert (2**-y).as_powers_dict() == {2: -y}
|
@@ -5,7 +5,7 @@ from symengine import (
|
|
5
5
|
loggamma, beta, polygamma, digamma, trigamma, sign, floor, ceiling, conjugate,
|
6
6
|
nan, Float, UnevaluatedExpr
|
7
7
|
)
|
8
|
-
from symengine.
|
8
|
+
from symengine.test_utilities import raises
|
9
9
|
|
10
10
|
import unittest
|
11
11
|
|
@@ -85,6 +85,7 @@ def test_derivative():
|
|
85
85
|
assert s.variables == (x,)
|
86
86
|
|
87
87
|
fxy = Function("f")(x, y)
|
88
|
+
assert (1+fxy).has(fxy)
|
88
89
|
g = Derivative(Function("f")(x, y), x, 2, y, 1)
|
89
90
|
assert g == fxy.diff(x, x, y)
|
90
91
|
assert g == fxy.diff(y, 1, x, 2)
|
@@ -1,17 +1,12 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
from __future__ import (absolute_import, division, print_function)
|
3
|
-
|
4
|
-
|
5
1
|
import array
|
6
2
|
import cmath
|
7
3
|
from functools import reduce
|
8
4
|
import itertools
|
9
5
|
from operator import mul
|
10
6
|
import math
|
11
|
-
import sys
|
12
7
|
|
13
8
|
import symengine as se
|
14
|
-
from symengine.
|
9
|
+
from symengine.test_utilities import raises
|
15
10
|
from symengine import have_numpy
|
16
11
|
import unittest
|
17
12
|
from unittest.case import SkipTest
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
from symengine.lib.symengine_wrapper import (true, false, Eq, Ne, Ge, Gt, Le, Lt, Symbol,
|
3
3
|
I, And, Or, Not, Nand, Nor, Xor, Xnor, Piecewise,
|
4
4
|
Contains, Interval, FiniteSet, oo, log)
|
@@ -44,6 +44,7 @@ def test_And():
|
|
44
44
|
assert And(True, False) == false
|
45
45
|
assert And(False, False) == false
|
46
46
|
assert And(True, True, True) == true
|
47
|
+
raises(TypeError, lambda: x < y and y < 1)
|
47
48
|
|
48
49
|
|
49
50
|
def test_Or():
|
@@ -54,6 +55,7 @@ def test_Or():
|
|
54
55
|
assert Or(True, False) == true
|
55
56
|
assert Or(False, False) == false
|
56
57
|
assert Or(True, False, False) == true
|
58
|
+
raises(TypeError, lambda: x < y or y < 1)
|
57
59
|
|
58
60
|
|
59
61
|
def test_Nor():
|
@@ -116,4 +118,4 @@ def test_Contains():
|
|
116
118
|
assert Contains(x, Interval(1, 1)) != false
|
117
119
|
assert Contains(oo, Interval(-oo, oo)) == false
|
118
120
|
assert Contains(-oo, Interval(-oo, oo)) == false
|
119
|
-
|
121
|
+
|
@@ -2,14 +2,24 @@ from symengine import symbols, init_printing
|
|
2
2
|
from symengine.lib.symengine_wrapper import (DenseMatrix, Symbol, Integer,
|
3
3
|
Rational, function_symbol, I, NonSquareMatrixError, ShapeError, zeros,
|
4
4
|
ones, eye, ImmutableMatrix)
|
5
|
-
from symengine.
|
5
|
+
from symengine.test_utilities import raises
|
6
|
+
import unittest
|
6
7
|
|
7
8
|
|
8
9
|
try:
|
9
10
|
import numpy as np
|
10
|
-
|
11
|
+
have_numpy = True
|
11
12
|
except ImportError:
|
12
|
-
|
13
|
+
have_numpy = False
|
14
|
+
|
15
|
+
try:
|
16
|
+
import sympy
|
17
|
+
from sympy.core.cache import clear_cache
|
18
|
+
import atexit
|
19
|
+
atexit.register(clear_cache)
|
20
|
+
have_sympy = True
|
21
|
+
except ImportError:
|
22
|
+
have_sympy = False
|
13
23
|
|
14
24
|
|
15
25
|
def test_init():
|
@@ -520,10 +530,8 @@ def test_reshape():
|
|
520
530
|
assert C != A
|
521
531
|
|
522
532
|
|
523
|
-
|
533
|
+
@unittest.skipIf(not have_numpy, 'requires numpy')
|
524
534
|
def test_dump_real():
|
525
|
-
if not HAVE_NUMPY: # nosetests work-around
|
526
|
-
return
|
527
535
|
ref = [1, 2, 3, 4]
|
528
536
|
A = DenseMatrix(2, 2, ref)
|
529
537
|
out = np.empty(4)
|
@@ -531,10 +539,9 @@ def test_dump_real():
|
|
531
539
|
assert np.allclose(out, ref)
|
532
540
|
|
533
541
|
|
534
|
-
|
542
|
+
|
543
|
+
@unittest.skipIf(not have_numpy, 'requires numpy')
|
535
544
|
def test_dump_complex():
|
536
|
-
if not HAVE_NUMPY: # nosetests work-around
|
537
|
-
return
|
538
545
|
ref = [1j, 2j, 3j, 4j]
|
539
546
|
A = DenseMatrix(2, 2, ref)
|
540
547
|
out = np.empty(4, dtype=np.complex128)
|
@@ -721,7 +728,7 @@ def test_atoms():
|
|
721
728
|
a = Symbol("a")
|
722
729
|
b = Symbol("b")
|
723
730
|
X = DenseMatrix([[a, 2], [b, 4]])
|
724
|
-
assert X.atoms(Symbol) ==
|
731
|
+
assert X.atoms(Symbol) == {a, b}
|
725
732
|
|
726
733
|
|
727
734
|
def test_LUdecomp():
|
@@ -741,3 +748,8 @@ def test_repr_latex():
|
|
741
748
|
latex_string = testmat._repr_latex_()
|
742
749
|
assert isinstance(latex_string, str)
|
743
750
|
init_printing(False)
|
751
|
+
|
752
|
+
@unittest.skipIf(not have_sympy, "SymPy not installed")
|
753
|
+
def test_simplify():
|
754
|
+
A = ImmutableMatrix([1])
|
755
|
+
assert type(A.simplify()) == type(A)
|