From 4c29415ee2be84a764334c5c66df1d8f1a6368e6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 23 Jan 2016 16:15:09 +0530 Subject: [PATCH 1/4] Changes to FunctionWrapper::diff --- symengine/lib/pywrapper.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/symengine/lib/pywrapper.cpp b/symengine/lib/pywrapper.cpp index 1f86526a6..3f8b6ab57 100644 --- a/symengine/lib/pywrapper.cpp +++ b/symengine/lib/pywrapper.cpp @@ -165,10 +165,6 @@ RCP PyNumber::rpow(const Number &other) const { } return make_rcp(result, pymodule_); } -//! Differentiation w.r.t Symbol `x` -RCP PyNumber::diff(const RCP &x) const { - return zero; -} RCP PyNumber::eval(long bits) const { return pymodule_->eval_(pyobject_, bits); @@ -250,7 +246,7 @@ RCP PyFunction::eval(long bits) const { return pyfunction_class_->get_py_module()->eval_(pyobject_, bits); } -RCP PyFunction::diff(const RCP &s) const { +RCP PyFunction::diff_impl(const RCP &s) const { return pyfunction_class_->get_py_module()->diff_(pyobject_, s); } From a40bdb9264f56c0c1939da3bc49f3b2cc3a6a556 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 23 Jan 2016 16:17:22 +0530 Subject: [PATCH 2/4] Changes to Derivative container --- symengine/lib/symengine.pxd | 16 ++++++++++++++-- symengine/lib/symengine/pywrapper.h | 6 +----- symengine/lib/symengine_wrapper.pyx | 18 +++++++++--------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/symengine/lib/symengine.pxd b/symengine/lib/symengine.pxd index 5ddcf7b92..cb3411504 100644 --- a/symengine/lib/symengine.pxd +++ b/symengine/lib/symengine.pxd @@ -41,6 +41,17 @@ cdef extern from "" namespace "std": iterator begin() nogil iterator end() 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: @@ -187,6 +198,7 @@ cdef extern from "" namespace "SymEngine": 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" cdef cppclass Basic: string __str__() nogil except + unsigned int hash() nogil except + @@ -345,7 +357,7 @@ cdef extern from "" namespace "SymEngine": RCP[const Basic] make_rcp_Integer "SymEngine::make_rcp"(int i) nogil RCP[const Basic] make_rcp_Integer "SymEngine::make_rcp"(mpz_class i) nogil RCP[const Basic] make_rcp_Subs "SymEngine::make_rcp"(const RCP[const Basic] &arg, const map_basic_basic &x) nogil - RCP[const Basic] make_rcp_Derivative "SymEngine::make_rcp"(const RCP[const Basic] &arg, const vec_basic &x) nogil + RCP[const Basic] make_rcp_Derivative "SymEngine::make_rcp"(const RCP[const Basic] &arg, const multiset_basic &x) nogil RCP[const Basic] make_rcp_FunctionWrapper "SymEngine::make_rcp"(void* obj, string name, string hash_, const vec_basic &arg, \ void (*dec_ref)(void *), int (*comp)(void *, void *)) nogil RCP[const Basic] make_rcp_RealDouble "SymEngine::make_rcp"(double x) nogil @@ -463,7 +475,7 @@ cdef extern from "" namespace "SymEngine": cdef cppclass Derivative(Basic): Derivative(const RCP[const Basic] &arg, const vec_basic &x) nogil RCP[const Basic] get_arg() nogil - vec_basic get_symbols() nogil + multiset_basic get_symbols() nogil cdef cppclass Subs(Basic): Subs(const RCP[const Basic] &arg, const map_basic_basic &x) nogil diff --git a/symengine/lib/symengine/pywrapper.h b/symengine/lib/symengine/pywrapper.h index 964d0351f..cd39a75ea 100644 --- a/symengine/lib/symengine/pywrapper.h +++ b/symengine/lib/symengine/pywrapper.h @@ -64,7 +64,6 @@ class PyNumber : public NumberWrapper { //! Python module that this object belongs to RCP pymodule_; public: - IMPLEMENT_TYPEID(NUMBER_WRAPPER) PyNumber(PyObject* pyobject, const RCP &pymodule); ~PyNumber() { Py_DECREF(pyobject_); @@ -99,8 +98,6 @@ class PyNumber : public NumberWrapper { virtual RCP pow(const Number &other) const; virtual RCP rpow(const Number &other) const; - //! Differentiation w.r.t Symbol `x` - virtual RCP diff(const RCP &x) const; virtual RCP eval(long bits) const; virtual std::string __str__() const; virtual int compare(const Basic &o) const; @@ -148,7 +145,6 @@ class PyFunction : public FunctionWrapper { PyFunction(const vec_basic &vec, const RCP &pyfunc_class, PyObject *pyobject); ~PyFunction(); - IMPLEMENT_TYPEID(FUNCTIONWRAPPER) PyObject *get_py_object() const; RCP get_pyfunction_class() const; @@ -159,7 +155,7 @@ class PyFunction : public FunctionWrapper { /*! Evaluate the derivative w.r.t. `x` by calling the callback function * of the module that this function belongs to. * */ - virtual RCP diff(const RCP &x) const; + virtual RCP diff_impl(const RCP &x) const; virtual int compare(const Basic &o) const; virtual bool __eq__(const Basic &o) const; virtual std::size_t __hash__() const; diff --git a/symengine/lib/symengine_wrapper.pyx b/symengine/lib/symengine_wrapper.pyx index 01ed27407..d4c937530 100644 --- a/symengine/lib/symengine_wrapper.pyx +++ b/symengine/lib/symengine_wrapper.pyx @@ -1062,22 +1062,22 @@ cdef class Derivative(Basic): def __cinit__(self, expr = None, symbols = None): if expr is None or symbols is None: return - cdef symengine.vec_basic vec + cdef symengine.multiset_basic m cdef Basic s_ cdef Basic expr_ = sympify(expr, True) for s in symbols: s_ = sympify(s, True) - vec.push_back(s_.thisptr) - self.thisptr = symengine.make_rcp_Derivative(expr_.thisptr, vec) + m.insert((s_.thisptr)) + self.thisptr = symengine.make_rcp_Derivative(expr_.thisptr, m) def _sympy_(self): cdef RCP[const symengine.Derivative] X = \ symengine.rcp_static_cast_Derivative(self.thisptr) arg = c2py(deref(X).get_arg())._sympy_() - cdef symengine.vec_basic Y = deref(X).get_symbols() + cdef symengine.multiset_basic Y = deref(X).get_symbols() s = [] - for i in range(Y.size()): - s.append(c2py((Y[i]))._sympy_()) + for i in Y: + s.append(c2py((i))._sympy_()) import sympy return sympy.Derivative(arg, *s) @@ -1085,10 +1085,10 @@ cdef class Derivative(Basic): cdef RCP[const symengine.Derivative] X = \ symengine.rcp_static_cast_Derivative(self.thisptr) arg = c2py(deref(X).get_arg())._sage_() - cdef symengine.vec_basic Y = deref(X).get_symbols() + cdef symengine.multiset_basic Y = deref(X).get_symbols() s = [] - for i in range(Y.size()): - s.append(c2py((Y[i]))._sage_()) + for i in Y: + s.append(c2py((i))._sage_()) return arg.diff(*s) cdef class Subs(Basic): From 95d4aa07de4a74bb700a1546ca3d17a54df02267 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 23 Jan 2016 16:17:55 +0530 Subject: [PATCH 3/4] Update SymEngine hash --- symengine_version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symengine_version.txt b/symengine_version.txt index 689276f65..70ccb9b87 100644 --- a/symengine_version.txt +++ b/symengine_version.txt @@ -1 +1 @@ -2b7673f448f6f36d5d4adf6b1b94c32aa6dfb05b +27c7d9d50a57b45fbfc9bcee4622728c04a829cc From f44a165402ecc2ba80c59f31d9557a0ff2a49447 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 29 Jan 2016 06:59:08 +0530 Subject: [PATCH 4/4] Run SymEngine C++ install script without source --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b3e6b4508..c751b686d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ install: # Build C++ library - cd symengine-cpp - - source bin/test_travis.sh + - bin/test_travis.sh script: # Build Python wrappers and test