Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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 <<EOF
deb [arch=amd64] http://robotpkg.openrobots.org/wip/packages/debian/pub $UBUNTU_CODENAME robotpkg
deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $UBUNTU_CODENAME robotpkg
EOF
curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
sudo apt update
sudo apt install robotpkg-cppad robotpkg-py38-eigenpy
sudo apt install robotpkg-cppad robotpkg-cppadcodegen robotpkg-py38-eigenpy

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand All @@ -38,7 +38,7 @@ jobs:
export PYTHONPATH=$PYTHONPATH:/opt/openrobots/lib/python3/site-packages:/opt/openrobots/lib/python3/dist-packages
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openrobots/lib64:/opt/openrobots/lib/x86_64-linux-gnu:/opt/openrobots/lib/plugin:/opt/openrobots/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/openrobots/lib/pkgconfig:/opt/openrobots/share/pkgconfig:/opt/openrobots/lib/x86_64-linux-gnu/pkgconfig:/opt/openrobots/lib64/pkgconfig
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPYTHON_EXECUTABLE=$(which python3) -DCMAKE_PREFIX_PATH=/opt/openrobots
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPYTHON_EXECUTABLE=$(which python3) -DCMAKE_PREFIX_PATH=/opt/openrobots -DBUILD_CODEGEN_BINDINGS=ON

- name: Build
# Build your program with the given configuration
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SET(${PROJECT_NAME}_SOURCES
IF(BUILD_CODEGEN_BINDINGS)
LIST(APPEND ${PROJECT_NAME}_HEADERS
include/${PROJECT_NAME}/codegen/cg.hpp
include/${PROJECT_NAME}/codegen/ad.hpp
include/${PROJECT_NAME}/codegen/cppadcg-scalar.hpp
)
ENDIF(BUILD_CODEGEN_BINDINGS)
Expand Down
5 changes: 3 additions & 2 deletions include/pycppad/ad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ namespace pycppad
{
namespace bp = boost::python;

template<typename Scalar>
template<typename _Scalar>
class ADVisitor
: public bp::def_visitor< ADVisitor<Scalar> >
: public bp::def_visitor< ADVisitor<_Scalar> >
{
public:
typedef _Scalar Scalar;
typedef ::CppAD::AD<Scalar> AD;

template<class PyClass>
Expand Down
27 changes: 21 additions & 6 deletions include/pycppad/ad_fun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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, boost::noncopyable>("ADFun",
"Class used to hold function objects.\n\n",
bp::init<>())
.def(ADFunVisitor<Scalar>());
set_class_name(class_name);
bp::class_<ADFun, boost::noncopyable>(class_name.c_str(),
"Class used to hold function objects.\n\n",
bp::init<>())
.def(ADFunVisitor<Scalar>());

}
};
Expand Down
20 changes: 20 additions & 0 deletions include/pycppad/codegen/ad.hpp
Original file line number Diff line number Diff line change
@@ -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<double> >::__int__(const AD & self)
{
return static_cast<int>(::CppAD::Value<Scalar>(self).getValue());
}
}

#endif //#ifndef __pycppad_ad_hpp__
18 changes: 17 additions & 1 deletion include/pycppad/codegen/cppadcg-scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <eigenpy/eigenpy.hpp>

#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
Expand All @@ -19,11 +23,23 @@ namespace pycppad
void exposeCppADCGScalar()
{
typedef ::CppAD::cg::CG<Scalar> CGScalar;
typedef ::CppAD::AD<CGScalar> ADCGScalar;
typedef Eigen::Matrix<ADCGScalar,Eigen::Dynamic,1> VectorADCG;
typedef Eigen::Matrix<ADCGScalar,1,Eigen::Dynamic> RowVectorADCG;

eigenpy::exposeType<CGScalar>();
eigenpy::exposeType<CGScalar,Eigen::RowMajor>();


eigenpy::exposeType<ADCGScalar>();
eigenpy::exposeType<ADCGScalar,Eigen::RowMajor>();

CGVisitor<Scalar>::expose();


pycppad::ADVisitor<CGScalar>::expose("ADCG");
pycppad::ADFunVisitor<CGScalar>::expose("ADCGFun");
pycppad::IndependentVisitor<VectorADCG>::expose("CGIndependent");
pycppad::IndependentVisitor<RowVectorADCG>::expose("CGIndependent");
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions include/pycppad/independent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ namespace pycppad
template<class PyClass>
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:

Expand All @@ -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"
Expand Down