Skip to content

Commit

Permalink
Issue numenta#1380: Validate python parameters passed to SP compute m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
lscheinkman committed Jan 12, 2018
1 parent d608108 commit 2b6a35b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/nupic/bindings/algorithms.i
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 2b6a35b

Please sign in to comment.