Skip to content

Commit

Permalink
npbackend: implemented flatten and ravel as methods. Fixes #5 and #9
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Jun 8, 2015
1 parent a045a54 commit c9fbfb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion bridge/npbackend/src/_bhmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct
int mmap_allocated;
}BhArray;

//Help function that returns number of bytes in 'ary'
//Help function that returns number of bytes in 'ary'
//BUT minimum 'itemsize', which mimic the behavior of NumPy
static int64_t ary_nbytes(const BhArray *ary)
{
Expand Down Expand Up @@ -522,6 +522,12 @@ BhArray_reshape(PyObject *self, PyObject *args)
return method2function("reshape", self, args);
}

static PyObject *
BhArray_flatten(PyObject *self, PyObject *args)
{
return method2function("flatten", self, args);
}

static PyObject *
BhArray_sum(PyObject *self, PyObject *args)
{
Expand All @@ -546,6 +552,8 @@ static PyMethodDef BhArrayMethods[] = {
{"reshape", BhArray_reshape, METH_VARARGS, "a.reshape(shape)\n\nReturns an array"
"containing the same data with a new shape.\n\n"
"Refer to `bohrium.reshape` for full documentation."},
{"flatten", BhArray_flatten, METH_VARARGS, "a.flatten()\n\nReturn a copy of the array collapsed into one dimension."},
{"ravel", BhArray_flatten, METH_VARARGS, "a.ravel()\n\nReturn a copy of the array collapsed into one dimension."},
{"sum", BhArray_sum, METH_VARARGS, "a.sum(axis=None, dtype=None, out=None)\n\n"
"Return the sum of the array elements over the given axis.\n\n"
"Refer to `bohrium.sum` for full documentation."},
Expand Down
10 changes: 10 additions & 0 deletions test/python/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def test_flatten(self,a):
exec(cmd)
return (res,cmd)

def test_flatten_self(self,a):
cmd = "res = a[0].flatten()"
exec(cmd)
return (res,cmd)

def test_ravel_self(self,a):
cmd = "res = a[0].ravel()"
exec(cmd)
return (res,cmd)

class test_diagonal(numpytest):

def init(self):
Expand Down

0 comments on commit c9fbfb4

Please sign in to comment.