Verified Commit a4fa076c authored by Justin Carpentier's avatar Justin Carpentier
Browse files

user types: allow template specialization of getitem

parent f53d37e0
Pipeline #18767 failed with stage
in 17 minutes and 8 seconds
......@@ -38,6 +38,27 @@ static void cast(void* from_, void* to_, npy_intp n, void* /*fromarr*/,
}
}
template <typename T>
struct getitem {
///
/// \brief Get a python object from an array
/// It returns a standard Python object from
/// a single element of the array object arr pointed to by data.
/// \param[in] data Pointer to the first element of the C++ data stream
/// \param[in] arr Pointer to the first element of the Python object data
/// stream
///
/// \returns PyObject corresponding to the python datastream.
///
static PyObject* run(void* data, void* /* arr */) {
// std::cout << "getitem" << std::endl;
T* elt_ptr = static_cast<T*>(data);
bp::object m(boost::ref(*elt_ptr));
Py_INCREF(m.ptr());
return m.ptr();
}
};
template <typename T, int type_code = NumpyEquivalentType<T>::type_code>
struct SpecialMethods {
inline static void copyswap(void* /*dst*/, void* /*src*/, int /*swap*/,
......@@ -71,7 +92,7 @@ struct OffsetOf {
template <typename T>
struct SpecialMethods<T, NPY_USERDEF> {
inline static void copyswap(void* dst, void* src, int swap, void* /*arr*/) {
static void copyswap(void* dst, void* src, int swap, void* /*arr*/) {
// std::cout << "copyswap" << std::endl;
if (src != NULL) {
T& t1 = *static_cast<T*>(dst);
......@@ -86,22 +107,8 @@ struct SpecialMethods<T, NPY_USERDEF> {
}
}
///
/// \brief Get a python object from an array
/// It returns a standard Python object from
/// a single element of the array object arr pointed to by data.
/// \param[in] data Pointer to the first element of the C++ data stream
/// \param[in] arr Pointer to the first element of the Python object data
/// stream
///
/// \returns PyObject corresponding to the python datastream.
///
inline static PyObject* getitem(void* ip, void* /*ap*/) {
// std::cout << "getitem" << std::endl;
T* elt_ptr = static_cast<T*>(ip);
bp::object m(*elt_ptr);
Py_INCREF(m.ptr());
return m.ptr();
static PyObject* getitem(void* ip, void* ap) {
return eigenpy::internal::getitem<T>::run(ip, ap);
}
///
......@@ -216,7 +223,7 @@ struct SpecialMethods<T, NPY_USERDEF> {
}
static int fill(void* data_, npy_intp length, void* /*arr*/) {
// std::cout << "fillwithscalar" << std::endl;
// std::cout << "fill" << std::endl;
T* data = static_cast<T*>(data_);
const T delta = data[1] - data[0];
T r = data[1];
......
Supports Markdown
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