Commit fa9362b4 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Eteri

Fixup DataArrayView

parent 6252f617
...@@ -26,8 +26,52 @@ ...@@ -26,8 +26,52 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from numpy.lib.recfunctions import merge_arrays
from erp5.component.document.DataArray import DataArray from erp5.component.document.DataArray import DataArray
from numpy import dtype
from numpy.lib.recfunctions import merge_arrays
from wendelin.lib.calc import mul
import sys
class MergedArray(object):
def __init__(self, array_list):
self.array_list = array_list
def __getitem__(self, idx):
if not(isinstance, idx, slice):
raise TypeError("Only slice index is supported.")
if idx.start == 0 and idx.stop == sys.maxint:
raise ValueError("Only partial slice is supported")
return merge_arrays([a[0:len(self)][idx] for a in self.array_list], flatten=True)
# ~~~ ndarray-like attributes
@property
def data(self):
raise TypeError("Direct access to data for BigArray is forbidden")
@property
def strides(self):
return (self.itemsize,)
@property
def dtype(self):
return dtype(reduce(lambda x, y: [(n, x.dtype.fields[n][0]) for n in x.dtype.names] + [(n, y.dtype.fields[n][0]) for n in y.dtype.names], self.array_list))
@property
def shape(self):
return (min((len(a) for a in self.array_list)),)
@property
def size(self):
return mul(self.shape)
def __len__(self):
# lengths of the major axis
return self.shape[0]
@property
def itemsize(self):
return self.dtype.itemsize
@property
def nbytes(self):
return self.itemsize * self.size
@property
def ndim(self):
return len(self.shape)
class DataArrayView(DataArray): class DataArrayView(DataArray):
""" """
...@@ -44,7 +88,7 @@ class DataArrayView(DataArray): ...@@ -44,7 +88,7 @@ class DataArrayView(DataArray):
""" """
Get numpy view of views defined in Data Array View Lines. Get numpy view of views defined in Data Array View Lines.
""" """
line_list = [(l.getIntIndex(), l) for l in self.objectValues(portal_type="Data Array View Line")] line_list = [(l.getIntIndex(), l.getArray()) for l in self.objectValues(portal_type="Data Array View Line")]
if not line_list: if not line_list:
return None return None
return merge_arrays([l[1].getArray() for l in sorted(line_list)], flatten=True) return MergedArray([l[1] for l in sorted(line_list)])
\ No newline at end of file
...@@ -45,7 +45,9 @@ ...@@ -45,7 +45,9 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple/> <tuple>
<string>W: 81, 29: Redefining name \'dtype\' from outer scope (line 30) (redefined-outer-name)</string>
</tuple>
</value> </value>
</item> </item>
<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