symengine 0.14.0__cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.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 +220 -0
- symengine/lib/symengine.pxd +955 -0
- symengine/lib/symengine_wrapper.cpython-310-x86_64-linux-gnu.so +0 -0
- symengine/lib/symengine_wrapper.pxd +83 -0
- symengine-0.14.0.data/purelib/symengine/__init__.py +79 -0
- symengine-0.14.0.data/purelib/symengine/functions.py +10 -0
- symengine-0.14.0.data/purelib/symengine/lib/__init__.py +0 -0
- symengine-0.14.0.data/purelib/symengine/printing.py +33 -0
- symengine-0.14.0.data/purelib/symengine/sympy_compat.py +4 -0
- symengine-0.14.0.data/purelib/symengine/test_utilities.py +95 -0
- symengine-0.14.0.data/purelib/symengine/tests/__init__.py +0 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_arit.py +261 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_cse.py +17 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_dict_basic.py +28 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_eval.py +67 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_expr.py +28 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_functions.py +432 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_lambdify.py +863 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_logic.py +124 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_matrices.py +757 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_ntheory.py +254 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_number.py +186 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_pickling.py +59 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_printing.py +38 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sage.py +175 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_series_expansion.py +22 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sets.py +118 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_solve.py +25 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_subs.py +82 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_symbol.py +179 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympify.py +63 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympy_compat.py +200 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympy_conv.py +835 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_var.py +68 -0
- symengine-0.14.0.data/purelib/symengine/utilities.py +280 -0
- symengine-0.14.0.dist-info/AUTHORS +40 -0
- symengine-0.14.0.dist-info/LICENSE +431 -0
- symengine-0.14.0.dist-info/METADATA +39 -0
- symengine-0.14.0.dist-info/RECORD +46 -0
- symengine-0.14.0.dist-info/WHEEL +6 -0
- symengine-0.14.0.dist-info/top_level.txt +1 -0
- symengine.libs/libflint-0b80cc24.so.19.0.0 +0 -0
- symengine.libs/libgmp-42d12c2b.so.10.5.0 +0 -0
- symengine.libs/libmpc-9408b0d6.so.3.3.1 +0 -0
- symengine.libs/libmpfr-b62f4d19.so.6.2.1 +0 -0
- symengine.libs/libzstd-0f56e521.so.1.5.6 +0 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
#ifndef SYMENGINE_PYWRAPPER_H
|
2
|
+
#define SYMENGINE_PYWRAPPER_H
|
3
|
+
|
4
|
+
#include <Python.h>
|
5
|
+
#include <symengine/number.h>
|
6
|
+
#include <symengine/constants.h>
|
7
|
+
#include <symengine/functions.h>
|
8
|
+
|
9
|
+
namespace SymEngine {
|
10
|
+
|
11
|
+
std::string pickle_dumps(const PyObject *);
|
12
|
+
PyObject* pickle_loads(const std::string &);
|
13
|
+
|
14
|
+
/*
|
15
|
+
* PySymbol is a subclass of Symbol that keeps a reference to a Python object.
|
16
|
+
* When subclassing a Symbol from Python, the information stored in subclassed
|
17
|
+
* object is lost because all the arithmetic and function evaluations happen on
|
18
|
+
* the C++ side. The object returned by `(x + 1) - 1` is wrapped in the Python
|
19
|
+
* class Symbol and therefore the fact that `x` is a subclass of Symbol is lost.
|
20
|
+
*
|
21
|
+
* By subclassing in the C++ side and keeping a python object reference, the
|
22
|
+
* subclassed python object can be returned instead of wrapping in a Python
|
23
|
+
* class Symbol.
|
24
|
+
*
|
25
|
+
* TODO: Python object and C++ object both keep a reference to each other as one
|
26
|
+
* must be alive when the other is alive. This creates a cyclic reference and
|
27
|
+
* should be fixed.
|
28
|
+
*/
|
29
|
+
|
30
|
+
class PySymbol : public Symbol {
|
31
|
+
private:
|
32
|
+
PyObject* obj;
|
33
|
+
std::string bytes;
|
34
|
+
public:
|
35
|
+
const bool store_pickle;
|
36
|
+
PySymbol(const std::string& name, PyObject* obj, bool store_pickle) :
|
37
|
+
Symbol(name), obj(obj), store_pickle(store_pickle) {
|
38
|
+
if (store_pickle) {
|
39
|
+
bytes = pickle_dumps(obj);
|
40
|
+
} else {
|
41
|
+
Py_INCREF(obj);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
PyObject* get_py_object() const {
|
45
|
+
if (store_pickle) {
|
46
|
+
return pickle_loads(bytes);
|
47
|
+
} else {
|
48
|
+
Py_INCREF(obj);
|
49
|
+
return obj;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
virtual ~PySymbol() {
|
53
|
+
if (not store_pickle) {
|
54
|
+
// TODO: This is never called because of the cyclic reference.
|
55
|
+
Py_DECREF(obj);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
/*
|
61
|
+
* This module provides classes to wrap Python objects defined in SymPy
|
62
|
+
* or Sage into SymEngine.
|
63
|
+
*
|
64
|
+
* PyModule is a python module (SymPy or Sage) that provides Python callbacks.
|
65
|
+
* These callback functions for conversion, evaluation and differentiation are
|
66
|
+
* defined in the Cython module `symengine_wrapper.pyx` and passed to C++.
|
67
|
+
*
|
68
|
+
* PyNumber is for numeric types where addition, subtraction, multiplication
|
69
|
+
* and division with other numeric types produce a numeric type.
|
70
|
+
*
|
71
|
+
* PyFunction is an instance of a function defined in SymPy or Sage and contains
|
72
|
+
* a PyFunctionClass instance which holds the callback functions needed for
|
73
|
+
* interaction with other SymEngine functions
|
74
|
+
*
|
75
|
+
* C++ Evaluation methods like eval_double, eval_mpfr calls the eval_ method to
|
76
|
+
* convert PyNumber and PyFunction to known SymEngine types.
|
77
|
+
*/
|
78
|
+
|
79
|
+
//! Class to store the Python objects and Cython callback functions specific
|
80
|
+
// to a Python module. eg: SymPy or Sage
|
81
|
+
class PyModule : public EnableRCPFromThis<PyModule> {
|
82
|
+
public:
|
83
|
+
// Callback function to convert a SymEngine object to Python
|
84
|
+
PyObject* (*to_py_)(const RCP<const Basic>);
|
85
|
+
// Callback function to convert a Python object to SymEngine
|
86
|
+
RCP<const Basic> (*from_py_)(PyObject*);
|
87
|
+
// Callback function to evaluate a Python object to a bits number of
|
88
|
+
// precision and return a SymEngine Number
|
89
|
+
RCP<const Number> (*eval_)(PyObject*, long bits);
|
90
|
+
// Callback function to differentiate a Python object with respect to
|
91
|
+
// a SymEngine symbol and get a SymEngine object
|
92
|
+
RCP<const Basic> (*diff_)(PyObject*, RCP<const Basic>);
|
93
|
+
// Common constants in Python
|
94
|
+
PyObject *one, *zero, *minus_one;
|
95
|
+
public:
|
96
|
+
PyModule(PyObject* (*)(const RCP<const Basic> x), RCP<const Basic> (*)(PyObject*),
|
97
|
+
RCP<const Number> (*)(PyObject*, long), RCP<const Basic> (*)(PyObject*, RCP<const Basic>));
|
98
|
+
~PyModule();
|
99
|
+
PyObject* get_zero() const { return zero; }
|
100
|
+
PyObject* get_one() const { return one; }
|
101
|
+
PyObject* get_minus_one() const { return minus_one; }
|
102
|
+
};
|
103
|
+
|
104
|
+
//! Python numeric types that do not have direct counterparts in SymEngine are
|
105
|
+
// wrapped using this method. Eg: Sage's real_mpfi.
|
106
|
+
// Arithmetic operations are done by calling Python/C API's PyNumber_* methods
|
107
|
+
// after converting SymEngine::Number to Python module type. Arithmetic
|
108
|
+
// operations always returns a PyNumber type.
|
109
|
+
class PyNumber : public NumberWrapper {
|
110
|
+
private:
|
111
|
+
//! Python reference to the object being wrapped
|
112
|
+
PyObject* pyobject_;
|
113
|
+
//! Python module that this object belongs to
|
114
|
+
RCP<const PyModule> pymodule_;
|
115
|
+
public:
|
116
|
+
PyNumber(PyObject* pyobject, const RCP<const PyModule> &pymodule);
|
117
|
+
~PyNumber() {
|
118
|
+
Py_DECREF(pyobject_);
|
119
|
+
}
|
120
|
+
PyObject* get_py_object() const { return pyobject_; }
|
121
|
+
RCP<const PyModule> get_py_module() const { return pymodule_; }
|
122
|
+
//! \return true if `0`
|
123
|
+
virtual bool is_zero() const;
|
124
|
+
//! \return true if `1`
|
125
|
+
virtual bool is_one() const;
|
126
|
+
//! \return true if `-1`
|
127
|
+
virtual bool is_minus_one() const;
|
128
|
+
//! \return true if negative
|
129
|
+
virtual bool is_negative() const;
|
130
|
+
//! \return true if positive
|
131
|
+
virtual bool is_positive() const;
|
132
|
+
//! \return true if complex
|
133
|
+
virtual bool is_complex() const;
|
134
|
+
//! return true if the number is an exact representation
|
135
|
+
// false if the number is an approximation
|
136
|
+
virtual bool is_exact() const { return true; };
|
137
|
+
|
138
|
+
//! Addition
|
139
|
+
virtual RCP<const Number> add(const Number &other) const;
|
140
|
+
//! Subtraction
|
141
|
+
virtual RCP<const Number> sub(const Number &other) const;
|
142
|
+
virtual RCP<const Number> rsub(const Number &other) const;
|
143
|
+
//! Multiplication
|
144
|
+
virtual RCP<const Number> mul(const Number &other) const;
|
145
|
+
//! Division
|
146
|
+
virtual RCP<const Number> div(const Number &other) const;
|
147
|
+
virtual RCP<const Number> rdiv(const Number &other) const;
|
148
|
+
//! Power
|
149
|
+
virtual RCP<const Number> pow(const Number &other) const;
|
150
|
+
virtual RCP<const Number> rpow(const Number &other) const;
|
151
|
+
|
152
|
+
virtual RCP<const Number> eval(long bits) const;
|
153
|
+
virtual std::string __str__() const;
|
154
|
+
virtual int compare(const Basic &o) const;
|
155
|
+
virtual bool __eq__(const Basic &o) const;
|
156
|
+
virtual hash_t __hash__() const;
|
157
|
+
};
|
158
|
+
|
159
|
+
/*! Class to represent the parent class for a PyFunction. Stores
|
160
|
+
* a python reference `pyobject_` to a python callable object.
|
161
|
+
* A PyFunction instance is an instance of the parent PyFunctionClass's
|
162
|
+
* `pyobject_`.
|
163
|
+
* */
|
164
|
+
class PyFunctionClass : public EnableRCPFromThis<PyFunctionClass> {
|
165
|
+
private:
|
166
|
+
//! Callable python object to construct an instance of this class
|
167
|
+
PyObject *pyobject_;
|
168
|
+
//! Name of the function
|
169
|
+
std::string name_;
|
170
|
+
//! Hash of the python function
|
171
|
+
mutable hash_t hash_;
|
172
|
+
//! PyModule that this python function belongs to
|
173
|
+
RCP<const PyModule> pymodule_;
|
174
|
+
public:
|
175
|
+
PyFunctionClass(PyObject *pyobject, std::string name, const RCP<const PyModule> &pymodule);
|
176
|
+
PyObject* get_py_object() const { return pyobject_; }
|
177
|
+
RCP<const PyModule> get_py_module() const { return pymodule_; }
|
178
|
+
std::string get_name() const { return name_; }
|
179
|
+
//! Create an instance of this class with arguments `vec`.
|
180
|
+
PyObject* call(const vec_basic &vec) const;
|
181
|
+
bool __eq__(const PyFunctionClass &x) const;
|
182
|
+
int compare(const PyFunctionClass &x) const;
|
183
|
+
hash_t hash() const;
|
184
|
+
};
|
185
|
+
|
186
|
+
/*! Class to represent the parent class for a PyFunction. Stores
|
187
|
+
* a python reference `pyobject_` to a python callable object.
|
188
|
+
* A PyFunction instance is an instance of the parent PyFunctionClass's
|
189
|
+
* `pyobject_`.
|
190
|
+
* */
|
191
|
+
class PyFunction : public FunctionWrapper {
|
192
|
+
private:
|
193
|
+
RCP<const PyFunctionClass> pyfunction_class_;
|
194
|
+
PyObject *pyobject_;
|
195
|
+
public:
|
196
|
+
PyFunction(const vec_basic &vec, const RCP<const PyFunctionClass> &pyfunc_class,
|
197
|
+
PyObject *pyobject);
|
198
|
+
~PyFunction();
|
199
|
+
|
200
|
+
PyObject *get_py_object() const;
|
201
|
+
RCP<const PyFunctionClass> get_pyfunction_class() const;
|
202
|
+
//! Create an instance of similar type with arguments `x`.
|
203
|
+
virtual RCP<const Basic> create(const vec_basic &x) const;
|
204
|
+
//! Eval the number to bits precision and return a SymEngine::Number type
|
205
|
+
virtual RCP<const Number> eval(long bits) const;
|
206
|
+
/*! Evaluate the derivative w.r.t. `x` by calling the callback function
|
207
|
+
* of the module that this function belongs to.
|
208
|
+
* */
|
209
|
+
virtual RCP<const Basic> diff_impl(const RCP<const Symbol> &x) const;
|
210
|
+
virtual int compare(const Basic &o) const;
|
211
|
+
virtual bool __eq__(const Basic &o) const;
|
212
|
+
virtual hash_t __hash__() const;
|
213
|
+
};
|
214
|
+
|
215
|
+
std::string wrapper_dumps(const Basic &x);
|
216
|
+
RCP<const Basic> wrapper_loads(const std::string &s);
|
217
|
+
|
218
|
+
}
|
219
|
+
|
220
|
+
#endif //SYMENGINE_PYWRAPPER_H
|