Skip to content

Commit

Permalink
core/cg: template specialization of getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarpent committed May 22, 2022
1 parent 3606713 commit a6abdbf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/pycppad/codegen/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ struct cast<From,::CppAD::cg::CG<Scalar>>
}
};

namespace internal {

template <typename Scalar>
struct getitem<::CppAD::cg::CG<Scalar>> {

typedef ::CppAD::cg::CG<Scalar> CG;

static PyObject* run(void* data, void* /* arr */) {
CG & cg = *static_cast<CG*>(data);

if(!cg.isValueDefined()) // not initialized
cg.setValue(static_cast<Scalar>(0));

bp::object m(cg);
Py_INCREF(m.ptr());
return m.ptr();
}
};

} // namespace internal
} // namespace eigenpy

namespace pycppad
Expand Down

0 comments on commit a6abdbf

Please sign in to comment.