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.
Files changed (79) hide show
  1. symengine/lib/{flint-16.dll → flint-17.dll} +0 -0
  2. symengine/lib/mpc.dll +0 -0
  3. symengine/lib/mpfr.dll +0 -0
  4. symengine/lib/pywrapper.h +22 -5
  5. symengine/lib/symengine.pxd +274 -432
  6. symengine/lib/symengine_wrapper.cp38-win_amd64.lib +0 -0
  7. symengine/lib/symengine_wrapper.cp38-win_amd64.pyd +0 -0
  8. symengine/lib/symengine_wrapper.pxd +77 -86
  9. symengine/lib/zlib.dll +0 -0
  10. symengine/lib/zstd.dll +0 -0
  11. {symengine → symengine-0.11.0.data/purelib/symengine}/__init__.py +9 -3
  12. {symengine → symengine-0.11.0.data/purelib/symengine}/printing.py +3 -3
  13. symengine-0.11.0.data/purelib/symengine/test_utilities.py +95 -0
  14. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_arit.py +21 -10
  15. symengine-0.11.0.data/purelib/symengine/tests/test_cse.py +17 -0
  16. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_dict_basic.py +4 -4
  17. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_eval.py +2 -2
  18. symengine-0.11.0.data/purelib/symengine/tests/test_expr.py +28 -0
  19. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_functions.py +2 -1
  20. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_lambdify.py +1 -6
  21. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_logic.py +4 -2
  22. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_matrices.py +22 -10
  23. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_ntheory.py +1 -1
  24. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_number.py +1 -1
  25. symengine-0.11.0.data/purelib/symengine/tests/test_pickling.py +59 -0
  26. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_printing.py +1 -1
  27. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_series_expansion.py +1 -1
  28. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sets.py +1 -1
  29. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_solve.py +1 -1
  30. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_subs.py +1 -1
  31. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_symbol.py +5 -5
  32. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympify.py +2 -2
  33. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympy_compat.py +2 -2
  34. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sympy_conv.py +40 -3
  35. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_var.py +1 -1
  36. {symengine → symengine-0.11.0.data/purelib/symengine}/utilities.py +0 -93
  37. {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/AUTHORS +1 -0
  38. {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/METADATA +31 -33
  39. symengine-0.11.0.dist-info/RECORD +49 -0
  40. {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/WHEEL +1 -1
  41. symengine-0.11.0.dist-info/top_level.txt +1 -0
  42. symengine/__pycache__/__init__.cpython-38.pyc +0 -0
  43. symengine/__pycache__/functions.cpython-38.pyc +0 -0
  44. symengine/__pycache__/printing.cpython-38.pyc +0 -0
  45. symengine/__pycache__/sympy_compat.cpython-38.pyc +0 -0
  46. symengine/__pycache__/utilities.cpython-38.pyc +0 -0
  47. symengine/lib/__pycache__/__init__.cpython-38.pyc +0 -0
  48. symengine/lib/config.pxi +0 -6
  49. symengine/tests/__pycache__/__init__.cpython-38.pyc +0 -0
  50. symengine/tests/__pycache__/test_arit.cpython-38.pyc +0 -0
  51. symengine/tests/__pycache__/test_dict_basic.cpython-38.pyc +0 -0
  52. symengine/tests/__pycache__/test_eval.cpython-38.pyc +0 -0
  53. symengine/tests/__pycache__/test_expr.cpython-38.pyc +0 -0
  54. symengine/tests/__pycache__/test_functions.cpython-38.pyc +0 -0
  55. symengine/tests/__pycache__/test_lambdify.cpython-38.pyc +0 -0
  56. symengine/tests/__pycache__/test_logic.cpython-38.pyc +0 -0
  57. symengine/tests/__pycache__/test_matrices.cpython-38.pyc +0 -0
  58. symengine/tests/__pycache__/test_ntheory.cpython-38.pyc +0 -0
  59. symengine/tests/__pycache__/test_number.cpython-38.pyc +0 -0
  60. symengine/tests/__pycache__/test_printing.cpython-38.pyc +0 -0
  61. symengine/tests/__pycache__/test_sage.cpython-38.pyc +0 -0
  62. symengine/tests/__pycache__/test_series_expansion.cpython-38.pyc +0 -0
  63. symengine/tests/__pycache__/test_sets.cpython-38.pyc +0 -0
  64. symengine/tests/__pycache__/test_solve.cpython-38.pyc +0 -0
  65. symengine/tests/__pycache__/test_subs.cpython-38.pyc +0 -0
  66. symengine/tests/__pycache__/test_symbol.cpython-38.pyc +0 -0
  67. symengine/tests/__pycache__/test_sympify.cpython-38.pyc +0 -0
  68. symengine/tests/__pycache__/test_sympy_compat.cpython-38.pyc +0 -0
  69. symengine/tests/__pycache__/test_sympy_conv.cpython-38.pyc +0 -0
  70. symengine/tests/__pycache__/test_var.cpython-38.pyc +0 -0
  71. symengine/tests/test_expr.py +0 -14
  72. symengine-0.9.2.dist-info/RECORD +0 -74
  73. symengine-0.9.2.dist-info/top_level.txt +0 -1
  74. {symengine → symengine-0.11.0.data/purelib/symengine}/functions.py +0 -0
  75. {symengine → symengine-0.11.0.data/purelib/symengine}/lib/__init__.py +0 -0
  76. {symengine → symengine-0.11.0.data/purelib/symengine}/sympy_compat.py +0 -0
  77. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/__init__.py +0 -0
  78. {symengine → symengine-0.11.0.data/purelib/symengine}/tests/test_sage.py +0 -0
  79. {symengine-0.9.2.dist-info → symengine-0.11.0.dist-info}/LICENSE +0 -0
@@ -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
- include "config.pxi"
10
-
11
- cdef class Basic(object):
12
- cdef rcp_const_basic thisptr
13
-
14
- cdef class MatrixBase(object):
15
- cdef symengine.MatrixBase* thisptr
16
-
17
- cdef class PyFunctionClass(object):
18
- cdef RCP[const symengine.PyFunctionClass] thisptr
19
-
20
- cdef class PyModule(object):
21
- cdef RCP[const symengine.PyModule] thisptr
22
-
23
- cdef class _DictBasic(object):
24
- cdef map_basic_basic c
25
-
26
- cdef class DictBasicIter(object):
27
- cdef map_basic_basic.iterator begin
28
- cdef map_basic_basic.iterator end
29
- cdef init(self, map_basic_basic.iterator begin, map_basic_basic.iterator end)
30
-
31
- cdef object c2py(rcp_const_basic o)
32
-
33
- cdef class _Lambdify(object):
34
- cdef size_t args_size, tot_out_size
35
- cdef list out_shapes
36
- cdef readonly bint real
37
- cdef readonly size_t n_exprs
38
- cdef public str order
39
- cdef vector[int] accum_out_sizes
40
- cdef object numpy_dtype
41
-
42
- cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
43
- cdef _load(self, const string &s)
44
- cpdef eval_real(self, inp, out)
45
- cpdef eval_complex(self, inp, out)
46
- cpdef unsafe_eval(sef, inp, out, unsigned nbroadcast=*)
47
-
48
- cdef class LambdaDouble(_Lambdify):
49
- cdef vector[symengine.LambdaRealDoubleVisitor] lambda_double
50
- cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
51
- cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
52
- cpdef as_scipy_low_level_callable(self)
53
- cpdef as_ctypes(self)
54
- cpdef unsafe_real(self,
55
- double[::1] inp, double[::1] out,
56
- int inp_offset=*, int out_offset=*)
57
-
58
- cdef class LambdaComplexDouble(_Lambdify):
59
- cdef vector[symengine.LambdaComplexDoubleVisitor] lambda_double
60
- cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
61
- cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out, int inp_offset=*, int out_offset=*)
62
-
63
- IF HAVE_SYMENGINE_LLVM:
64
- cdef class _LLVMLambdify(_Lambdify):
65
- cdef int opt_level
66
-
67
- cdef class LLVMDouble(_LLVMLambdify):
68
- cdef vector[symengine.LLVMDoubleVisitor] lambda_double
69
- cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
70
- cdef _load(self, const string &s)
71
- cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
72
- cpdef as_scipy_low_level_callable(self)
73
- cpdef as_ctypes(self)
74
-
75
- cdef class LLVMFloat(_LLVMLambdify):
76
- cdef vector[symengine.LLVMFloatVisitor] lambda_double
77
- cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
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.version_info >= (3, 8, 0) and sys.platform == 'win32' \
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 as AppliedUndef,
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.9.2"
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("{0} cannot assign to object of type {1}".format(
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 "{} = {};".format(assign_to, ccode(expr))
18
+ return f"{assign_to} = {ccode(expr)};"
19
19
 
20
20
  code_lines = []
21
21
  for i, element in enumerate(expr):
22
- code_line = '{}[{}] = {};'.format(assign_to, i, element)
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.utilities import raises
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) == set((x**2, 2*x*y, Integer(5)))
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) == set((Integer(2), x**2, y))
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() == set([x])
146
- assert (x**2).atoms(Symbol) == set([x])
147
- assert (x ** y + z).atoms() == set([x, y, z])
148
- assert (x**y + z).atoms(Symbol) == set([x, y, z])
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 == set([x])
156
- assert (x**y + z).free_symbols == set([x, y, z])
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.utilities import raises
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()) == set([(2*z, x), (x, Integer(2)), (y, z)])
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()) == set([2*z, y])
25
- assert set(d.values()) == set([x, z])
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.utilities import raises
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.utilities import raises
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.utilities import raises
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.utilities import raises
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.utilities import raises
5
+ from symengine.test_utilities import raises
6
+ import unittest
6
7
 
7
8
 
8
9
  try:
9
10
  import numpy as np
10
- HAVE_NUMPY = True
11
+ have_numpy = True
11
12
  except ImportError:
12
- HAVE_NUMPY = False
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
- # @pytest.mark.skipif(not HAVE_NUMPY, reason='requires numpy')
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
- # @pytest.mark.skipif(not HAVE_NUMPY, reason='requires numpy')
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) == set([a, b])
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)
@@ -1,4 +1,4 @@
1
- from symengine.utilities import raises
1
+ from symengine.test_utilities import raises
2
2
 
3
3
  from symengine.lib.symengine_wrapper import (isprime, nextprime, gcd,
4
4
  lcm, gcd_ext, mod, quotient, quotient_mod, mod_inverse, crt, fibonacci,
@@ -1,4 +1,4 @@
1
- from symengine.utilities import raises
1
+ from symengine.test_utilities import raises
2
2
 
3
3
  from symengine import Integer, I, S, Symbol, pi, Rational
4
4
  from symengine.lib.symengine_wrapper import (perfect_power, is_square, integer_nthroot)