Commit d7693e87 authored by Ivan Tyagov's avatar Ivan Tyagov

Implement array slicing in its most simple list alike form + test of it.

parent 81c688e0
......@@ -57,7 +57,7 @@ class DataArray(BigFile):
"""
array = ZBigArray(shape, dtype)
self._setArray(array)
def getArray(self, default=None):
"""
Get numpy array value.
......@@ -73,4 +73,12 @@ class DataArray(BigFile):
# ZBigArray requirement: before we can compute it (with subobject
# .zfile) have to be made explicitly known to connection or current
# transaction committed (XXX: impossible to use as raises ConflictErrors)
transaction.commit()
\ No newline at end of file
transaction.commit()
def getArraySlice(self, start, end):
"""
Implement array slicing in its most simple list alike form.
Any other advanced slicing techniques currently possible by getting
array reference directly.
"""
return self.getArray()[start:end]
\ No newline at end of file
......@@ -258,4 +258,25 @@ context.activate().DataStream_readChunkListAndTransform( \
# resize Zbig Array
persistent_zbig_array = np.resize(persistent_zbig_array, (100,100))
self.assertNotEquals(pure_numpy_array.shape, persistent_zbig_array.shape)
\ No newline at end of file
self.assertNotEquals(pure_numpy_array.shape, persistent_zbig_array.shape)
# get array slice (fails)
data_array = self.portal.data_array_module.newContent( \
portal_type = 'Data Array')
shape = (1000,)
data_array.initArray(shape, np.uint8)
self.tic()
persistent_zbig_array = data_array.getArray()
new_array = np.arange(1000)
new_array.resize(shape)
self.assertEquals(new_array.shape, persistent_zbig_array.shape)
persistent_zbig_array[:,] = new_array
self.tic()
self.assertTrue(
np.array_equal(data_array.getArraySlice(0,100), \
new_array[:100]))
\ No newline at end of file
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