Commit 6a56d3ba authored by Rohan Budhiraja's avatar Rohan Budhiraja
Browse files

[code-handler] expose generateCode

parent 211fa8ea
......@@ -5,6 +5,8 @@
#define __pycppad_codegen_code_handler_hpp__
#include <cppad/cg/code_handler.hpp>
#include <cppad/cg/lang/c/language_c.hpp>
#include <cppad/cg/lang/c/lang_c_default_var_name_gen.hpp>
namespace pycppad
{
......@@ -20,11 +22,40 @@ namespace pycppad
public:
typedef ::CppAD::cg::CG<Scalar> CG;
typedef ::CppAD::AD<CG> ADCG;
typedef ::CppAD::AD<Scalar> AD;
typedef Eigen::Matrix<ADCG,Eigen::Dynamic,1> VectorADCG;
typedef Eigen::Matrix<AD,Eigen::Dynamic,1> VectorAD;
typedef Eigen::Matrix<ADCG,1,Eigen::Dynamic> RowVectorADCG;
typedef Eigen::Matrix<CG,Eigen::Dynamic,1> VectorCG;
typedef Eigen::Matrix<CG,1,Eigen::Dynamic> RowVectorCG;
typedef ::CppAD::cg::CodeHandler<Scalar> CodeHandler;
typedef ::CppAD::cg::LanguageC<Scalar> LanguageC;
typedef ::CppAD::cg::LangCDefaultVariableNameGenerator<Scalar> LangCDefaultVariableNameGenerator;
protected:
template<typename VectorType>
static void makeVariables(CodeHandler& self, const VectorType& x)
{
VectorType& x_= const_cast<VectorType&>(x);
self.makeVariables(x_);
return;
}
template<typename VectorType, typename LangType, typename NameGenType>
static std::string generateCode(CodeHandler& self,
LangType& lang,
VectorType& dependent,
NameGenType& nameGen,
const std::string& jobName)
{
std::ostringstream oss;
self.generateCode(oss, lang, dependent, nameGen, jobName);
return oss.str();
}
public:
template<class PyClass>
void visit(PyClass& cl) const
......@@ -40,17 +71,17 @@ namespace pycppad
static_cast<void (CodeHandler::*)(ADCG&)>(&CodeHandler::makeVariable),
bp::args("self", "variable"), "")
.def("makeVariables",
&CodeHandler::template makeVariables<VectorADCG>,
&makeVariables<VectorCG>,
bp::args("self", "variables"), "")
.def("makeVariables",
&CodeHandler::template makeVariables<RowVectorADCG>,
bp::args("self", "variables"), "")
// .def("makeVariables",
// &CodeHandler::template makeVariables<RowVectorADCG>,
// bp::args("self", "variables"), "")
// .def("makeVariables",
// &CodeHandler::template makeVariables<VectorCG>,
// bp::args("self", "variables"), "")
// .def("makeVariables",
// &CodeHandler::template makeVariables<RowVectorCG>,
// bp::args("self", "variables"), "")
.def("makeVariables",
&CodeHandler::template makeVariables<VectorCG>,
bp::args("self", "variables"), "")
.def("makeVariables",
&CodeHandler::template makeVariables<RowVectorCG>,
bp::args("self", "variables"), "")
.def("getIndependentVariableSize", &CodeHandler::getIndependentVariableSize, bp::arg("self"))
.def("getIndependentVariableIndex", &CodeHandler::getIndependentVariableIndex, bp::args("self", "var"))
.def("getMaximumVariableID", &CodeHandler::getMaximumVariableID, bp::arg("self"))
......@@ -67,8 +98,10 @@ namespace pycppad
.def("getAtomicFunctionName", &CodeHandler::getAtomicFunctionName, bp::args("self", "id"))
//.def("getExternalFuncMaxForwardOrder", &CodeHandler::getExternalFuncMaxForwardOrder, bp::arg("self"))
//.def("getExternalFuncMaxReverseOrder", &CodeHandler::getExternalFuncMaxReverseOrder, bp::arg("self"))
//.def("generateCode", &CodeHandler::generateCode,
// bp::args("self", "out", "lang", "dependent", "nameGen", "jobName"))
.def("generateCode", &generateCode<VectorCG, LanguageC, LangCDefaultVariableNameGenerator>,
bp::args("self", "lang", "dependent", "nameGen", "jobName"))
.def("generateCode", &generateCode<RowVectorCG, LanguageC, LangCDefaultVariableNameGenerator>,
bp::args("self", "lang", "dependent", "nameGen", "jobName"))
;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment