diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 060e16a..53685ab 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -19,7 +19,7 @@ jobs: - name: Install Dependencies run: | - sudo apt install libboost-all-dev libeigen3-dev + sudo apt install libboost-python-dev libeigen3-dev . /etc/os-release sudo tee /etc/apt/sources.list.d/robotpkg.list < + template class ADVisitor - : public bp::def_visitor< ADVisitor > + : public bp::def_visitor< ADVisitor<_Scalar> > { public: + typedef _Scalar Scalar; typedef ::CppAD::AD AD; template diff --git a/include/pycppad/ad_fun.hpp b/include/pycppad/ad_fun.hpp index e08251a..570ea6d 100644 --- a/include/pycppad/ad_fun.hpp +++ b/include/pycppad/ad_fun.hpp @@ -37,7 +37,7 @@ namespace pycppad //.def("swap", &ADFun::swap, bp::args("self", "f")) .def("from_json", &ADFun::from_json, bp::args("self", "json")) //.def("from_graph", &ADFun::from_graph, bp::args("self", "graph_obj")) - .def("to_json", &ADFun::to_json, bp::arg("self")) + //.def("to_json", &ADFun::to_json, bp::arg("self")) .def("size_order", &ADFun::size_order, bp::arg("self")) .def("Dependent",&Dependent, bp::args("self", "x", "y")) @@ -74,13 +74,28 @@ namespace pycppad return f; } + protected: + + static std::string & get_class_name() + { + static std::string class_name; + return class_name; + } + + static void set_class_name(const std::string & class_name) + { + get_class_name() = class_name; + } + + public: - static void expose() + static void expose(const std::string & class_name = "ADFun") { - bp::class_("ADFun", - "Class used to hold function objects.\n\n", - bp::init<>()) - .def(ADFunVisitor()); + set_class_name(class_name); + bp::class_(class_name.c_str(), + "Class used to hold function objects.\n\n", + bp::init<>()) + .def(ADFunVisitor()); } }; diff --git a/include/pycppad/codegen/ad.hpp b/include/pycppad/codegen/ad.hpp new file mode 100644 index 0000000..008d90c --- /dev/null +++ b/include/pycppad/codegen/ad.hpp @@ -0,0 +1,20 @@ +/* + * Copyright 2021 INRIA + */ + +#ifndef __pycppad_codegen_ad_hpp__ +#define __pycppad_codegen_ad_hpp__ + +#include "pycppad/ad.hpp" + +namespace pycppad +{ + + template<> + int64_t ADVisitor<::CppAD::cg::CG >::__int__(const AD & self) + { + return static_cast(::CppAD::Value(self).getValue()); + } +} + +#endif //#ifndef __pycppad_ad_hpp__ diff --git a/include/pycppad/codegen/cppadcg-scalar.hpp b/include/pycppad/codegen/cppadcg-scalar.hpp index 7cee14c..5ccef8e 100644 --- a/include/pycppad/codegen/cppadcg-scalar.hpp +++ b/include/pycppad/codegen/cppadcg-scalar.hpp @@ -9,6 +9,10 @@ #include #include "pycppad/codegen/cg.hpp" +#include "pycppad/codegen/ad.hpp" +#include "pycppad/ad.hpp" +#include "pycppad/independent.hpp" +#include "pycppad/ad_fun.hpp" namespace pycppad @@ -19,11 +23,23 @@ namespace pycppad void exposeCppADCGScalar() { typedef ::CppAD::cg::CG CGScalar; + typedef ::CppAD::AD ADCGScalar; + typedef Eigen::Matrix VectorADCG; + typedef Eigen::Matrix RowVectorADCG; eigenpy::exposeType(); eigenpy::exposeType(); - + + eigenpy::exposeType(); + eigenpy::exposeType(); + CGVisitor::expose(); + + + pycppad::ADVisitor::expose("ADCG"); + pycppad::ADFunVisitor::expose("ADCGFun"); + pycppad::IndependentVisitor::expose("CGIndependent"); + pycppad::IndependentVisitor::expose("CGIndependent"); } } } diff --git a/include/pycppad/independent.hpp b/include/pycppad/independent.hpp index d4581e1..749f04d 100644 --- a/include/pycppad/independent.hpp +++ b/include/pycppad/independent.hpp @@ -24,6 +24,20 @@ namespace pycppad template void visit(PyClass&) const { } + + protected: + + static std::string & get_class_name() + { + static std::string class_name; + return class_name; + } + + static void set_class_name(const std::string & class_name) + { + get_class_name() = class_name; + } + public: @@ -39,9 +53,10 @@ namespace pycppad return; } - static void expose() + static void expose(const std::string & class_name = "Independent") { - bp::def("Independent",&Independent, + set_class_name(class_name); + bp::def(class_name.c_str(),&Independent, (bp::arg("x"), bp::arg("abort_op_index") = 0, bp::arg("record_compare") = true), "define a variable as Independent." "Parameters:\n"