Skip to content

Commit a6abdbf

Browse files
committed
core/cg: template specialization of getitem
1 parent 3606713 commit a6abdbf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/pycppad/codegen/cg.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ struct cast<From,::CppAD::cg::CG<Scalar>>
3232
}
3333
};
3434

35+
namespace internal {
36+
37+
template <typename Scalar>
38+
struct getitem<::CppAD::cg::CG<Scalar>> {
39+
40+
typedef ::CppAD::cg::CG<Scalar> CG;
41+
42+
static PyObject* run(void* data, void* /* arr */) {
43+
CG & cg = *static_cast<CG*>(data);
44+
45+
if(!cg.isValueDefined()) // not initialized
46+
cg.setValue(static_cast<Scalar>(0));
47+
48+
bp::object m(cg);
49+
Py_INCREF(m.ptr());
50+
return m.ptr();
51+
}
52+
};
53+
54+
} // namespace internal
3555
} // namespace eigenpy
3656

3757
namespace pycppad

0 commit comments

Comments
 (0)