5 #ifndef __eigenpy_user_type_hpp__ 6 #define __eigenpy_user_type_hpp__ 16 template<typename T, int type_code = NumpyEquivalentType<T>::type_code>
19 inline static void copyswap(
void * ,
void * ,
int ,
void * ) ;
20 inline static PyObject *
getitem(
void * ,
void * ) ;
21 inline static int setitem(PyObject * ,
void * ,
void * ) ;
22 inline static void copyswapn(
void * ,
long ,
void * ,
23 long ,
long ,
int ,
void * ) ;
24 inline static npy_bool
nonzero(
void * ,
void * ) ;
25 inline static void dotfunc(
void * , npy_intp ,
void * , npy_intp ,
26 void * , npy_intp ,
void * );
33 inline static void copyswap(
void * dst,
void *
src,
int swap,
void * )
38 T & t1 = *
static_cast<T*
>(dst);
39 T & t2 = *
static_cast<T*
>(
src);
45 T & t1 = *
static_cast<T*
>(dst);
46 T & t2 = *
static_cast<T*
>(
src);
51 inline static PyObject *
getitem(
void * ip,
void * ap)
54 PyArrayObject * py_array =
static_cast<PyArrayObject *
>(ap);
55 if((py_array==NULL) || PyArray_ISBEHAVED_RO(py_array))
57 T * elt_ptr =
static_cast<T*
>(ip);
58 bp::object m(boost::ref(*elt_ptr));
64 T * elt_ptr =
static_cast<T*
>(ip);
65 bp::object m(boost::ref(*elt_ptr));
71 inline static int setitem(PyObject * src_obj,
void * dest_ptr,
void *
array)
79 PyArrayObject * py_array =
static_cast<PyArrayObject *
>(
array);
80 PyArray_Descr * descr = PyArray_DTYPE(py_array);
81 PyTypeObject * array_scalar_type = descr->typeobj;
82 PyTypeObject * src_obj_type = Py_TYPE(src_obj);
84 if(array_scalar_type != src_obj_type)
89 bp::extract<T&> extract_src_obj(src_obj);
90 if(!extract_src_obj.check())
93 ss <<
"The input type is of wrong type. ";
94 ss <<
"The expected type is " << bp::type_info(
typeid(T)).name() << std::endl;
99 const T &
src = extract_src_obj();
100 T & dest = *
static_cast<T*
>(dest_ptr);
106 inline static void copyswapn(
void * dst,
long dstride,
void *
src,
long sstride,
107 long n,
int swap,
void *
array)
111 char *dstptr =
static_cast<char*
>(dst);
112 char *srcptr =
static_cast<char*
>(
src);
114 PyArrayObject * py_array =
static_cast<PyArrayObject *
>(
array);
115 PyArray_CopySwapFunc *
copyswap = PyArray_DESCR(py_array)->f->copyswap;
117 for (npy_intp i = 0; i < n; i++)
119 copyswap(dstptr, srcptr, swap, array);
128 static const T ZeroValue = T(0);
129 PyArrayObject * py_array =
static_cast<PyArrayObject *
>(
array);
130 if(py_array == NULL || PyArray_ISBEHAVED_RO(py_array))
132 const T &
value = *
static_cast<T*
>(ip);
133 return (npy_bool)(value != ZeroValue);
138 PyArray_DESCR(py_array)->f->copyswap(&tmp_value, ip, PyArray_ISBYTESWAPPED(py_array),
140 return (npy_bool)(tmp_value != ZeroValue);
144 inline static void dotfunc(
void * ip0_, npy_intp is0,
void * ip1_, npy_intp is1,
145 void * op, npy_intp n,
void * )
148 char *ip0 = (
char*)ip0_, *ip1 = (
char*)ip1_;
150 for(i = 0; i < n; i++)
153 res += *
static_cast<T*
>(
static_cast<void*
>(ip0))
154 * *
static_cast<T*
>(
static_cast<void*
>(ip1));
158 *
static_cast<T*
>(op) = res;
169 template<
typename Scalar>
174 if(isNumpyNativeType<Scalar>())
178 if(py_type_ptr == NULL)
180 py_type_ptr = Register::getPyType<Scalar>();
197 getitem, setitem, nonzero,
209 #endif // __eigenpy_user_type_hpp__ #define call_PyArray_DescrFromType(typenum)
static npy_bool nonzero(void *ip, void *array)
static PyObject * getitem(void *ip, void *ap)
static int setitem(PyObject *, void *, void *)
static npy_bool nonzero(void *, void *)
static int setitem(PyObject *src_obj, void *dest_ptr, void *array)
static PyObject * getitem(void *, void *)
static void dotfunc(void *, npy_intp, void *, npy_intp, void *, npy_intp, void *)
static int registerNewType(PyTypeObject *py_type_ptr, const std::type_info *type_info_ptr, const int type_size, PyArray_GetItemFunc *getitem, PyArray_SetItemFunc *setitem, PyArray_NonzeroFunc *nonzero, PyArray_CopySwapFunc *copyswap, PyArray_CopySwapNFunc *copyswapn, PyArray_DotFunc *dotfunc)
static void dotfunc(void *ip0_, npy_intp is0, void *ip1_, npy_intp is1, void *op, npy_intp n, void *)
static void copyswapn(void *, long, void *, long, long, int, void *)
static void copyswap(void *, void *, int, void *)
static bool isRegistered()
#define call_PyArray_RegisterCanCast(descr, totype, scalar)
static void copyswap(void *dst, void *src, int swap, void *)
int registerNewType(PyTypeObject *py_type_ptr=NULL)
static void copyswapn(void *dst, long dstride, void *src, long sstride, long n, int swap, void *array)