Commit c850a14d authored by Ivan Tyagov's avatar Ivan Tyagov

More testing and API extension.

parent e101ff9c
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.BigFile import BigFile from Products.ERP5.Document.BigFile import BigFile
from wendelin.bigarray.array_zodb import ZBigArray
import transaction
class DataArray(BigFile): class DataArray(BigFile):
""" """
...@@ -46,10 +48,23 @@ class DataArray(BigFile): ...@@ -46,10 +48,23 @@ class DataArray(BigFile):
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.CategoryCore property_sheets = ( PropertySheet.CategoryCore
, PropertySheet.SortIndex , PropertySheet.SortIndex
, PropertySheet.DataArray
) )
def initArray(self, shape, dtype):
"""
Initialise array.
"""
array = ZBigArray(shape, dtype)
self._setArray(array)
def _setArray(self, value): def _setArray(self, value):
""" """
Set numpy array to this ERP5 Data Array. Set numpy array to this ERP5 Data Array.
""" """
self.array = value self.array = value
\ No newline at end of file
# 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
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import msgpack import msgpack
import numpy as np import numpy as np
import transaction #import transaction
class Test(ERP5TypeTestCase): class Test(ERP5TypeTestCase):
""" """
...@@ -99,25 +99,31 @@ class Test(ERP5TypeTestCase): ...@@ -99,25 +99,31 @@ class Test(ERP5TypeTestCase):
data_array = self.portal.data_array_module.newContent( \ data_array = self.portal.data_array_module.newContent( \
portal_type = 'Data Array') portal_type = 'Data Array')
array = ZBigArray((60,60), np.uint8) data_array.initArray((3, 3), np.uint8)
# ZBigArray requirement: before we can compute it (with subobject
# .zfile) have to be made explicitly known to connection or current
# transaction committed
transaction.commit()
data_array.setArray(array)
self.tic() self.tic()
# test array stored and we teturn ZBig Array instance # test array stored and we return ZBig Array instance
persistent_zbig_array = data_array.getArray() persistent_zbig_array = data_array.getArray()
self.assertEqual(ZBigArray, persistent_zbig_array.__class__) self.assertEqual(ZBigArray, persistent_zbig_array.__class__)
self.assertEquals(array, persistent_zbig_array)
# try to resize it # try to resize its numpy "view" and check that persistent one is not saved
#pure_numpy_array = persistent_zbig_array[:,:] # ZBigArray -> ndarray view of it # as these are differerent objects
#pure_numpy_array = np.resize(pure_numpy_array, (100,100)) pure_numpy_array = persistent_zbig_array[:,:] # ZBigArray -> ndarray view of it
#self.assertNotEquals(pure_numpy_array.shape, persistent_zbig_array.shape) pure_numpy_array = np.resize(pure_numpy_array, (4, 4))
self.assertNotEquals(pure_numpy_array.shape, persistent_zbig_array.shape)
# test copy numpy -> wendelin but first resize persistent one (add new one)
data_array.initArray((4, 4), np.uint8)
persistent_zbig_array = data_array.getArray()
rows = [0,1]
cols = [2,2]
new_array = np.arange(1,17).reshape((4,4))
persistent_zbig_array[:,:] = new_array
self.assertEquals(new_array.shape, persistent_zbig_array.shape)
# (enable when new wendelin.core released as it can kill system)
#self.assertTrue(np.array_equal(a, persistent_zbig_array))
# resize Zbig Array # resize Zbig Array (enable when new wendelin.core released as it can kill system)
#persistent_zbig_array.resize(100,100) #persistent_zbig_array = np.resize(persistent_zbig_array, (100,100))
\ No newline at end of file #self.assertNotEquals(pure_numpy_array.shape, persistent_zbig_array.shape)
\ No newline at end of file
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
<tuple> <tuple>
<string>W: 53, 4: Unused variable \'scipy\' (unused-variable)</string> <string>W: 53, 4: Unused variable \'scipy\' (unused-variable)</string>
<string>W: 54, 4: Unused variable \'sklearn\' (unused-variable)</string> <string>W: 54, 4: Unused variable \'sklearn\' (unused-variable)</string>
<string>W:118, 4: Unused variable \'rows\' (unused-variable)</string>
<string>W:119, 4: Unused variable \'cols\' (unused-variable)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
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