symengine 0.9.2__cp39-cp39-macosx_11_0_arm64.whl → 0.11.0__cp39-cp39-macosx_11_0_arm64.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/pywrapper.h +22 -5
- symengine/lib/symengine.pxd +274 -432
- symengine/lib/symengine_wrapper.cpython-39-darwin.so +0 -0
- symengine/lib/symengine_wrapper.pxd +17 -26
- {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 +4 -6
- symengine-0.11.0.dist-info/RECORD +47 -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/.dylibs → symengine.dylibs}/libflint-15.dylib +0 -0
- symengine.dylibs/libgmp.10.dylib +0 -0
- symengine.dylibs/libmpc.3.dylib +0 -0
- symengine.dylibs/libmpfr.6.dylib +0 -0
- symengine.dylibs/libz.1.2.13.dylib +0 -0
- symengine.dylibs/libzstd.1.5.5.dylib +0 -0
- symengine/.dylibs/libgmp.10.dylib +0 -0
- symengine/.dylibs/libmpc.3.dylib +0 -0
- symengine/.dylibs/libmpfr.6.dylib +0 -0
- symengine/.dylibs/libz.1.2.11.dylib +0 -0
- symengine/__pycache__/__init__.cpython-39.pyc +0 -0
- symengine/__pycache__/functions.cpython-39.pyc +0 -0
- symengine/__pycache__/printing.cpython-39.pyc +0 -0
- symengine/__pycache__/sympy_compat.cpython-39.pyc +0 -0
- symengine/__pycache__/utilities.cpython-39.pyc +0 -0
- symengine/lib/__pycache__/__init__.cpython-39.pyc +0 -0
- symengine/lib/config.pxi +0 -6
- symengine/tests/__pycache__/__init__.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_arit.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_dict_basic.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_eval.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_expr.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_functions.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_lambdify.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_logic.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_matrices.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_ntheory.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_number.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_printing.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_sage.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_series_expansion.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_sets.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_solve.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_subs.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_symbol.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_sympify.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_sympy_compat.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_sympy_conv.cpython-39.pyc +0 -0
- symengine/tests/__pycache__/test_var.cpython-39.pyc +0 -0
- symengine/tests/test_expr.py +0 -14
- symengine-0.9.2.dist-info/RECORD +0 -72
- 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
|
@@ -6,8 +6,6 @@ from libcpp.vector cimport vector
|
|
6
6
|
from libcpp.string cimport string
|
7
7
|
from libcpp cimport bool as cppbool
|
8
8
|
|
9
|
-
include "config.pxi"
|
10
|
-
|
11
9
|
cdef class Basic(object):
|
12
10
|
cdef rcp_const_basic thisptr
|
13
11
|
|
@@ -60,27 +58,20 @@ cdef class LambdaComplexDouble(_Lambdify):
|
|
60
58
|
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
61
59
|
cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out, int inp_offset=*, int out_offset=*)
|
62
60
|
|
63
|
-
|
64
|
-
cdef
|
65
|
-
|
66
|
-
|
67
|
-
cdef
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
cdef
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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=*)
|
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
|
+
|
@@ -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)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from symengine import symbols, sin, sinh, have_numpy, have_llvm, cos, Symbol
|
2
|
+
from symengine.test_utilities import raises
|
3
|
+
import pickle
|
4
|
+
import unittest
|
5
|
+
|
6
|
+
|
7
|
+
def test_basic():
|
8
|
+
x, y, z = symbols('x y z')
|
9
|
+
expr = sin(cos(x + y)/z)**2
|
10
|
+
s = pickle.dumps(expr)
|
11
|
+
expr2 = pickle.loads(s)
|
12
|
+
assert expr == expr2
|
13
|
+
|
14
|
+
|
15
|
+
class MySymbolBase(Symbol):
|
16
|
+
def __init__(self, name, attr):
|
17
|
+
super().__init__(name=name)
|
18
|
+
self.attr = attr
|
19
|
+
|
20
|
+
def __eq__(self, other):
|
21
|
+
if not isinstance(other, MySymbolBase):
|
22
|
+
return False
|
23
|
+
return self.name == other.name and self.attr == other.attr
|
24
|
+
|
25
|
+
|
26
|
+
class MySymbol(MySymbolBase):
|
27
|
+
def __reduce__(self):
|
28
|
+
return (self.__class__, (self.name, self.attr))
|
29
|
+
|
30
|
+
|
31
|
+
def test_pysymbol():
|
32
|
+
a = MySymbol("hello", attr=1)
|
33
|
+
b = pickle.loads(pickle.dumps(a + 2)) - 2
|
34
|
+
try:
|
35
|
+
assert a == b
|
36
|
+
finally:
|
37
|
+
a._unsafe_reset()
|
38
|
+
b._unsafe_reset()
|
39
|
+
|
40
|
+
a = MySymbolBase("hello", attr=1)
|
41
|
+
try:
|
42
|
+
raises(NotImplementedError, lambda: pickle.dumps(a))
|
43
|
+
raises(NotImplementedError, lambda: pickle.dumps(a + 2))
|
44
|
+
finally:
|
45
|
+
a._unsafe_reset()
|
46
|
+
|
47
|
+
|
48
|
+
@unittest.skipUnless(have_llvm, "No LLVM support")
|
49
|
+
@unittest.skipUnless(have_numpy, "Numpy not installed")
|
50
|
+
def test_llvm_double():
|
51
|
+
import numpy as np
|
52
|
+
from symengine import Lambdify
|
53
|
+
args = x, y, z = symbols('x y z')
|
54
|
+
expr = sin(sinh(x+y) + z)
|
55
|
+
l = Lambdify(args, expr, cse=True, backend='llvm')
|
56
|
+
ss = pickle.dumps(l)
|
57
|
+
ll = pickle.loads(ss)
|
58
|
+
inp = [1, 2, 3]
|
59
|
+
assert np.allclose(l(inp), ll(inp))
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
from symengine.lib.symengine_wrapper import (Interval, EmptySet, UniversalSet,
|
3
3
|
FiniteSet, Union, Complement, ImageSet, ConditionSet, Reals, Rationals,
|
4
4
|
Integers, And, Or, oo, Symbol, true, Ge, Eq, Gt)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from symengine import Symbol, symbols, symarray, has_symbol, Dummy
|
2
|
-
from symengine.
|
2
|
+
from symengine.test_utilities import raises
|
3
3
|
import unittest
|
4
4
|
import platform
|
5
5
|
|
@@ -48,7 +48,7 @@ def test_symbols():
|
|
48
48
|
|
49
49
|
assert symbols(('x', 'y', 'z')) == (x, y, z)
|
50
50
|
assert symbols(['x', 'y', 'z']) == [x, y, z]
|
51
|
-
assert symbols(
|
51
|
+
assert symbols({'x', 'y', 'z'}) == {x, y, z}
|
52
52
|
|
53
53
|
raises(ValueError, lambda: symbols(''))
|
54
54
|
raises(ValueError, lambda: symbols(','))
|
@@ -104,13 +104,13 @@ def test_symbols():
|
|
104
104
|
assert sym('a0:4') == '(a0, a1, a2, a3)'
|
105
105
|
assert sym('a2:4,b1:3') == '(a2, a3, b1, b2)'
|
106
106
|
assert sym('a1(2:4)') == '(a12, a13)'
|
107
|
-
assert sym(
|
108
|
-
assert sym(
|
107
|
+
assert sym('a0:2.0:2') == '(a0.0, a0.1, a1.0, a1.1)'
|
108
|
+
assert sym('aa:cz') == '(aaz, abz, acz)'
|
109
109
|
assert sym('aa:c0:2') == '(aa0, aa1, ab0, ab1, ac0, ac1)'
|
110
110
|
assert sym('aa:ba:b') == '(aaa, aab, aba, abb)'
|
111
111
|
assert sym('a:3b') == '(a0b, a1b, a2b)'
|
112
112
|
assert sym('a-1:3b') == '(a-1b, a-2b)'
|
113
|
-
assert sym('a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
|
113
|
+
assert sym(r'a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
|
114
114
|
(chr(0),)*4)
|
115
115
|
assert sym('x(:a:3)') == '(x(a0), x(a1), x(a2))'
|
116
116
|
assert sym('x(:c):1') == '(xa0, xb0, xc0)'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from symengine.
|
1
|
+
from symengine.test_utilities import raises
|
2
2
|
|
3
3
|
from symengine import (Symbol, Integer, sympify, SympifyError, true, false, pi, nan, oo,
|
4
4
|
zoo, E, I, GoldenRatio, Catalan, Rational, sqrt, Eq)
|
@@ -44,7 +44,7 @@ def test_S():
|
|
44
44
|
|
45
45
|
|
46
46
|
def test_sympify_error1a():
|
47
|
-
class Test
|
47
|
+
class Test:
|
48
48
|
pass
|
49
49
|
raises(SympifyError, lambda: sympify(Test()))
|
50
50
|
|