Skip to content
Snippets Groups Projects
Commit 127e57d9 authored by Joseph Gilbert's avatar Joseph Gilbert
Browse files

-bug fix: matrix_item callback now returns rows from a matrix as in previous...

-bug fix: matrix_item callback now returns rows from a matrix as in previous API implementation (exmple: ob.getMatrix()[0])
parent 6c650c58
No related branches found
No related tags found
No related merge requests found
...@@ -479,19 +479,23 @@ static PyObject * Matrix_repr (MatrixObject *self) ...@@ -479,19 +479,23 @@ static PyObject * Matrix_repr (MatrixObject *self)
} }
//no support for matrix[x][y] so have to return by sequence index //no support for matrix[x][y] so have to return by sequence index
//will return a row from the matrix to support previous API
//compatability
static PyObject * Matrix_item (MatrixObject *self, int i) static PyObject * Matrix_item (MatrixObject *self, int i)
{ {
int maxsize, x, y; float *vec;
int x;
maxsize = self->colSize * self->rowSize; if(i < 0 || i >= self->rowSize)
if(i < 0 || i >= maxsize)
return EXPP_ReturnPyObjError(PyExc_IndexError, return EXPP_ReturnPyObjError(PyExc_IndexError,
"array index out of range\n"); "matrix row index out of range\n");
x = (int)floor((double)(i / self->colSize)); vec = PyMem_Malloc (self->colSize *sizeof (float));
y = i % self->colSize; for(x = 0; x < self->colSize; x++){
vec[x] = self->matrix[i][x];
}
return PyFloat_FromDouble(self->matrix[x][y]); return (PyObject*)newVectorObject(vec, self->colSize);
} }
static PyObject *Matrix_slice(MatrixObject *self, int begin, int end) static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment