Commit 4b9ae426 by Gael varoquaux

Cosmit

parent ac4f4190
......@@ -33,33 +33,35 @@ cdef class ArrayWrapper:
cdef int size
cdef set_data(self, int size, void* data_ptr):
""" Constructor for the class.
""" Set the data of the array
Mallocs a memory buffer of size (n*sizeof(int)) and sets up
the numpy array.
This cannot be done in the constructor as it must recieve C-level
arguments.
Parameters:
-----------
n -- Length of the array.
Data attributes:
----------------
data -- Pointer to an integer array.
alloc -- Size of the data buffer allocated.
size: int
Length of the array.
data_ptr: void*
Pointer to the data
"""
self.data_ptr = data_ptr
self.size = size
def __array__(self):
""" Here we use the __array__ method, that is called when numpy
tries to get an array from the object."""
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> self.size
# Create a 1D array, of length 'size'
ndarray = np.PyArray_SimpleNewFromData(1, shape,
np.NPY_INT, self.data_ptr)
np.NPY_INT, self.data_ptr)
return ndarray
def __dealloc__(self):
""" Frees the array. """
""" Frees the array. This is called by Python when all the
references to the object are gone. """
free(<void*>self.data_ptr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment