Skip to content

Commit 177a135

Browse files
committed
[cppadcg][independent] expose CGIndependent
1 parent 3b23275 commit 177a135

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

include/pycppad/codegen/cppadcg-scalar.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pycppad/codegen/cg.hpp"
1212
#include "pycppad/codegen/ad.hpp"
1313
#include "pycppad/ad.hpp"
14+
#include "pycppad/independent.hpp"
1415
#include "pycppad/ad_fun.hpp"
1516

1617

@@ -23,8 +24,8 @@ namespace pycppad
2324
{
2425
typedef ::CppAD::cg::CG<Scalar> CGScalar;
2526
typedef ::CppAD::AD<CGScalar> ADCGScalar;
26-
//typedef Eigen::Matrix<ADCGScalar,Eigen::Dynamic,1> VectorADCG;
27-
//typedef Eigen::Matrix<ADCGScalar,1,Eigen::Dynamic> RowVectorADCG;
27+
typedef Eigen::Matrix<ADCGScalar,Eigen::Dynamic,1> VectorADCG;
28+
typedef Eigen::Matrix<ADCGScalar,1,Eigen::Dynamic> RowVectorADCG;
2829

2930
eigenpy::exposeType<CGScalar>();
3031
eigenpy::exposeType<CGScalar,Eigen::RowMajor>();
@@ -36,9 +37,9 @@ namespace pycppad
3637

3738

3839
pycppad::ADVisitor<CGScalar>::expose("ADCG");
39-
//pycppad::ADFunVisitor<CGScalar>::expose("ADCGFun");
40-
//pycppad::IndependentVisitor<VectorADCG>::expose();
41-
//pycppad::IndependentVisitor<RowVectorADCG>::expose();
40+
pycppad::ADFunVisitor<CGScalar>::expose("ADCGFun");
41+
pycppad::IndependentVisitor<VectorADCG>::expose("CGIndependent");
42+
pycppad::IndependentVisitor<RowVectorADCG>::expose("CGIndependent");
4243
}
4344
}
4445
}

include/pycppad/independent.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ namespace pycppad
2424
template<class PyClass>
2525
void visit(PyClass&) const
2626
{ }
27+
28+
protected:
29+
30+
static std::string & get_class_name()
31+
{
32+
static std::string class_name;
33+
return class_name;
34+
}
35+
36+
static void set_class_name(const std::string & class_name)
37+
{
38+
get_class_name() = class_name;
39+
}
40+
2741

2842
public:
2943

@@ -39,9 +53,10 @@ namespace pycppad
3953
return;
4054
}
4155

42-
static void expose()
56+
static void expose(const std::string & class_name = "Independent")
4357
{
44-
bp::def("Independent",&Independent,
58+
set_class_name(class_name);
59+
bp::def(class_name.c_str(),&Independent,
4560
(bp::arg("x"), bp::arg("abort_op_index") = 0, bp::arg("record_compare") = true),
4661
"define a variable as Independent."
4762
"Parameters:\n"

0 commit comments

Comments
 (0)