diff --git a/src/nupic/bindings/algorithms.i b/src/nupic/bindings/algorithms.i index 95a410ab98..9b4d82e8fe 100644 --- a/src/nupic/bindings/algorithms.i +++ b/src/nupic/bindings/algorithms.i @@ -1163,10 +1163,22 @@ void forceRetentionOfImageSensorLiteLibrary(void) { self._initFromCapnpPyBytes(proto.as_builder().to_bytes()) # copy * 2 %} - inline void compute(PyObject *py_x, bool learn, PyObject *py_y) + inline void compute(PyObject *py_inputArray, bool learn, PyObject *py_activeArray) { - PyArrayObject* x = (PyArrayObject*) py_x; - PyArrayObject* y = (PyArrayObject*) py_y; + PyArrayObject* x = (PyArrayObject*) py_inputArray; + PyArrayObject* y = (PyArrayObject*) py_activeArray; + if (!PyArray_ISUNSIGNED(x) || PyArray_DTYPE(x)->elsize != sizeof(nupic::UInt)) + { + NTA_THROW << "Invalid data type given for input array." + << " Expecting 'uint" << sizeof(nupic::UInt) * 8 << "'" + << " but got '" << PyArray_DTYPE(x)->type << "'"; + } + if (!PyArray_ISUNSIGNED(y) || PyArray_DTYPE(y)->elsize != sizeof(nupic::UInt)) + { + NTA_THROW << "Invalid data type given for active array." + << " Expecting 'uint" << sizeof(nupic::UInt) * 8 << "'" + << " but got '" << PyArray_DTYPE(y)->type << "'"; + } self->compute((nupic::UInt*) PyArray_DATA(x), (bool)learn, (nupic::UInt*) PyArray_DATA(y)); }