32 #ifndef _cisstVector_i_h
33 #define _cisstVector_i_h
38 #include <arrayobject.h>
51 if (!PyArray_Check(input)) {
52 PyErr_SetString(PyExc_TypeError,
"Object must be a NumPy array");
59 template <
class _elementType>
62 PyErr_SetString(PyExc_ValueError,
"Unsupported data type");
70 if (PyArray_ObjectType(input, 0) != NPY_BOOL) {
71 PyErr_SetString(PyExc_ValueError,
"Array must be of type bool");
81 if (PyArray_ObjectType(input, 0) != NPY_INT8) {
82 PyErr_SetString(PyExc_ValueError,
"Array must be of type char (int8)");
92 if (PyArray_ObjectType(input, 0) != NPY_UINT8) {
93 PyErr_SetString(PyExc_ValueError,
"Array must be of type unsigned char (uint8)");
103 if (PyArray_ObjectType(input, 0) != NPY_INT16) {
104 PyErr_SetString(PyExc_ValueError,
"Array must be of type short (int16)");
114 if (PyArray_ObjectType(input, 0) != NPY_UINT16) {
115 PyErr_SetString(PyExc_ValueError,
"Array must be of type unsigned short (uint16)");
126 #if (CISST_DATA_MODEL == CISST_ILP32) || (CISST_DATA_MODEL == CISST_LLP64)
127 if ((PyArray_ObjectType(input, 0) != NPY_INT) && (PyArray_ObjectType(input, 0) != NPY_LONG))
129 if (PyArray_ObjectType(input, 0) != NPY_INT)
132 PyErr_SetString(PyExc_ValueError,
"Array must be of type int (int32)");
143 #if (CISST_DATA_MODEL == CISST_ILP32) || (CISST_DATA_MODEL == CISST_LLP64)
144 if ((PyArray_ObjectType(input, 0) != NPY_UINT) && (PyArray_ObjectType(input, 0) != NPY_ULONG))
146 if (PyArray_ObjectType(input, 0) != NPY_UINT)
149 PyErr_SetString(PyExc_ValueError,
"Array must be of type unsigned int (uint32)");
159 if (PyArray_ObjectType(input, 0) != NPY_INT64) {
160 PyErr_SetString(PyExc_ValueError,
"Array must be of type long int (int64)");
170 if (PyArray_ObjectType(input, 0) != NPY_UINT64) {
171 PyErr_SetString(PyExc_ValueError,
"Array must be of type unsigned long int (uint64)");
181 if (PyArray_ObjectType(input, 0) != NPY_FLOAT) {
182 PyErr_SetString(PyExc_ValueError,
"Array must be of type float");
192 if (PyArray_ObjectType(input, 0) != NPY_DOUBLE) {
193 PyErr_SetString(PyExc_ValueError,
"Array must be of type double");
200 template <
class _elementType>
279 if (PyArray_NDIM(input) != 1) {
280 PyErr_SetString(PyExc_ValueError,
"Array must be 1D (vector)");
289 if (PyArray_NDIM(input) != 2) {
290 PyErr_SetString(PyExc_ValueError,
"Array must be 2D (matrix)");
297 template <vct::
size_type _dimension>
300 if (PyArray_NDIM(input) != _dimension) {
301 std::stringstream stream;
302 stream <<
"Array must have " << _dimension <<
" dimension(s)";
303 std::string msg = stream.str();
304 PyErr_SetString(PyExc_ValueError, msg.c_str());
313 const int flags = PyArray_FLAGS(input);
314 if(!(flags & NPY_WRITEABLE)) {
315 PyErr_SetString(PyExc_ValueError,
"Array must be writable");
322 template <vct::
size_type _size, vct::str
ide_type _str
ide,
class _elementType,
class _dataPtrType>
328 if (inputSize != targetSize) {
329 std::stringstream stream;
330 stream <<
"Input vector's size must be " << targetSize;
331 std::string msg = stream.str();
332 PyErr_SetString(PyExc_ValueError, msg.c_str());
339 template <
class _vectorOwnerType,
typename _elementType>
349 class _elementType,
class _dataPtrType>
357 if ( inputRows != targetRows
358 || inputCols != targetCols) {
359 std::stringstream stream;
360 stream <<
"Input matrix's size must be " << targetRows <<
" rows by " << targetCols <<
" columns";
361 std::string msg = stream.str();
362 PyErr_SetString(PyExc_ValueError, msg.c_str());
369 template <
class _matrixOwnerType,
typename _elementType>
379 const int flags = PyArray_FLAGS(input);
380 if(!(flags & NPY_OWNDATA)) {
381 PyErr_SetString(PyExc_ValueError,
"Array must own its data");
388 template <vct::
size_type _size, vct::str
ide_type _str
ide,
class _elementType,
class _dataPtrType>
396 template <
class _vectorOwnerType,
typename _elementType>
400 const int flags = PyArray_FLAGS(input);
401 if(!(flags & NPY_OWNDATA)) {
402 PyErr_SetString(PyExc_ValueError,
"Array must own its data");
411 class _elementType,
class _dataPtrType>
419 template <
class _matrixOwnerType,
typename _elementType>
423 const int flags = PyArray_FLAGS(input);
424 if(!(flags & NPY_OWNDATA)) {
425 PyErr_SetString(PyExc_ValueError,
"Array must own its data");
434 if (PyArray_REFCOUNT(input) > 4) {
435 PyErr_SetString(PyExc_ValueError,
"Array must not be referenced by other objects. Try making a deep copy of the array and call the function again.");
442 template <vct::
size_type _size, vct::str
ide_type _str
ide,
class _elementType,
class _dataPtrType>
450 template <
class _vectorOwnerType,
typename _elementType>
454 if (PyArray_REFCOUNT(input) > 4) {
455 PyErr_SetString(PyExc_ValueError,
"Array must not be referenced by other objects. Try making a deep copy of the array and call the function again.");
464 class _elementType,
class _dataPtrType>
472 template <
class _matrixOwnerType,
typename _elementType>
476 if (PyArray_REFCOUNT(input) > 4) {
477 PyErr_SetString(PyExc_ValueError,
"Array must not be referenced by other objects. Try making a deep copy of the array and call the function again.");
485 #endif // _cisstVector_i_h
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
Assert macros definitions.
bool vctThrowUnlessIsPyArray(PyObject *input)
Definition: vctPythonUtilities.h:49
Declaration of vctDynamicConstMatrixBase.
bool vctThrowUnlessIsSameTypeArray< long int >(PyObject *input)
Definition: vctPythonUtilities.h:157
Portability across compilers and operating systems tools.
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
bool vctThrowUnlessIsWritable(PyObject *input)
Definition: vctPythonUtilities.h:311
bool vctThrowUnlessDimension1(PyObject *input)
Definition: vctPythonUtilities.h:277
bool vctThrowUnlessDimensionN(PyObject *input)
Definition: vctPythonUtilities.h:298
int vctPythonType< unsigned long int >(void)
Definition: vctPythonUtilities.h:264
bool vctThrowUnlessIsSameTypeArray< unsigned long int >(PyObject *input)
Definition: vctPythonUtilities.h:168
bool vctThrowUnlessIsSameTypeArray< float >(PyObject *input)
Definition: vctPythonUtilities.h:179
size_t size_type
Definition: vctContainerTraits.h:35
int vctPythonType< unsigned short >(void)
Definition: vctPythonUtilities.h:236
bool vctThrowUnlessIsSameTypeArray< unsigned char >(PyObject *input)
Definition: vctPythonUtilities.h:90
int vctPythonType< int >(void)
Definition: vctPythonUtilities.h:243
bool vctThrowUnlessNotReferenced(PyObject *input)
Definition: vctPythonUtilities.h:432
int vctPythonType< long int >(void)
Definition: vctPythonUtilities.h:257
Definition: vctDynamicConstMatrixBase.h:77
bool vctThrowUnlessIsSameTypeArray< unsigned int >(PyObject *input)
Definition: vctPythonUtilities.h:140
bool vctThrowUnlessDimension2(PyObject *input)
Definition: vctPythonUtilities.h:287
int vctPythonType< bool >(void)
Definition: vctPythonUtilities.h:208
size_type size(void) const
Definition: vctFixedSizeConstVectorBase.h:205
int vctPythonType< short >(void)
Definition: vctPythonUtilities.h:229
bool vctThrowUnlessCorrectVectorSize(PyObject *input, const vctFixedSizeConstVectorBase< _size, _stride, _elementType, _dataPtrType > &target)
Definition: vctPythonUtilities.h:323
int vctPythonType< unsigned int >(void)
Definition: vctPythonUtilities.h:250
int vctPythonType< unsigned char >(void)
Definition: vctPythonUtilities.h:222
int vctPythonType< char >(void)
Definition: vctPythonUtilities.h:215
bool vctThrowUnlessIsSameTypeArray< unsigned short >(PyObject *input)
Definition: vctPythonUtilities.h:112
bool vctThrowUnlessIsSameTypeArray< bool >(PyObject *input)
Definition: vctPythonUtilities.h:68
int vctPythonType(void)
Definition: vctPythonUtilities.h:201
Declaration of vctFixedSizeConstVectorBase.
bool vctThrowUnlessIsSameTypeArray(PyObject *CMN_UNUSED(input))
Definition: vctPythonUtilities.h:60
Declaration of vctDynamicConstVectorBase.
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
bool vctThrowUnlessCorrectMatrixSize(PyObject *input, const vctFixedSizeConstMatrixBase< _rows, _cols, _rowStride, _colStride, _elementType, _dataPtrType > &target)
Definition: vctPythonUtilities.h:350
Definition: vctDynamicConstVectorBase.h:77
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
bool vctThrowUnlessIsSameTypeArray< short >(PyObject *input)
Definition: vctPythonUtilities.h:101
int vctPythonType< double >(void)
Definition: vctPythonUtilities.h:271
bool vctThrowUnlessIsSameTypeArray< int >(PyObject *input)
Definition: vctPythonUtilities.h:123
bool vctThrowUnlessIsSameTypeArray< char >(PyObject *input)
Definition: vctPythonUtilities.h:79
bool vctThrowUnlessOwnsData(PyObject *input)
Definition: vctPythonUtilities.h:377
bool vctThrowUnlessIsSameTypeArray< double >(PyObject *input)
Definition: vctPythonUtilities.h:190
Declaration of vctFixedSizeConstMatrixBase.
Declaration of vctDynamicConstNArrayBase.