symengine 0.14.0__cp313-cp313t-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 (50) hide show
  1. symengine/lib/flint-19.dll +0 -0
  2. symengine/lib/libgcc_s_seh-1.dll +0 -0
  3. symengine/lib/libgmp-10.dll +0 -0
  4. symengine/lib/libmpc-3.dll +0 -0
  5. symengine/lib/libmpfr-6.dll +0 -0
  6. symengine/lib/libwinpthread-1.dll +0 -0
  7. symengine/lib/pywrapper.h +220 -0
  8. symengine/lib/symengine.pxd +955 -0
  9. symengine/lib/symengine_wrapper.cp313t-win_amd64.lib +0 -0
  10. symengine/lib/symengine_wrapper.cp313t-win_amd64.pyd +0 -0
  11. symengine/lib/symengine_wrapper.pxd +78 -0
  12. symengine/lib/zlib.dll +0 -0
  13. symengine/lib/zstd.dll +0 -0
  14. symengine-0.14.0.data/purelib/symengine/__init__.py +79 -0
  15. symengine-0.14.0.data/purelib/symengine/functions.py +10 -0
  16. symengine-0.14.0.data/purelib/symengine/lib/__init__.py +0 -0
  17. symengine-0.14.0.data/purelib/symengine/printing.py +33 -0
  18. symengine-0.14.0.data/purelib/symengine/sympy_compat.py +4 -0
  19. symengine-0.14.0.data/purelib/symengine/test_utilities.py +95 -0
  20. symengine-0.14.0.data/purelib/symengine/tests/__init__.py +0 -0
  21. symengine-0.14.0.data/purelib/symengine/tests/test_arit.py +261 -0
  22. symengine-0.14.0.data/purelib/symengine/tests/test_cse.py +17 -0
  23. symengine-0.14.0.data/purelib/symengine/tests/test_dict_basic.py +28 -0
  24. symengine-0.14.0.data/purelib/symengine/tests/test_eval.py +67 -0
  25. symengine-0.14.0.data/purelib/symengine/tests/test_expr.py +28 -0
  26. symengine-0.14.0.data/purelib/symengine/tests/test_functions.py +432 -0
  27. symengine-0.14.0.data/purelib/symengine/tests/test_lambdify.py +863 -0
  28. symengine-0.14.0.data/purelib/symengine/tests/test_logic.py +124 -0
  29. symengine-0.14.0.data/purelib/symengine/tests/test_matrices.py +757 -0
  30. symengine-0.14.0.data/purelib/symengine/tests/test_ntheory.py +254 -0
  31. symengine-0.14.0.data/purelib/symengine/tests/test_number.py +186 -0
  32. symengine-0.14.0.data/purelib/symengine/tests/test_pickling.py +59 -0
  33. symengine-0.14.0.data/purelib/symengine/tests/test_printing.py +38 -0
  34. symengine-0.14.0.data/purelib/symengine/tests/test_sage.py +175 -0
  35. symengine-0.14.0.data/purelib/symengine/tests/test_series_expansion.py +22 -0
  36. symengine-0.14.0.data/purelib/symengine/tests/test_sets.py +118 -0
  37. symengine-0.14.0.data/purelib/symengine/tests/test_solve.py +25 -0
  38. symengine-0.14.0.data/purelib/symengine/tests/test_subs.py +82 -0
  39. symengine-0.14.0.data/purelib/symengine/tests/test_symbol.py +179 -0
  40. symengine-0.14.0.data/purelib/symengine/tests/test_sympify.py +63 -0
  41. symengine-0.14.0.data/purelib/symengine/tests/test_sympy_compat.py +200 -0
  42. symengine-0.14.0.data/purelib/symengine/tests/test_sympy_conv.py +835 -0
  43. symengine-0.14.0.data/purelib/symengine/tests/test_var.py +68 -0
  44. symengine-0.14.0.data/purelib/symengine/utilities.py +280 -0
  45. symengine-0.14.0.dist-info/AUTHORS +40 -0
  46. symengine-0.14.0.dist-info/LICENSE +430 -0
  47. symengine-0.14.0.dist-info/METADATA +39 -0
  48. symengine-0.14.0.dist-info/RECORD +50 -0
  49. symengine-0.14.0.dist-info/WHEEL +5 -0
  50. symengine-0.14.0.dist-info/top_level.txt +1 -0
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -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