Commit a6ac6f2a authored by Médéric Boquien's avatar Médéric Boquien
Browse files

Make the data member of SharedArray more robust by adding a setter. This...

Make the data member of SharedArray more robust by adding a setter. This setter checks that the variable to be assigned is indeed a ctypes.Array. This prevents from accidentally erasing data with a Numpy array for instance.
parent a7a24fc2
......@@ -35,12 +35,19 @@ class SharedArray(object):
"""
def __init__(self, shape):
self._shape = shape
self._data = RawArray(ctypes.c_double, int(np.product(self._shape)))
self.data = RawArray(ctypes.c_double, int(np.product(self._shape)))
@property
def data(self):
return np.ctypeslib.as_array(self._data).reshape(self._shape)
@data.setter
def data(self, data):
if isinstance(data, ctypes.Array):
self._data = data
else:
raise TypeError("Type must be RawArray.")
@property
def shape(self):
return self._shape
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 to comment