diff --git a/.gitignore b/.gitignore index 1ef1e18ed..f93c02277 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ cython_test.cpp *.vcxproj *.filters symengine/lib/symengine_wrapper.cpp +symengine/lib/symengine_wrapper.pyx +symengine/lib/symengine_wrapper.pxd # Config Files symengine/lib/config.pxi diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake index 318f58e48..beac6c568 100644 --- a/cmake/FindCython.cmake +++ b/cmake/FindCython.cmake @@ -63,26 +63,13 @@ if(NOT CYTHON_INCLUDE_DIRECTORIES) endif(NOT CYTHON_INCLUDE_DIRECTORIES) # Cythonizes the .pyx files into .cpp file (but doesn't compile it) -macro(CYTHON_ADD_MODULE_PYX name) - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pxd) - set(DEPENDS ${name}.pyx ${name}.pxd) - else(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pxd) - set(DEPENDS ${name}.pyx) - endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pxd) +macro(CYTHON_ADD_MODULE_PYX cpp_name pyx_name) # Allow the user to specify dependencies as optional arguments set(DEPENDS ${DEPENDS} ${ARGN}) add_custom_command( - OUTPUT ${name}.cpp + OUTPUT ${cpp_name} COMMAND ${CYTHON_BIN} - ARGS ${CYTHON_FLAGS} -I ${CYTHON_INCLUDE_DIRECTORIES} -o ${name}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pyx - DEPENDS ${DEPENDS} - COMMENT "Cythonizing ${name}.pyx") + ARGS ${CYTHON_FLAGS} -I ${CYTHON_INCLUDE_DIRECTORIES} -o ${cpp_name} ${pyx_name} + DEPENDS ${DEPENDS} ${pyx_name} + COMMENT "Cythonizing ${pyx_name}") endmacro(CYTHON_ADD_MODULE_PYX) - -# Cythonizes and compiles a .pyx file -macro(CYTHON_ADD_MODULE name) - CYTHON_ADD_MODULE_PYX(${name}) - # We need Python for this: - find_package(Python REQUIRED) - add_python_library(${name} ${name}.cpp ${ARGN}) -endmacro(CYTHON_ADD_MODULE) diff --git a/cmake/preprocess.py b/cmake/preprocess.py new file mode 100644 index 000000000..a99d24898 --- /dev/null +++ b/cmake/preprocess.py @@ -0,0 +1,38 @@ +import sys + + +def main(input_name, output_name, replacements): + replacements = dict((item.split("=")[0], item.split("=")[1] == "True") for item in replacements) + with open(input_name, "r") as inp: + text = inp.readlines() + + new_text = [] + in_cond = [True] + nspaces = [0] + for i, line in enumerate(text): + if line.strip().startswith("IF"): + s = len(line) - len(line.lstrip()) + while s <= nspaces[-1] and len(in_cond) > 1: + in_cond = in_cond[:-1] + nspaces = nspaces[:-1] + + cond = line.lstrip()[3:-2] + in_cond.append(replacements[cond]) + nspaces.append(s) + elif line.strip().startswith("ELSE"): + in_cond[-1] = not in_cond[-1] and in_cond[-2] + + if len(line) > 1 and not line.strip().startswith(("IF", "ELSE")): + while len(in_cond) > 1 and (len(line) <= nspaces[-1] or not line.startswith(" "*nspaces[-1]) or line[nspaces[-1]] != " "): + in_cond = in_cond[:-1] + nspaces = nspaces[:-1] + if len(line) == 1: + new_text.append(line) + elif in_cond[-1] and not line.strip().startswith(("IF", "ELSE")): + new_text.append(line[4*(len(in_cond) - 1):]) + + with open(output_name, "w") as out: + out.writelines(new_text) + +if __name__ == "__main__": + main(sys.argv[1], sys.argv[2], sys.argv[3:]) diff --git a/symengine/lib/CMakeLists.txt b/symengine/lib/CMakeLists.txt index bf5cc9f80..7683d4aa8 100644 --- a/symengine/lib/CMakeLists.txt +++ b/symengine/lib/CMakeLists.txt @@ -1,13 +1,47 @@ set(SRC - symengine_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.cpp pywrapper.cpp ) -configure_file(config.pxi.in config.pxi) +include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) -include_directories(BEFORE ${python_wrapper_BINARY_DIR}/symengine/lib) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pxd + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/symengine_wrapper.in.pxd + ${PROJECT_SOURCE_DIR}/cmake/preprocess.py + COMMAND ${PYTHON_BIN} ${PROJECT_SOURCE_DIR}/cmake/preprocess.py + ${CMAKE_CURRENT_SOURCE_DIR}/symengine_wrapper.in.pxd + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pxd + HAVE_SYMENGINE_MPFR=${HAVE_SYMENGINE_MPFR} + HAVE_SYMENGINE_MPC=${HAVE_SYMENGINE_MPC} + HAVE_SYMENGINE_PIRANHA=${HAVE_SYMENGINE_PIRANHA} + HAVE_SYMENGINE_FLINT=${HAVE_SYMENGINE_FLINT} + HAVE_SYMENGINE_LLVM=${HAVE_SYMENGINE_LLVM} + HAVE_SYMENGINE_LLVM_LONG_DOUBLE=${HAVE_SYMENGINE_LLVM_LONG_DOUBLE} + COMMENT "Preprocessing symengine_wrapper.in.pxd" +) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pyx + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/symengine_wrapper.in.pyx + ${CMAKE_CURRENT_SOURCE_DIR}/symengine_wrapper.in.pxd + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pxd + ${PROJECT_SOURCE_DIR}/cmake/preprocess.py + COMMAND ${PYTHON_BIN} ${PROJECT_SOURCE_DIR}/cmake/preprocess.py + ${CMAKE_CURRENT_SOURCE_DIR}/symengine_wrapper.in.pyx + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pyx + HAVE_SYMENGINE_MPFR=${HAVE_SYMENGINE_MPFR} + HAVE_SYMENGINE_MPC=${HAVE_SYMENGINE_MPC} + HAVE_SYMENGINE_PIRANHA=${HAVE_SYMENGINE_PIRANHA} + HAVE_SYMENGINE_FLINT=${HAVE_SYMENGINE_FLINT} + HAVE_SYMENGINE_LLVM=${HAVE_SYMENGINE_LLVM} + HAVE_SYMENGINE_LLVM_LONG_DOUBLE=${HAVE_SYMENGINE_LLVM_LONG_DOUBLE} + COMMENT "Preprocessing symengine_wrapper.in.pyx" +) -cython_add_module_pyx(symengine_wrapper symengine.pxd) +cython_add_module_pyx(symengine_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pyx + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pxd + ${CMAKE_CURRENT_SOURCE_DIR}/symengine.pxd) add_python_library(symengine_wrapper ${SRC}) target_link_libraries(symengine_wrapper ${SYMENGINE_LIBRARIES}) if (CMAKE_CXX_COMPILER_ID MATCHES GNU|Clang) @@ -18,10 +52,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU|Clang) ) endif() -add_custom_target(cython - COMMAND cython symengine_wrapper.pyx - ) - set(PY_PATH ${PYTHON_INSTALL_PATH}/symengine/lib) install(TARGETS symengine_wrapper RUNTIME DESTINATION ${PY_PATH} @@ -29,9 +59,8 @@ install(TARGETS symengine_wrapper LIBRARY DESTINATION ${PY_PATH} ) install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/config.pxi symengine.pxd - symengine_wrapper.pxd + ${CMAKE_CURRENT_BINARY_DIR}/symengine_wrapper.pxd pywrapper.h DESTINATION ${PY_PATH} ) diff --git a/symengine/lib/config.pxi.in b/symengine/lib/config.pxi.in deleted file mode 100644 index 26a33012e..000000000 --- a/symengine/lib/config.pxi.in +++ /dev/null @@ -1,6 +0,0 @@ -DEF HAVE_SYMENGINE_MPFR = ${HAVE_SYMENGINE_MPFR} -DEF HAVE_SYMENGINE_MPC = ${HAVE_SYMENGINE_MPC} -DEF HAVE_SYMENGINE_PIRANHA = ${HAVE_SYMENGINE_PIRANHA} -DEF HAVE_SYMENGINE_FLINT = ${HAVE_SYMENGINE_FLINT} -DEF HAVE_SYMENGINE_LLVM = ${HAVE_SYMENGINE_LLVM} -DEF HAVE_SYMENGINE_LLVM_LONG_DOUBLE = ${HAVE_SYMENGINE_LLVM_LONG_DOUBLE} diff --git a/symengine/lib/symengine.pxd b/symengine/lib/symengine.pxd index ff5cd7728..ee96731ba 100644 --- a/symengine/lib/symengine.pxd +++ b/symengine/lib/symengine.pxd @@ -4,8 +4,21 @@ from libcpp.map cimport map from libcpp.vector cimport vector from cpython.ref cimport PyObject from libcpp.pair cimport pair +from libcpp.set cimport set +from libcpp.unordered_map cimport unordered_map -include "config.pxi" +cdef extern from "" namespace "std": + # Cython's libcpp.set does not support multiset in 0.29.x + cdef cppclass multiset[T]: + cppclass iterator: + T& operator*() + iterator operator++() nogil + iterator operator--() nogil + bint operator==(iterator) nogil + bint operator!=(iterator) nogil + iterator begin() nogil + iterator end() nogil + iterator insert(T&) nogil cdef extern from 'symengine/mp_class.h' namespace "SymEngine": ctypedef unsigned long mp_limb_t @@ -31,94 +44,6 @@ cdef extern from 'symengine/mp_class.h' namespace "SymEngine": rational_class(mpq_t) const mpq_t get_mpq_t(const rational_class &a) -cdef extern from "" namespace "std": -# Cython's libcpp.set does not support two template arguments to set. -# Methods to declare and iterate a set with a custom compare are given here - cdef cppclass set[T, U]: - cppclass iterator: - T& operator*() - iterator operator++() nogil - iterator operator--() nogil - bint operator==(iterator) nogil - bint operator!=(iterator) nogil - iterator begin() nogil - iterator end() nogil - iterator insert(T&) nogil - - cdef cppclass multiset[T, U]: - cppclass iterator: - T& operator*() - iterator operator++() nogil - iterator operator--() nogil - bint operator==(iterator) nogil - bint operator!=(iterator) nogil - iterator begin() nogil - iterator end() nogil - iterator insert(T&) nogil - -cdef extern from "" namespace "std" nogil: - cdef cppclass unordered_map[T, U]: - cppclass iterator: - pair[T, U]& operator*() - iterator operator++() - iterator operator--() - bint operator==(iterator) - bint operator!=(iterator) - cppclass reverse_iterator: - pair[T, U]& operator*() - iterator operator++() - iterator operator--() - bint operator==(reverse_iterator) - bint operator!=(reverse_iterator) - cppclass const_iterator(iterator): - pass - cppclass const_reverse_iterator(reverse_iterator): - pass - unordered_map() except + - unordered_map(unordered_map&) except + - #unordered_map(key_compare&) - U& operator[](T&) - #unordered_map& operator=(unordered_map&) - bint operator==(unordered_map&, unordered_map&) - bint operator!=(unordered_map&, unordered_map&) - bint operator<(unordered_map&, unordered_map&) - bint operator>(unordered_map&, unordered_map&) - bint operator<=(unordered_map&, unordered_map&) - bint operator>=(unordered_map&, unordered_map&) - U& at(T&) - iterator begin() - const_iterator const_begin "begin"() - void clear() - size_t count(T&) - bint empty() - iterator end() - const_iterator const_end "end"() - pair[iterator, iterator] equal_range(T&) - #pair[const_iterator, const_iterator] equal_range(key_type&) - void erase(iterator) - void erase(iterator, iterator) - size_t erase(T&) - iterator find(T&) - const_iterator const_find "find"(T&) - pair[iterator, bint] insert(pair[T, U]) # XXX pair[T,U]& - iterator insert(iterator, pair[T, U]) # XXX pair[T,U]& - #void insert(input_iterator, input_iterator) - #key_compare key_comp() - iterator lower_bound(T&) - const_iterator const_lower_bound "lower_bound"(T&) - size_t max_size() - reverse_iterator rbegin() - const_reverse_iterator const_rbegin "rbegin"() - reverse_iterator rend() - const_reverse_iterator const_rend "rend"() - size_t size() - void swap(unordered_map&) - iterator upper_bound(T&) - const_iterator const_upper_bound "upper_bound"(T&) - #value_compare value_comp() - void max_load_factor(float) - float max_load_factor() - cdef extern from "" namespace "SymEngine": cdef enum ENull: null @@ -126,17 +51,22 @@ cdef extern from "" namespace "SymEngine": cdef cppclass RCP[T]: T& operator*() nogil # Not yet supported in Cython: -# RCP[T]& operator=(RCP[T] &r_ptr) nogil except + - void reset() nogil except + +# RCP[T]& operator=(RCP[T] &r_ptr) except+ nogil + void reset() except+ nogil cdef cppclass Ptr[T]: - T& operator*() nogil except + + T& operator*() except+ nogil void print_stack_on_segfault() nogil cdef extern from "" namespace "SymEngine": ctypedef Basic const_Basic "const SymEngine::Basic" - ctypedef RCP[const Basic] rcp_const_basic "SymEngine::RCP" + # RCP[const_Basic] instead of RCP[const Basic] is because of https://github.com/cython/cython/issues/5478 + ctypedef RCP[const_Basic] rcp_const_basic "SymEngine::RCP" + #cdef cppclass rcp_const_basic "SymEngine::RCP": + # Basic& operator*() nogil + # void reset() except+ nogil + # pass # Cython has broken support for the following: # ctypedef map[rcp_const_basic, rcp_const_basic] map_basic_basic # So instead we replicate the map features we need here @@ -178,11 +108,12 @@ cdef extern from "" namespace "SymEngine": ctypedef map[RCP[Integer], unsigned] map_integer_uint "SymEngine::map_integer_uint" cdef struct RCPIntegerKeyLess cdef struct RCPBasicKeyLess - ctypedef set[rcp_const_basic, RCPBasicKeyLess] set_basic "SymEngine::set_basic" - ctypedef multiset[rcp_const_basic, RCPBasicKeyLess] multiset_basic "SymEngine::multiset_basic" + ctypedef set[rcp_const_basic] set_basic "SymEngine::set_basic" + ctypedef multiset[rcp_const_basic] multiset_basic "SymEngine::multiset_basic" + cdef cppclass Basic: - string __str__() nogil except + - unsigned int hash() nogil except + + string __str__() except+ nogil + unsigned int hash() except+ nogil vec_basic get_args() nogil int __cmp__(const Basic &o) nogil @@ -193,11 +124,11 @@ cdef extern from "" namespace "SymEngine": ctypedef unordered_map[rcp_const_basic, rcp_const_number].iterator umap_basic_num_iterator "SymEngine::umap_basic_num::iterator" ctypedef vector[pair[rcp_const_basic, rcp_const_basic]] vec_pair "SymEngine::vec_pair" - bool eq(const Basic &a, const Basic &b) nogil except + - bool neq(const Basic &a, const Basic &b) nogil except + + bool eq(const Basic &a, const Basic &b) except+ nogil + bool neq(const Basic &a, const Basic &b) except+ nogil RCP[const Symbol] rcp_static_cast_Symbol "SymEngine::rcp_static_cast"(rcp_const_basic &b) nogil - RCP[const PySymbol] rcp_static_cast_PySymbol "SymEngine::rcp_static_cast"(rcp_const_basic &b) nogil except + + RCP[const PySymbol] rcp_static_cast_PySymbol "SymEngine::rcp_static_cast"(rcp_const_basic &b) except+ nogil RCP[const Integer] rcp_static_cast_Integer "SymEngine::rcp_static_cast"(rcp_const_basic &b) nogil RCP[const Rational] rcp_static_cast_Rational "SymEngine::rcp_static_cast"(rcp_const_basic &b) nogil RCP[const Complex] rcp_static_cast_Complex "SymEngine::rcp_static_cast"(rcp_const_basic &b) nogil @@ -229,100 +160,12 @@ cdef extern from "" namespace "SymEngine": Ptr[RCP[Basic]] outArg(rcp_const_basic &arg) nogil Ptr[RCP[Integer]] outArg_Integer "SymEngine::outArg>"(RCP[const Integer] &arg) nogil - bool is_a_Add "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Mul "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Pow "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Integer "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Rational "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Complex "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Symbol "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Dummy "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Constant "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Infty "SymEngine::is_a"(const Basic &b) nogil - bool is_a_NaN "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Sin "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Cos "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Tan "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Cot "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Csc "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Sec "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ASin "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACos "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ATan "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACot "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACsc "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ASec "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Sinh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Cosh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Tanh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Coth "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Csch "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Sech "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ASinh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACosh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ATanh "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACoth "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ACsch "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ASech "SymEngine::is_a"(const Basic &b) nogil - bool is_a_FunctionSymbol "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Abs "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Max "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Min "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Gamma "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Derivative "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Subs "SymEngine::is_a"(const Basic &b) nogil - bool is_a_PyFunction "SymEngine::is_a"(const Basic &b) nogil - bool is_a_RealDouble "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ComplexDouble "SymEngine::is_a"(const Basic &b) nogil - bool is_a_RealMPFR "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ComplexMPC "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Log "SymEngine::is_a"(const Basic &b) nogil - bool is_a_BooleanAtom "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Equality "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Unequality "SymEngine::is_a"(const Basic &b) nogil - bool is_a_LessThan "SymEngine::is_a"(const Basic &b) nogil - bool is_a_StrictLessThan "SymEngine::is_a"(const Basic &b) nogil - bool is_a_PyNumber "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ATan2 "SymEngine::is_a"(const Basic &b) nogil - bool is_a_LambertW "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Zeta "SymEngine::is_a"(const Basic &b) nogil - bool is_a_DirichletEta "SymEngine::is_a"(const Basic &b) nogil - bool is_a_KroneckerDelta "SymEngine::is_a"(const Basic &b) nogil - bool is_a_LeviCivita "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Erf "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Erfc "SymEngine::is_a"(const Basic &b) nogil - bool is_a_LowerGamma "SymEngine::is_a"(const Basic &b) nogil - bool is_a_UpperGamma "SymEngine::is_a"(const Basic &b) nogil - bool is_a_LogGamma "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Beta "SymEngine::is_a"(const Basic &b) nogil - bool is_a_PolyGamma "SymEngine::is_a"(const Basic &b) nogil - bool is_a_PySymbol "SymEngine::is_a_sub"(const Basic &b) nogil - bool is_a_Sign "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Floor "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Ceiling "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Conjugate "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Interval "SymEngine::is_a"(const Basic &b) nogil - bool is_a_EmptySet "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Reals "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Rationals "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Integers "SymEngine::is_a"(const Basic &b) nogil - bool is_a_UniversalSet "SymEngine::is_a"(const Basic &b) nogil - bool is_a_FiniteSet "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Union "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Complement "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ConditionSet "SymEngine::is_a"(const Basic &b) nogil - bool is_a_ImageSet "SymEngine::is_a"(const Basic &b) nogil - bool is_a_UnevaluatedExpr "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Piecewise "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Contains "SymEngine::is_a"(const Basic &b) nogil - bool is_a_And "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Not "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Or "SymEngine::is_a"(const Basic &b) nogil - bool is_a_Xor "SymEngine::is_a"(const Basic &b) nogil - rcp_const_basic expand(rcp_const_basic &o, bool deep) nogil except + + bool is_a[T] (const Basic &b) nogil + bool is_a_sub[T] (const Basic &b) nogil + rcp_const_basic expand(rcp_const_basic &o, bool deep) except+ nogil void as_numer_denom(rcp_const_basic &x, const Ptr[RCP[Basic]] &numer, const Ptr[RCP[Basic]] &denom) nogil void as_real_imag(rcp_const_basic &x, const Ptr[RCP[Basic]] &real, const Ptr[RCP[Basic]] &imag) nogil - void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) nogil except + + void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) except+ nogil cdef extern from "" namespace "SymEngine": rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) nogil @@ -330,7 +173,7 @@ cdef extern from "" namespace "SymEngine": rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) nogil cdef extern from "" namespace "SymEngine": - rcp_const_basic diff "SymEngine::sdiff"(rcp_const_basic &arg, rcp_const_basic &x) nogil except + + rcp_const_basic diff "SymEngine::sdiff"(rcp_const_basic &arg, rcp_const_basic &x) except+ nogil cdef extern from "" namespace "SymEngine": cdef cppclass Symbol(Basic): @@ -372,8 +215,8 @@ cdef extern from "pywrapper.h" namespace "SymEngine": PySymbol(string name, PyObject* pyobj, bool use_pickle) except + PyObject* get_py_object() except + - string wrapper_dumps(const Basic &x) nogil except + - rcp_const_basic wrapper_loads(const string &s) nogil except + + string wrapper_dumps(const Basic &x) except+ nogil + rcp_const_basic wrapper_loads(const string &s) except+ nogil cdef extern from "" namespace "SymEngine": cdef cppclass Integer(Number): @@ -443,9 +286,9 @@ cdef extern from "" namespace "SymEngine": pass cdef extern from "" namespace "SymEngine": - cdef rcp_const_basic add(rcp_const_basic &a, rcp_const_basic &b) nogil except+ - cdef rcp_const_basic sub(rcp_const_basic &a, rcp_const_basic &b) nogil except+ - cdef rcp_const_basic add(const vec_basic &a) nogil except+ + cdef rcp_const_basic add(rcp_const_basic &a, rcp_const_basic &b) except+ nogil + cdef rcp_const_basic sub(rcp_const_basic &a, rcp_const_basic &b) except+ nogil + cdef rcp_const_basic add(const vec_basic &a) except+ nogil cdef cppclass Add(Basic): void as_two_terms(const Ptr[RCP[Basic]] &a, const Ptr[RCP[Basic]] &b) @@ -453,21 +296,21 @@ cdef extern from "" namespace "SymEngine": const umap_basic_num &get_dict() cdef extern from "" namespace "SymEngine": - cdef rcp_const_basic mul(rcp_const_basic &a, rcp_const_basic &b) nogil except+ - cdef rcp_const_basic div(rcp_const_basic &a, rcp_const_basic &b) nogil except+ - cdef rcp_const_basic neg(rcp_const_basic &a) nogil except+ - cdef rcp_const_basic mul(const vec_basic &a) nogil except+ + cdef rcp_const_basic mul(rcp_const_basic &a, rcp_const_basic &b) except+ nogil + cdef rcp_const_basic div(rcp_const_basic &a, rcp_const_basic &b) except+ nogil + cdef rcp_const_basic neg(rcp_const_basic &a) except+ nogil + cdef rcp_const_basic mul(const vec_basic &a) except+ nogil cdef cppclass Mul(Basic): void as_two_terms(const Ptr[RCP[Basic]] &a, const Ptr[RCP[Basic]] &b) RCP[const Number] get_coef() const map_basic_basic &get_dict() - cdef RCP[const Mul] mul_from_dict "SymEngine::Mul::from_dict"(RCP[const Number] coef, map_basic_basic &&d) nogil + cdef RCP[const Mul] mul_from_dict "SymEngine::Mul::from_dict"(RCP[const Number] coef, map_basic_basic &d) nogil cdef extern from "" namespace "SymEngine": - cdef rcp_const_basic pow(rcp_const_basic &a, rcp_const_basic &b) nogil except+ - cdef rcp_const_basic sqrt(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic exp(rcp_const_basic &x) nogil except+ + cdef rcp_const_basic pow(rcp_const_basic &a, rcp_const_basic &b) except+ nogil + cdef rcp_const_basic sqrt(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic exp(rcp_const_basic &x) except+ nogil cdef cppclass Pow(Basic): rcp_const_basic get_base() nogil @@ -491,9 +334,9 @@ cdef extern from "" namespace "SymEngine": void (*dec_ref)(void *), int (*comp)(void *, void *)) nogil rcp_const_basic make_rcp_RealDouble "SymEngine::make_rcp"(double x) nogil rcp_const_basic make_rcp_ComplexDouble "SymEngine::make_rcp"(double complex x) nogil - RCP[const PyModule] make_rcp_PyModule "SymEngine::make_rcp"(PyObject* (*) (rcp_const_basic x), \ - rcp_const_basic (*)(PyObject*), RCP[const Number] (*)(PyObject*, long bits), - rcp_const_basic (*)(PyObject*, rcp_const_basic)) nogil + RCP[const PyModule] make_rcp_PyModule "SymEngine::make_rcp"(PyObject* (*) (rcp_const_basic x) except +, \ + rcp_const_basic (*)(PyObject*) except +, RCP[const Number] (*)(PyObject*, long bits) except +, + rcp_const_basic (*)(PyObject*, rcp_const_basic) except +) except + rcp_const_basic make_rcp_PyNumber "SymEngine::make_rcp"(PyObject*, RCP[const PyModule] x) nogil RCP[const PyFunctionClass] make_rcp_PyFunctionClass "SymEngine::make_rcp"(PyObject* pyobject, string name, RCP[const PyModule] pymodule) nogil @@ -501,58 +344,58 @@ cdef extern from "" namespace "SymEngine": RCP[const PyFunctionClass] pyfunc_class, const PyObject* pyobject) nogil cdef extern from "" namespace "SymEngine": - cdef rcp_const_basic sin(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic cos(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic tan(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic cot(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic csc(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic sec(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic asin(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acos(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic atan(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acot(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acsc(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic asec(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic sinh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic cosh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic tanh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic coth(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic csch(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic sech(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic asinh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acosh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic atanh(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acoth(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic acsch(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic asech(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic function_symbol(string name, const vec_basic &arg) nogil except+ - cdef rcp_const_basic abs(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic max(const vec_basic &arg) nogil except+ - cdef rcp_const_basic min(const vec_basic &arg) nogil except+ - cdef rcp_const_basic gamma(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic atan2(rcp_const_basic &num, rcp_const_basic &den) nogil except+ - cdef rcp_const_basic lambertw(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic zeta(rcp_const_basic &s) nogil except+ - cdef rcp_const_basic zeta(rcp_const_basic &s, rcp_const_basic &a) nogil except+ - cdef rcp_const_basic dirichlet_eta(rcp_const_basic &s) nogil except+ - cdef rcp_const_basic kronecker_delta(rcp_const_basic &i, rcp_const_basic &j) nogil except+ - cdef rcp_const_basic levi_civita(const vec_basic &arg) nogil except+ - cdef rcp_const_basic erf(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic erfc(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic lowergamma(rcp_const_basic &s, rcp_const_basic &x) nogil except+ - cdef rcp_const_basic uppergamma(rcp_const_basic &s, rcp_const_basic &x) nogil except+ - cdef rcp_const_basic loggamma(rcp_const_basic &arg) nogil except+ - cdef rcp_const_basic beta(rcp_const_basic &x, rcp_const_basic &y) nogil except+ - cdef rcp_const_basic polygamma(rcp_const_basic &n, rcp_const_basic &x) nogil except+ - cdef rcp_const_basic digamma(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic trigamma(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic sign(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic floor(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic ceiling(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic conjugate(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic log(rcp_const_basic &x) nogil except+ - cdef rcp_const_basic log(rcp_const_basic &x, rcp_const_basic &y) nogil except+ - cdef rcp_const_basic unevaluated_expr(rcp_const_basic &x) nogil except+ + cdef rcp_const_basic sin(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic cos(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic tan(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic cot(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic csc(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic sec(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic asin(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acos(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic atan(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acot(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acsc(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic asec(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic sinh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic cosh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic tanh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic coth(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic csch(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic sech(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic asinh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acosh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic atanh(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acoth(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic acsch(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic asech(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic function_symbol(string name, const vec_basic &arg) except+ nogil + cdef rcp_const_basic abs(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic max(const vec_basic &arg) except+ nogil + cdef rcp_const_basic min(const vec_basic &arg) except+ nogil + cdef rcp_const_basic gamma(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic atan2(rcp_const_basic &num, rcp_const_basic &den) except+ nogil + cdef rcp_const_basic lambertw(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic zeta(rcp_const_basic &s) except+ nogil + cdef rcp_const_basic zeta(rcp_const_basic &s, rcp_const_basic &a) except+ nogil + cdef rcp_const_basic dirichlet_eta(rcp_const_basic &s) except+ nogil + cdef rcp_const_basic kronecker_delta(rcp_const_basic &i, rcp_const_basic &j) except+ nogil + cdef rcp_const_basic levi_civita(const vec_basic &arg) except+ nogil + cdef rcp_const_basic erf(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic erfc(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic lowergamma(rcp_const_basic &s, rcp_const_basic &x) except+ nogil + cdef rcp_const_basic uppergamma(rcp_const_basic &s, rcp_const_basic &x) except+ nogil + cdef rcp_const_basic loggamma(rcp_const_basic &arg) except+ nogil + cdef rcp_const_basic beta(rcp_const_basic &x, rcp_const_basic &y) except+ nogil + cdef rcp_const_basic polygamma(rcp_const_basic &n, rcp_const_basic &x) except+ nogil + cdef rcp_const_basic digamma(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic trigamma(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic sign(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic floor(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic ceiling(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic conjugate(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic log(rcp_const_basic &x) except+ nogil + cdef rcp_const_basic log(rcp_const_basic &x, rcp_const_basic &y) except+ nogil + cdef rcp_const_basic unevaluated_expr(rcp_const_basic &x) except+ nogil cdef cppclass Function(Basic): pass @@ -720,71 +563,68 @@ cdef extern from "" namespace "SymEngine": cdef cppclass Conjugate(OneArgFunction): pass + cdef cppclass UnevaluatedExpr(OneArgFunction): + pass + cdef cppclass Log(Function): pass -IF HAVE_SYMENGINE_MPFR: - cdef extern from "mpfr.h": - ctypedef struct __mpfr_struct: - pass - ctypedef __mpfr_struct mpfr_t[1] - ctypedef __mpfr_struct* mpfr_ptr - ctypedef const __mpfr_struct* mpfr_srcptr - ctypedef long mpfr_prec_t - ctypedef enum mpfr_rnd_t: - MPFR_RNDN - MPFR_RNDZ - MPFR_RNDU - MPFR_RNDD - MPFR_RNDA - MPFR_RNDF - MPFR_RNDNA - - cdef extern from "" namespace "SymEngine": - cdef cppclass mpfr_class: - mpfr_class() nogil - mpfr_class(mpfr_prec_t prec) nogil - mpfr_class(string s, mpfr_prec_t prec, unsigned base) nogil - mpfr_class(mpfr_t m) nogil - mpfr_ptr get_mpfr_t() nogil - - cdef cppclass RealMPFR(Number): - RealMPFR(mpfr_class) nogil - mpfr_class as_mpfr() nogil - mpfr_prec_t get_prec() nogil - - RCP[const RealMPFR] real_mpfr(mpfr_class t) nogil -ELSE: - cdef extern from "" namespace "SymEngine": - cdef cppclass RealMPFR(Number): - pass - -IF HAVE_SYMENGINE_MPC: - cdef extern from "mpc.h": - ctypedef struct __mpc_struct: - pass - ctypedef __mpc_struct mpc_t[1] - ctypedef __mpc_struct* mpc_ptr - ctypedef const __mpc_struct* mpc_srcptr - - cdef extern from "" namespace "SymEngine": - cdef cppclass mpc_class: - mpc_class() nogil - mpc_class(mpfr_prec_t prec) nogil - mpc_class(mpc_t m) nogil - mpc_ptr get_mpc_t() nogil - mpc_class(string s, mpfr_prec_t prec, unsigned base) nogil - - cdef cppclass ComplexMPC(ComplexBase): - ComplexMPC(mpc_class) nogil - mpc_class as_mpc() nogil - mpfr_prec_t get_prec() nogil - - RCP[const ComplexMPC] complex_mpc(mpc_class t) nogil -ELSE: - cdef extern from "" namespace "SymEngine": - cdef cppclass ComplexMPC(Number): - pass +cdef extern from "": + # These come from mpfr.h, but don't include mpfr.h to not break + # builds without mpfr + ctypedef struct __mpfr_struct: + pass + ctypedef __mpfr_struct mpfr_t[1] + ctypedef __mpfr_struct* mpfr_ptr + ctypedef const __mpfr_struct* mpfr_srcptr + ctypedef long mpfr_prec_t + ctypedef enum mpfr_rnd_t: + MPFR_RNDN + MPFR_RNDZ + MPFR_RNDU + MPFR_RNDD + MPFR_RNDA + MPFR_RNDF + MPFR_RNDNA + +cdef extern from "" namespace "SymEngine": + cdef cppclass mpfr_class: + mpfr_class() nogil + mpfr_class(mpfr_prec_t prec) nogil + mpfr_class(string s, mpfr_prec_t prec, unsigned base) nogil + mpfr_class(mpfr_t m) nogil + mpfr_ptr get_mpfr_t() nogil + + cdef cppclass RealMPFR(Number): + RealMPFR(mpfr_class) nogil + mpfr_class as_mpfr() nogil + mpfr_prec_t get_prec() nogil + + RCP[const RealMPFR] real_mpfr(mpfr_class t) nogil + +cdef extern from "": + # These come from mpc.h, but don't include mpc.h to not break + # builds without mpc + ctypedef struct __mpc_struct: + pass + ctypedef __mpc_struct mpc_t[1] + ctypedef __mpc_struct* mpc_ptr + ctypedef const __mpc_struct* mpc_srcptr + +cdef extern from "" namespace "SymEngine": + cdef cppclass mpc_class: + mpc_class() nogil + mpc_class(mpfr_prec_t prec) nogil + mpc_class(mpc_t m) nogil + mpc_ptr get_mpc_t() nogil + mpc_class(string s, mpfr_prec_t prec, unsigned base) nogil + + cdef cppclass ComplexMPC(ComplexBase): + ComplexMPC(mpc_class) nogil + mpc_class as_mpc() nogil + mpfr_prec_t get_prec() nogil + + RCP[const ComplexMPC] complex_mpc(mpc_class t) nogil cdef extern from "" namespace "SymEngine": cdef cppclass MatrixBase: @@ -792,7 +632,7 @@ cdef extern from "" namespace "SymEngine": const unsigned ncols() nogil rcp_const_basic get(unsigned i, unsigned j) nogil rcp_const_basic set(unsigned i, unsigned j, rcp_const_basic e) nogil - string __str__() nogil except+ + string __str__() except+ nogil bool eq(const MatrixBase &) nogil rcp_const_basic det() nogil void inv(MatrixBase &) @@ -839,23 +679,22 @@ cdef extern from "" namespace "SymEngine": tribool is_positive_definite() nogil tribool is_negative_definite() nogil - bool is_a_DenseMatrix "SymEngine::is_a"(const MatrixBase &b) nogil DenseMatrix* static_cast_DenseMatrix "static_cast"(const MatrixBase *a) void inverse_FFLU "SymEngine::inverse_fraction_free_LU"(const DenseMatrix &A, - DenseMatrix &B) nogil except + - void pivoted_LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x) nogil except + + DenseMatrix &B) except+ nogil + void pivoted_LU_solve (const DenseMatrix &A, const DenseMatrix &b, DenseMatrix &x) except+ nogil void inverse_GJ "SymEngine::inverse_gauss_jordan"(const DenseMatrix &A, - DenseMatrix &B) nogil except + + DenseMatrix &B) except+ nogil void FFLU_solve "SymEngine::fraction_free_LU_solve"(const DenseMatrix &A, - const DenseMatrix &b, DenseMatrix &x) nogil except + + const DenseMatrix &b, DenseMatrix &x) except+ nogil void FFGJ_solve "SymEngine::fraction_free_gauss_jordan_solve"(const DenseMatrix &A, - const DenseMatrix &b, DenseMatrix &x) nogil except + + const DenseMatrix &b, DenseMatrix &x) except+ nogil void LDL_solve "SymEngine::LDL_solve"(const DenseMatrix &A, const DenseMatrix &b, - DenseMatrix &x) nogil except + + DenseMatrix &x) except+ nogil void jacobian "SymEngine::sjacobian"(const DenseMatrix &A, - const DenseMatrix &x, DenseMatrix &result) nogil except + + const DenseMatrix &x, DenseMatrix &result) except+ nogil void diff "SymEngine::sdiff"(const DenseMatrix &A, - rcp_const_basic &x, DenseMatrix &result) nogil except + + rcp_const_basic &x, DenseMatrix &result) except+ nogil void eye (DenseMatrix &A, int k) nogil void diag(DenseMatrix &A, vec_basic &v, int k) nogil void ones(DenseMatrix &A) nogil @@ -868,7 +707,7 @@ cdef extern from "" namespace "SymEngine": void cross(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &C) nogil cdef extern from "": - void pivoted_LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U, vector[pair[int, int]] &P) nogil except + + void pivoted_LU (const DenseMatrix &A, DenseMatrix &L, DenseMatrix &U, vector[pair[int, int]] &P) except+ nogil cdef extern from "" namespace "SymEngine": int probab_prime_p(const Integer &a, int reps) @@ -877,10 +716,10 @@ cdef extern from "" namespace "SymEngine": RCP[const Integer] lcm(const Integer &a, const Integer &b) nogil void gcd_ext(const Ptr[RCP[Integer]] &g, const Ptr[RCP[Integer]] &s, const Ptr[RCP[Integer]] &t, const Integer &a, const Integer &b) nogil - RCP[const Integer] mod "SymEngine::mod_f"(const Integer &n, const Integer &d) nogil except + - RCP[const Integer] quotient "SymEngine::quotient_f"(const Integer &n, const Integer &d) nogil except + + RCP[const Integer] mod "SymEngine::mod_f"(const Integer &n, const Integer &d) except+ nogil + RCP[const Integer] quotient "SymEngine::quotient_f"(const Integer &n, const Integer &d) except+ nogil void quotient_mod "SymEngine::quotient_mod_f"(const Ptr[RCP[Integer]] &q, const Ptr[RCP[Integer]] &mod, - const Integer &n, const Integer &d) nogil except + + const Integer &n, const Integer &d) except+ nogil int mod_inverse(const Ptr[RCP[Integer]] &b, const Integer &a, const Integer &m) nogil bool crt(const Ptr[RCP[Integer]] &R, const vec_integer &rem, @@ -900,9 +739,9 @@ cdef extern from "" namespace "SymEngine": unsigned B, unsigned retries) nogil int factor_pollard_rho_method(const Ptr[RCP[Integer]] &f, const Integer &n, unsigned retries) nogil - void prime_factors(vec_integer &primes, const Integer &n) nogil except + - void prime_factor_multiplicities(map_integer_uint &primes, const Integer &n) nogil except + - RCP[const Number] bernoulli(unsigned long n) nogil except + + void prime_factors(vec_integer &primes, const Integer &n) except+ nogil + void prime_factor_multiplicities(map_integer_uint &primes, const Integer &n) except+ nogil + RCP[const Number] bernoulli(unsigned long n) except+ nogil bool primitive_root(const Ptr[RCP[Integer]] &g, const Integer &n) nogil void primitive_root_list(vec_integer &roots, const Integer &n) nogil RCP[const Integer] totient(RCP[const Integer] n) nogil @@ -930,15 +769,15 @@ cdef extern from "" namespace "SymEngine": unsigned next_prime() nogil cdef extern from "" namespace "SymEngine": - bool has_symbol(const Basic &b, const Basic &x) nogil except + - rcp_const_basic coeff(const Basic &b, const Basic &x, const Basic &n) nogil except + - set_basic free_symbols(const Basic &b) nogil except + - set_basic free_symbols(const MatrixBase &b) nogil except + + bool has_symbol(const Basic &b, const Basic &x) except+ nogil + rcp_const_basic coeff(const Basic &b, const Basic &x, const Basic &n) except+ nogil + set_basic free_symbols(const Basic &b) except+ nogil + set_basic free_symbols(const MatrixBase &b) except+ nogil unsigned count_ops(const vec_basic &a) nogil cdef extern from "" namespace "SymEngine": cdef cppclass Boolean(Basic): - RCP[const Boolean] logical_not() nogil except+ + RCP[const Boolean] logical_not() except+ nogil cdef cppclass BooleanAtom(Boolean): bool get_val() nogil cdef cppclass Relational(Boolean): @@ -966,64 +805,54 @@ cdef extern from "" namespace "SymEngine": rcp_const_basic boolTrue rcp_const_basic boolFalse - bool is_a_Relational(const Basic &b) nogil - cdef RCP[const Boolean] Eq(rcp_const_basic &lhs) nogil except+ - cdef RCP[const Boolean] Eq(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ - cdef RCP[const Boolean] Ne(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ - cdef RCP[const Boolean] Ge(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ - cdef RCP[const Boolean] Gt(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ - cdef RCP[const Boolean] Le(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ - cdef RCP[const Boolean] Lt(rcp_const_basic &lhs, rcp_const_basic &rhs) nogil except+ + cdef RCP[const Boolean] Eq(rcp_const_basic &lhs) except+ nogil + cdef RCP[const Boolean] Eq(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil + cdef RCP[const Boolean] Ne(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil + cdef RCP[const Boolean] Ge(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil + cdef RCP[const Boolean] Gt(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil + cdef RCP[const Boolean] Le(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil + cdef RCP[const Boolean] Lt(rcp_const_basic &lhs, rcp_const_basic &rhs) except+ nogil ctypedef Boolean const_Boolean "const SymEngine::Boolean" ctypedef vector[pair[rcp_const_basic, RCP[const_Boolean]]] PiecewiseVec; ctypedef vector[RCP[Boolean]] vec_boolean "SymEngine::vec_boolean" - ctypedef set[RCP[Boolean], RCPBasicKeyLess] set_boolean "SymEngine::set_boolean" - cdef RCP[const Boolean] logical_and(set_boolean &s) nogil except+ - cdef RCP[const Boolean] logical_nand(set_boolean &s) nogil except+ - cdef RCP[const Boolean] logical_or(set_boolean &s) nogil except+ - cdef RCP[const Boolean] logical_not(RCP[const Boolean] &s) nogil except+ - cdef RCP[const Boolean] logical_nor(set_boolean &s) nogil except+ - cdef RCP[const Boolean] logical_xor(vec_boolean &s) nogil except+ - cdef RCP[const Boolean] logical_xnor(vec_boolean &s) nogil except+ - cdef rcp_const_basic piecewise(PiecewiseVec vec) nogil except + + ctypedef set[RCP[Boolean]] set_boolean "SymEngine::set_boolean" + cdef RCP[const Boolean] logical_and(set_boolean &s) except+ nogil + cdef RCP[const Boolean] logical_nand(set_boolean &s) except+ nogil + cdef RCP[const Boolean] logical_or(set_boolean &s) except+ nogil + cdef RCP[const Boolean] logical_not(RCP[const Boolean] &s) except+ nogil + cdef RCP[const Boolean] logical_nor(set_boolean &s) except+ nogil + cdef RCP[const Boolean] logical_xor(vec_boolean &s) except+ nogil + cdef RCP[const Boolean] logical_xnor(vec_boolean &s) except+ nogil + cdef rcp_const_basic piecewise(PiecewiseVec vec) except+ nogil cdef RCP[const Boolean] contains(rcp_const_basic &expr, RCP[const Set] &set) nogil -cdef extern from "" namespace "std": - cdef integer_class std_move_mpz "std::move" (integer_class) nogil - IF HAVE_SYMENGINE_MPFR: - cdef mpfr_class std_move_mpfr "std::move" (mpfr_class) nogil - IF HAVE_SYMENGINE_MPC: - cdef mpc_class std_move_mpc "std::move" (mpc_class) nogil - cdef map_basic_basic std_move_map_basic_basic "std::move" (map_basic_basic) nogil - cdef PiecewiseVec std_move_PiecewiseVec "std::move" (PiecewiseVec) nogil - cdef extern from "" namespace "SymEngine": cdef cppclass EvalfDomain: pass cdef EvalfDomain EvalfComplex "SymEngine::EvalfDomain::Complex" cdef EvalfDomain EvalfReal "SymEngine::EvalfDomain::Real" cdef EvalfDomain EvalfSymbolic "SymEngine::EvalfDomain::Symbolic" - rcp_const_basic evalf(const Basic &b, unsigned long bits, EvalfDomain domain) nogil except + + rcp_const_basic evalf(const Basic &b, unsigned long bits, EvalfDomain domain) except+ nogil cdef extern from "" namespace "SymEngine": - double eval_double(const Basic &b) nogil except + - double complex eval_complex_double(const Basic &b) nogil except + + double eval_double(const Basic &b) except+ nogil + double complex eval_complex_double(const Basic &b) except+ nogil cdef extern from "" namespace "SymEngine": cdef cppclass LambdaRealDoubleVisitor: LambdaRealDoubleVisitor() nogil - void init(const vec_basic &x, const vec_basic &b, bool cse) nogil except + + void init(const vec_basic &x, const vec_basic &b, bool cse) except+ nogil void call(double *r, const double *x) nogil cdef cppclass LambdaComplexDoubleVisitor: LambdaComplexDoubleVisitor() nogil - void init(const vec_basic &x, const vec_basic &b, bool cse) nogil except + + void init(const vec_basic &x, const vec_basic &b, bool cse) except+ nogil void call(double complex *r, const double complex *x) nogil cdef extern from "" namespace "SymEngine": cdef cppclass LLVMVisitor: LLVMVisitor() nogil - void init(const vec_basic &x, const vec_basic &b, bool cse, int opt_level) nogil except + + void init(const vec_basic &x, const vec_basic &b, bool cse, int opt_level) except+ nogil const string& dumps() nogil void loads(const string&) nogil @@ -1039,29 +868,27 @@ cdef extern from "" namespace "SymEngine": cdef extern from "" namespace "SymEngine": cdef cppclass SeriesCoeffInterface: - rcp_const_basic as_basic() nogil except + - umap_int_basic as_dict() nogil except + - rcp_const_basic get_coeff(int) nogil except + + rcp_const_basic as_basic() except+ nogil + umap_int_basic as_dict() except+ nogil + rcp_const_basic get_coeff(int) except+ nogil ctypedef RCP[const SeriesCoeffInterface] rcp_const_seriescoeffinterface "SymEngine::RCP" - rcp_const_seriescoeffinterface series "SymEngine::series"(rcp_const_basic &ex, RCP[const Symbol] &var, unsigned int prec) nogil except + + rcp_const_seriescoeffinterface series "SymEngine::series"(rcp_const_basic &ex, RCP[const Symbol] &var, unsigned int prec) except+ nogil -IF HAVE_SYMENGINE_MPFR: - cdef extern from "" namespace "SymEngine": - void eval_mpfr(mpfr_t result, const Basic &b, mpfr_rnd_t rnd) nogil except + +cdef extern from "" namespace "SymEngine": + void eval_mpfr(mpfr_t result, const Basic &b, mpfr_rnd_t rnd) except+ nogil -IF HAVE_SYMENGINE_MPC: - cdef extern from "" namespace "SymEngine": - void eval_mpc(mpc_t result, const Basic &b, mpfr_rnd_t rnd) nogil except + +cdef extern from "" namespace "SymEngine": + void eval_mpc(mpc_t result, const Basic &b, mpfr_rnd_t rnd) except+ nogil cdef extern from "" namespace "SymEngine": - rcp_const_basic parse(const string &n) nogil except + + rcp_const_basic parse(const string &n) except+ nogil cdef extern from "" namespace "SymEngine": cdef cppclass Set(Basic): - RCP[const Set] set_intersection(RCP[const Set] &o) nogil except + - RCP[const Set] set_union(RCP[const Set] &o) nogil except + - RCP[const Set] set_complement(RCP[const Set] &o) nogil except + - RCP[const Boolean] contains(rcp_const_basic &a) nogil except + + RCP[const Set] set_intersection(RCP[const Set] &o) except+ nogil + RCP[const Set] set_union(RCP[const Set] &o) except+ nogil + RCP[const Set] set_complement(RCP[const Set] &o) except+ nogil + RCP[const Boolean] contains(rcp_const_basic &a) except+ nogil cdef cppclass Interval(Set): pass cdef cppclass EmptySet(Set): @@ -1084,25 +911,25 @@ cdef extern from "" namespace "SymEngine": pass cdef cppclass ImageSet(Set): pass - ctypedef set[RCP[Set], RCPBasicKeyLess] set_set "SymEngine::set_set" - cdef rcp_const_basic interval(RCP[const Number] &start, RCP[const Number] &end, bool l, bool r) nogil except + - cdef RCP[const EmptySet] emptyset() nogil except + - cdef RCP[const Reals] reals() nogil except + - cdef RCP[const Rationals] rationals() nogil except + - cdef RCP[const Integers] integers() nogil except + - cdef RCP[const UniversalSet] universalset() nogil except + - cdef RCP[const Set] finiteset(set_basic &container) nogil except + - cdef RCP[const Set] set_union(set_set &a) nogil except + - cdef RCP[const Set] set_intersection(set_set &a) nogil except + - cdef RCP[const Set] set_complement_helper(RCP[const Set] &container, RCP[const Set] &universe) nogil except + - cdef RCP[const Set] set_complement(RCP[const Set] &universe, RCP[const Set] &container) nogil except + - cdef RCP[const Set] conditionset(rcp_const_basic &sym, RCP[const Boolean] &condition) nogil except + - cdef RCP[const Set] imageset(rcp_const_basic &sym, rcp_const_basic &expr, RCP[const Set] &base) nogil except + + ctypedef set[RCP[Set]] set_set "SymEngine::set_set" + cdef rcp_const_basic interval(RCP[const Number] &start, RCP[const Number] &end, bool l, bool r) except+ nogil + cdef RCP[const EmptySet] emptyset() except+ nogil + cdef RCP[const Reals] reals() except+ nogil + cdef RCP[const Rationals] rationals() except+ nogil + cdef RCP[const Integers] integers() except+ nogil + cdef RCP[const UniversalSet] universalset() except+ nogil + cdef RCP[const Set] finiteset(set_basic &container) except+ nogil + cdef RCP[const Set] set_union(set_set &a) except+ nogil + cdef RCP[const Set] set_intersection(set_set &a) except+ nogil + cdef RCP[const Set] set_complement_helper(RCP[const Set] &container, RCP[const Set] &universe) except+ nogil + cdef RCP[const Set] set_complement(RCP[const Set] &universe, RCP[const Set] &container) except+ nogil + cdef RCP[const Set] conditionset(rcp_const_basic &sym, RCP[const Boolean] &condition) except+ nogil + cdef RCP[const Set] imageset(rcp_const_basic &sym, rcp_const_basic &expr, RCP[const Set] &base) except+ nogil cdef extern from "" namespace "SymEngine": - cdef RCP[const Set] solve(rcp_const_basic &f, RCP[const Symbol] &sym) nogil except + - cdef RCP[const Set] solve(rcp_const_basic &f, RCP[const Symbol] &sym, RCP[const Set] &domain) nogil except + - cdef vec_basic linsolve(const vec_basic &eqs, const vec_sym &syms) nogil except + + cdef RCP[const Set] solve(rcp_const_basic &f, RCP[const Symbol] &sym) except+ nogil + cdef RCP[const Set] solve(rcp_const_basic &f, RCP[const Symbol] &sym, RCP[const Set] &domain) except+ nogil + cdef vec_basic linsolve(const vec_basic &eqs, const vec_sym &syms) except+ nogil cdef extern from "symengine/tribool.h" namespace "SymEngine": cdef cppclass tribool: @@ -1118,10 +945,10 @@ cdef extern from "symengine/tribool.h" namespace "SymEngine::tribool": cdef tribool tritrue cdef extern from "" namespace "SymEngine": - string ccode(const Basic &x) nogil except + - string latex(const Basic &x) nogil except + - string latex(const DenseMatrix &x, unsigned max_rows, unsigned max_cols) nogil except + - string unicode(const Basic &x) nogil except + + string ccode(const Basic &x) except+ nogil + string latex(const Basic &x) except+ nogil + string latex(const DenseMatrix &x, unsigned max_rows, unsigned max_cols) except+ nogil + string unicode(const Basic &x) except+ nogil ## Defined in 'symengine/cwrapper.cpp' cdef struct CRCPBasic: diff --git a/symengine/lib/symengine_wrapper.pxd b/symengine/lib/symengine_wrapper.in.pxd similarity index 99% rename from symengine/lib/symengine_wrapper.pxd rename to symengine/lib/symengine_wrapper.in.pxd index 0728c42bd..3712e17ce 100644 --- a/symengine/lib/symengine_wrapper.pxd +++ b/symengine/lib/symengine_wrapper.in.pxd @@ -6,8 +6,6 @@ from libcpp.vector cimport vector from libcpp.string cimport string from libcpp cimport bool as cppbool -include "config.pxi" - cdef class Basic(object): cdef rcp_const_basic thisptr diff --git a/symengine/lib/symengine_wrapper.pyx b/symengine/lib/symengine_wrapper.in.pyx similarity index 95% rename from symengine/lib/symengine_wrapper.pyx rename to symengine/lib/symengine_wrapper.in.pyx index de90b2cb8..e10d14768 100644 --- a/symengine/lib/symengine_wrapper.pyx +++ b/symengine/lib/symengine_wrapper.in.pyx @@ -5,6 +5,7 @@ from symengine cimport (RCP, pair, map_basic_basic, umap_int_basic, rcp_const_basic, std_pair_short_rcp_const_basic, rcp_const_seriescoeffinterface, CRCPBasic, tribool, is_indeterminate, is_true, is_false) from libcpp cimport bool as cppbool +from libcpp.utility cimport move from libcpp.string cimport string from libcpp.vector cimport vector from cpython cimport PyObject, Py_XINCREF, Py_XDECREF, \ @@ -30,7 +31,6 @@ try: except ImportError: have_numpy = False -include "config.pxi" class SympifyError(Exception): pass @@ -47,13 +47,13 @@ cpdef void assign_to_capsule(object capsule, object value): cdef object c2py(rcp_const_basic o): cdef Basic r cdef PyObject *obj - if (symengine.is_a_Add(deref(o))): + if (symengine.is_a[symengine.Add](deref(o))): r = Expr.__new__(Add) - elif (symengine.is_a_Mul(deref(o))): + elif (symengine.is_a[symengine.Mul](deref(o))): r = Expr.__new__(Mul) - elif (symengine.is_a_Pow(deref(o))): + elif (symengine.is_a[symengine.Pow](deref(o))): r = Expr.__new__(Pow) - elif (symengine.is_a_Integer(deref(o))): + elif (symengine.is_a[symengine.Integer](deref(o))): if (deref(symengine.rcp_static_cast_Integer(o)).is_zero()): return S.Zero elif (deref(symengine.rcp_static_cast_Integer(o)).is_one()): @@ -61,26 +61,26 @@ cdef object c2py(rcp_const_basic o): elif (deref(symengine.rcp_static_cast_Integer(o)).is_minus_one()): return S.NegativeOne r = Number.__new__(Integer) - elif (symengine.is_a_Rational(deref(o))): + elif (symengine.is_a[symengine.Rational](deref(o))): r = S.Half if (symengine.eq(deref(o), deref(r.thisptr))): return S.Half r = Number.__new__(Rational) - elif (symengine.is_a_Complex(deref(o))): + elif (symengine.is_a[symengine.Complex](deref(o))): r = S.ImaginaryUnit if (symengine.eq(deref(o), deref(r.thisptr))): return S.ImaginaryUnit r = Complex.__new__(Complex) - elif (symengine.is_a_Dummy(deref(o))): + elif (symengine.is_a[symengine.Dummy](deref(o))): r = Dummy.__new__(Dummy) - elif (symengine.is_a_Symbol(deref(o))): - if (symengine.is_a_PySymbol(deref(o))): + elif (symengine.is_a[symengine.Symbol](deref(o))): + if (symengine.is_a_sub[symengine.PySymbol](deref(o))): obj = deref(symengine.rcp_static_cast_PySymbol(o)).get_py_object() result = (obj) Py_XDECREF(obj); return result r = Symbol.__new__(Symbol) - elif (symengine.is_a_Constant(deref(o))): + elif (symengine.is_a[symengine.Constant](deref(o))): r = S.Pi if (symengine.eq(deref(o), deref(r.thisptr))): return S.Pi @@ -97,171 +97,171 @@ cdef object c2py(rcp_const_basic o): if (symengine.eq(deref(o), deref(r.thisptr))): return S.EulerGamma r = Constant.__new__(Constant) - elif (symengine.is_a_Infty(deref(o))): + elif (symengine.is_a[symengine.Infty](deref(o))): if (deref(symengine.rcp_static_cast_Infty(o)).is_positive()): return S.Infinity elif (deref(symengine.rcp_static_cast_Infty(o)).is_negative()): return S.NegativeInfinity return S.ComplexInfinity - elif (symengine.is_a_NaN(deref(o))): + elif (symengine.is_a[symengine.NaN](deref(o))): return S.NaN - elif (symengine.is_a_PyFunction(deref(o))): + elif (symengine.is_a[symengine.PyFunction](deref(o))): r = PyFunction.__new__(PyFunction) - elif (symengine.is_a_FunctionSymbol(deref(o))): + elif (symengine.is_a[symengine.FunctionSymbol](deref(o))): r = FunctionSymbol.__new__(FunctionSymbol) - elif (symengine.is_a_Abs(deref(o))): + elif (symengine.is_a[symengine.Abs](deref(o))): r = Function.__new__(Abs) - elif (symengine.is_a_Max(deref(o))): + elif (symengine.is_a[symengine.Max](deref(o))): r = Function.__new__(Max) - elif (symengine.is_a_Min(deref(o))): + elif (symengine.is_a[symengine.Min](deref(o))): r = Function.__new__(Min) - elif (symengine.is_a_BooleanAtom(deref(o))): + elif (symengine.is_a[symengine.BooleanAtom](deref(o))): if (deref(symengine.rcp_static_cast_BooleanAtom(o)).get_val()): return S.true return S.false - elif (symengine.is_a_Equality(deref(o))): + elif (symengine.is_a[symengine.Equality](deref(o))): r = Relational.__new__(Equality) - elif (symengine.is_a_Unequality(deref(o))): + elif (symengine.is_a[symengine.Unequality](deref(o))): r = Relational.__new__(Unequality) - elif (symengine.is_a_LessThan(deref(o))): + elif (symengine.is_a[symengine.LessThan](deref(o))): r = Relational.__new__(LessThan) - elif (symengine.is_a_StrictLessThan(deref(o))): + elif (symengine.is_a[symengine.StrictLessThan](deref(o))): r = Relational.__new__(StrictLessThan) - elif (symengine.is_a_Gamma(deref(o))): + elif (symengine.is_a[symengine.Gamma](deref(o))): r = Function.__new__(Gamma) - elif (symengine.is_a_Derivative(deref(o))): + elif (symengine.is_a[symengine.Derivative](deref(o))): r = Expr.__new__(Derivative) - elif (symengine.is_a_Subs(deref(o))): + elif (symengine.is_a[symengine.Subs](deref(o))): r = Expr.__new__(Subs) - elif (symengine.is_a_RealDouble(deref(o))): + elif (symengine.is_a[symengine.RealDouble](deref(o))): r = Number.__new__(RealDouble) - elif (symengine.is_a_ComplexDouble(deref(o))): + elif (symengine.is_a[symengine.ComplexDouble](deref(o))): r = ComplexDouble.__new__(ComplexDouble) - elif (symengine.is_a_RealMPFR(deref(o))): + elif (symengine.is_a[symengine.RealMPFR](deref(o))): r = Number.__new__(RealMPFR) - elif (symengine.is_a_ComplexMPC(deref(o))): + elif (symengine.is_a[symengine.ComplexMPC](deref(o))): r = ComplexMPC.__new__(ComplexMPC) - elif (symengine.is_a_Log(deref(o))): + elif (symengine.is_a[symengine.Log](deref(o))): r = Function.__new__(Log) - elif (symengine.is_a_Sin(deref(o))): + elif (symengine.is_a[symengine.Sin](deref(o))): r = Function.__new__(Sin) - elif (symengine.is_a_Cos(deref(o))): + elif (symengine.is_a[symengine.Cos](deref(o))): r = Function.__new__(Cos) - elif (symengine.is_a_Tan(deref(o))): + elif (symengine.is_a[symengine.Tan](deref(o))): r = Function.__new__(Tan) - elif (symengine.is_a_Cot(deref(o))): + elif (symengine.is_a[symengine.Cot](deref(o))): r = Function.__new__(Cot) - elif (symengine.is_a_Csc(deref(o))): + elif (symengine.is_a[symengine.Csc](deref(o))): r = Function.__new__(Csc) - elif (symengine.is_a_Sec(deref(o))): + elif (symengine.is_a[symengine.Sec](deref(o))): r = Function.__new__(Sec) - elif (symengine.is_a_ASin(deref(o))): + elif (symengine.is_a[symengine.ASin](deref(o))): r = Function.__new__(ASin) - elif (symengine.is_a_ACos(deref(o))): + elif (symengine.is_a[symengine.ACos](deref(o))): r = Function.__new__(ACos) - elif (symengine.is_a_ATan(deref(o))): + elif (symengine.is_a[symengine.ATan](deref(o))): r = Function.__new__(ATan) - elif (symengine.is_a_ACot(deref(o))): + elif (symengine.is_a[symengine.ACot](deref(o))): r = Function.__new__(ACot) - elif (symengine.is_a_ACsc(deref(o))): + elif (symengine.is_a[symengine.ACsc](deref(o))): r = Function.__new__(ACsc) - elif (symengine.is_a_ASec(deref(o))): + elif (symengine.is_a[symengine.ASec](deref(o))): r = Function.__new__(ASec) - elif (symengine.is_a_Sinh(deref(o))): + elif (symengine.is_a[symengine.Sinh](deref(o))): r = Function.__new__(Sinh) - elif (symengine.is_a_Cosh(deref(o))): + elif (symengine.is_a[symengine.Cosh](deref(o))): r = Function.__new__(Cosh) - elif (symengine.is_a_Tanh(deref(o))): + elif (symengine.is_a[symengine.Tanh](deref(o))): r = Function.__new__(Tanh) - elif (symengine.is_a_Coth(deref(o))): + elif (symengine.is_a[symengine.Coth](deref(o))): r = Function.__new__(Coth) - elif (symengine.is_a_Csch(deref(o))): + elif (symengine.is_a[symengine.Csch](deref(o))): r = Function.__new__(Csch) - elif (symengine.is_a_Sech(deref(o))): + elif (symengine.is_a[symengine.Sech](deref(o))): r = Function.__new__(Sech) - elif (symengine.is_a_ASinh(deref(o))): + elif (symengine.is_a[symengine.ASinh](deref(o))): r = Function.__new__(ASinh) - elif (symengine.is_a_ACosh(deref(o))): + elif (symengine.is_a[symengine.ACosh](deref(o))): r = Function.__new__(ACosh) - elif (symengine.is_a_ATanh(deref(o))): + elif (symengine.is_a[symengine.ATanh](deref(o))): r = Function.__new__(ATanh) - elif (symengine.is_a_ACoth(deref(o))): + elif (symengine.is_a[symengine.ACoth](deref(o))): r = Function.__new__(ACoth) - elif (symengine.is_a_ACsch(deref(o))): + elif (symengine.is_a[symengine.ACsch](deref(o))): r = Function.__new__(ACsch) - elif (symengine.is_a_ASech(deref(o))): + elif (symengine.is_a[symengine.ASech](deref(o))): r = Function.__new__(ASech) - elif (symengine.is_a_ATan2(deref(o))): + elif (symengine.is_a[symengine.ATan2](deref(o))): r = Function.__new__(ATan2) - elif (symengine.is_a_LambertW(deref(o))): + elif (symengine.is_a[symengine.LambertW](deref(o))): r = Function.__new__(LambertW) - elif (symengine.is_a_Zeta(deref(o))): + elif (symengine.is_a[symengine.Zeta](deref(o))): r = Function.__new__(zeta) - elif (symengine.is_a_DirichletEta(deref(o))): + elif (symengine.is_a[symengine.Dirichlet_eta](deref(o))): r = Function.__new__(dirichlet_eta) - elif (symengine.is_a_KroneckerDelta(deref(o))): + elif (symengine.is_a[symengine.KroneckerDelta](deref(o))): r = Function.__new__(KroneckerDelta) - elif (symengine.is_a_LeviCivita(deref(o))): + elif (symengine.is_a[symengine.LeviCivita](deref(o))): r = Function.__new__(LeviCivita) - elif (symengine.is_a_Erf(deref(o))): + elif (symengine.is_a[symengine.Erf](deref(o))): r = Function.__new__(erf) - elif (symengine.is_a_Erfc(deref(o))): + elif (symengine.is_a[symengine.Erfc](deref(o))): r = Function.__new__(erfc) - elif (symengine.is_a_LowerGamma(deref(o))): + elif (symengine.is_a[symengine.LowerGamma](deref(o))): r = Function.__new__(lowergamma) - elif (symengine.is_a_UpperGamma(deref(o))): + elif (symengine.is_a[symengine.UpperGamma](deref(o))): r = Function.__new__(uppergamma) - elif (symengine.is_a_LogGamma(deref(o))): + elif (symengine.is_a[symengine.LogGamma](deref(o))): r = Function.__new__(loggamma) - elif (symengine.is_a_Beta(deref(o))): + elif (symengine.is_a[symengine.Beta](deref(o))): r = Function.__new__(beta) - elif (symengine.is_a_PolyGamma(deref(o))): + elif (symengine.is_a[symengine.PolyGamma](deref(o))): r = Function.__new__(polygamma) - elif (symengine.is_a_Sign(deref(o))): + elif (symengine.is_a[symengine.Sign](deref(o))): r = Function.__new__(sign) - elif (symengine.is_a_Floor(deref(o))): + elif (symengine.is_a[symengine.Floor](deref(o))): r = Function.__new__(floor) - elif (symengine.is_a_Ceiling(deref(o))): + elif (symengine.is_a[symengine.Ceiling](deref(o))): r = Function.__new__(ceiling) - elif (symengine.is_a_Conjugate(deref(o))): + elif (symengine.is_a[symengine.Conjugate](deref(o))): r = Function.__new__(conjugate) - elif (symengine.is_a_PyNumber(deref(o))): + elif (symengine.is_a[symengine.PyNumber](deref(o))): r = PyNumber.__new__(PyNumber) - elif (symengine.is_a_Piecewise(deref(o))): + elif (symengine.is_a[symengine.Piecewise](deref(o))): r = Function.__new__(Piecewise) - elif (symengine.is_a_Contains(deref(o))): + elif (symengine.is_a[symengine.Contains](deref(o))): r = Boolean.__new__(Contains) - elif (symengine.is_a_Interval(deref(o))): + elif (symengine.is_a[symengine.Interval](deref(o))): r = Set.__new__(Interval) - elif (symengine.is_a_EmptySet(deref(o))): + elif (symengine.is_a[symengine.EmptySet](deref(o))): r = Set.__new__(EmptySet) - elif (symengine.is_a_Reals(deref(o))): + elif (symengine.is_a[symengine.Reals](deref(o))): r = Set.__new__(Reals) - elif (symengine.is_a_Integers(deref(o))): + elif (symengine.is_a[symengine.Integers](deref(o))): r = Set.__new__(Integers) - elif (symengine.is_a_Rationals(deref(o))): + elif (symengine.is_a[symengine.Rationals](deref(o))): r = Set.__new__(Rationals) - elif (symengine.is_a_UniversalSet(deref(o))): + elif (symengine.is_a[symengine.UniversalSet](deref(o))): r = Set.__new__(UniversalSet) - elif (symengine.is_a_FiniteSet(deref(o))): + elif (symengine.is_a[symengine.FiniteSet](deref(o))): r = Set.__new__(FiniteSet) - elif (symengine.is_a_Union(deref(o))): + elif (symengine.is_a[symengine.Union](deref(o))): r = Set.__new__(Union) - elif (symengine.is_a_Complement(deref(o))): + elif (symengine.is_a[symengine.Complement](deref(o))): r = Set.__new__(Complement) - elif (symengine.is_a_ConditionSet(deref(o))): + elif (symengine.is_a[symengine.ConditionSet](deref(o))): r = Set.__new__(ConditionSet) - elif (symengine.is_a_ImageSet(deref(o))): + elif (symengine.is_a[symengine.ImageSet](deref(o))): r = Set.__new__(ImageSet) - elif (symengine.is_a_And(deref(o))): + elif (symengine.is_a[symengine.And](deref(o))): r = Boolean.__new__(And) - elif (symengine.is_a_Not(deref(o))): + elif (symengine.is_a[symengine.Not](deref(o))): r = Boolean.__new__(Not) - elif (symengine.is_a_Or(deref(o))): + elif (symengine.is_a[symengine.Or](deref(o))): r = Boolean.__new__(Or) - elif (symengine.is_a_Xor(deref(o))): + elif (symengine.is_a[symengine.Xor](deref(o))): r = Boolean.__new__(Xor) - elif (symengine.is_a_UnevaluatedExpr(deref(o))): + elif (symengine.is_a[symengine.UnevaluatedExpr](deref(o))): r = Function.__new__(UnevaluatedExpr) else: raise Exception("Unsupported SymEngine class.") @@ -870,6 +870,12 @@ cdef class Basic(object): cdef Basic B = B_ return c2py(symengine.add(A.thisptr, B.thisptr)) + def __radd__(Basic self, b): + B_ = _sympify(b, False) + if B_ is None or isinstance(B_, MatrixBase): return NotImplemented + cdef Basic B = B_ + return c2py(symengine.add(B.thisptr, self.thisptr)) + def __sub__(a, b): cdef Basic A = _sympify(a, False) B_ = _sympify(b, False) @@ -877,6 +883,12 @@ cdef class Basic(object): cdef Basic B = B_ return c2py(symengine.sub(A.thisptr, B.thisptr)) + def __rsub__(Basic self, b): + B_ = _sympify(b, False) + if B_ is None or isinstance(B_, MatrixBase): return NotImplemented + cdef Basic B = B_ + return c2py(symengine.sub(B.thisptr, self.thisptr)) + def __mul__(a, b): cdef Basic A = _sympify(a, False) B_ = _sympify(b, False) @@ -884,22 +896,45 @@ cdef class Basic(object): cdef Basic B = B_ return c2py(symengine.mul(A.thisptr, B.thisptr)) + def __rmul__(Basic self, b): + B_ = _sympify(b, False) + if B_ is None or isinstance(B_, MatrixBase): return NotImplemented + cdef Basic B = B_ + return c2py(symengine.mul(B.thisptr, self.thisptr)) + def __truediv__(a, b): cdef Basic A = _sympify(a, False) - cdef Basic B = _sympify(b, False) - if A is None or B is None: return NotImplemented + B_ = _sympify(b, False) + if A is None or B_ is None or isinstance(B_, MatrixBase): return NotImplemented + cdef Basic B = B_ return c2py(symengine.div(A.thisptr, B.thisptr)) + def __rtruediv__(Basic self, b): + B_ = _sympify(b, False) + if B_ is None or isinstance(B_, MatrixBase): return NotImplemented + cdef Basic B = B_ + return c2py(symengine.div(B.thisptr, self.thisptr)) + def __floordiv__(x, y): return floor(x/y) + def __rfloordiv__(y, x): + return floor(x/y) + def __mod__(x, y): return x - y * floor(x/y) + def __rmod__(y, x): + return x - y * floor(x/y) + def __divmod__(x, y): f = floor(x/y) return f, x - y * f + def __rdivmod__(y, x): + f = floor(x/y) + return f, x - y * f + def __pow__(a, b, c): if c is not None: return powermod(a, b, c) @@ -908,6 +943,11 @@ cdef class Basic(object): if A is None or B is None: return NotImplemented return c2py(symengine.pow(A.thisptr, B.thisptr)) + def __rpow__(Basic self, b): + cdef Basic B = _sympify(b, False) + if B is None: return NotImplemented + return c2py(symengine.pow(B.thisptr, self.thisptr)) + def __neg__(Basic self not None): return c2py(symengine.neg(self.thisptr)) @@ -1995,7 +2035,7 @@ class RealMPFR(Float): cdef string i_ = str(i).encode("utf-8") cdef symengine.mpfr_class m m = symengine.mpfr_class(i_, prec, base) - return c2py(symengine.real_mpfr(symengine.std_move_mpfr(m))) + return c2py(symengine.real_mpfr(move[symengine.mpfr_class](m))) def get_prec(Basic self): return Integer(deref(symengine.rcp_static_cast_RealMPFR(self.thisptr)).get_prec()) @@ -2024,7 +2064,7 @@ cdef class ComplexMPC(ComplexBase): return cdef string i_ = ("(" + str(i) + " " + str(j) + ")").encode("utf-8") cdef symengine.mpc_class m = symengine.mpc_class(i_, prec, base) - self.thisptr = symengine.complex_mpc(symengine.std_move_mpc(m)) + self.thisptr = symengine.complex_mpc(move[symengine.mpc_class](m)) def _sympy_(self): import sympy @@ -2290,7 +2330,7 @@ class Mul(AssocOp): d = collections.defaultdict(int) d[c2py(symengine.mul_from_dict(\ (one), - symengine.std_move_map_basic_basic(dict)))] =\ + move[symengine.map_basic_basic](dict)))] =\ c2py(deref(X).get_coef()) return d @@ -3392,6 +3432,19 @@ cdef class DenseMatrixBase(MatrixBase): raise ShapeError("Invalid shapes for matrix addition. Got %s %s" % (a_.shape, b_.shape)) return a_.add_matrix(b_) + def __radd__(MatrixBase self, a): + a = _sympify(a, False) + if not isinstance(a, MatrixBase): + return NotImplemented + cdef MatrixBase a_ = a + if (a_.shape == (0, 0)): + return self + if (self.shape == (0, 0)): + return a_ + if (self.shape != a_.shape): + raise ShapeError("Invalid shapes for matrix addition. Got %s %s" % (a_.shape, self.shape)) + return a_.add_matrix(self) + def __mul__(a, b): a = _sympify(a, False) b = _sympify(b, False) @@ -3409,6 +3462,17 @@ cdef class DenseMatrixBase(MatrixBase): else: return NotImplemented + def __rmul__(Basic self, a): + a = _sympify(a, False) + if isinstance(a, MatrixBase): + if (a.ncols() != self.nrows()): + raise ShapeError("Invalid shapes for matrix multiplication. Got %s %s" % (a.shape, self.shape)) + return a.mul_matrix(self) + elif isinstance(a, Basic): + return self.mul_scalar(a) + else: + return NotImplemented + def __matmul__(a, b): a = _sympify(a, False) b = _sympify(b, False) @@ -3416,8 +3480,31 @@ cdef class DenseMatrixBase(MatrixBase): raise ShapeError("Invalid shapes for matrix multiplication. Got %s %s" % (a.shape, b.shape)) return a.mul_matrix(b) + def __rmatmul__(Basic self, a): + a = _sympify(a, False) + if (a.ncols() != self.nrows()): + raise ShapeError("Invalid shapes for matrix multiplication. Got %s %s" % (a.shape, self.shape)) + return a.mul_matrix(self) + def __truediv__(a, b): - return div_matrices(a, b) + a = _sympify(a, False) + b = _sympify(b, False) + if isinstance(a, MatrixBase): + if isinstance(b, MatrixBase): + return a.mul_matrix(b.inv()) + elif isinstance(b, Basic): + return a.mul_scalar(1/b) + else: + return NotImplemented + else: + return NotImplemented + + def __rtruediv__(Basic self, a): + a = _sympify(a, False) + if isinstance(a, MatrixBase): + return a.mul_matrix(self.inv()) + else: + return NotImplemented def __sub__(a, b): a = _sympify(a, False) @@ -3430,6 +3517,15 @@ cdef class DenseMatrixBase(MatrixBase): raise ShapeError("Invalid shapes for matrix subtraction. Got %s %s" % (a.shape, b.shape)) return a_.add_matrix(-b_) + def __rsub__(MatrixBase self, a): + a = _sympify(a, False) + if not isinstance(a, MatrixBase): + return NotImplemented + cdef MatrixBase a_ = a + if (a_.shape != self.shape): + raise ShapeError("Invalid shapes for matrix subtraction. Got %s %s" % (a.shape, self.shape)) + return a_.add_matrix(-self) + def __neg__(self): return self.mul_scalar(-1) @@ -4038,19 +4134,6 @@ cdef class DenseMatrixBase(MatrixBase): return self.applyfunc(lambda x : x.expand(*args, **kwargs)) -def div_matrices(a, b): - a = _sympify(a, False) - b = _sympify(b, False) - if isinstance(a, MatrixBase): - if isinstance(b, MatrixBase): - return a.mul_matrix(b.inv()) - elif isinstance(b, Basic): - return a.mul_scalar(1/b) - else: - return NotImplemented - else: - return NotImplemented - class DenseMatrixBaseIter(object): def __init__(self, d): @@ -5374,7 +5457,7 @@ def piecewise(*v): p.first = e.thisptr p.second = symengine.rcp_static_cast_Boolean(b.thisptr) vec.push_back(p) - return c2py(symengine.piecewise(symengine.std_move_PiecewiseVec(vec))) + return c2py(symengine.piecewise(move[symengine.PiecewiseVec](vec))) def interval(start, end, left_open=False, right_open=False):