class Chunk(object): @pv.verify_method(pv.Var(a_name="box", a_type=Box), pv.Proxy()) def __init__(self, box, filler): if filler is None: raise TypeError("Chunk: expected filler, but received %s" % str(box)) self._box = box self._filler = filler
class Array(object): @pv.verify_method(name=pv.Str("name"), attribute_list=pv.Iterable("attribute_list", a_type=Attribute), dimension_list=pv.Iterable("dimension_list", a_type=Dimension), filler=pv.Proxy()) def __init__(self, name=None, attribute_list=None, dimension_list=None): #, filler=None): #if filler is None: # raise TypeError("Array: expected filler, but received %s" % str(filler)) self._name = name self._attribute = attribute_list self._dimension = dimension_list #self._filler= filler(self) @property def name(self): return self._name @property def attribute_list(self): return self._attribute @property def dimension_list(self): return self._dimension @property def filler(self): return self._filler def __len__(self): 'Total count of chunks inside the array' return self._dimension.box_count() def __iter__(self): 'Iterate over chunks inside the array' def create_chunk(box): return Chunk(box, self.filler) return imap(create_chunk, self._dimension.box_iter()) #def dense(self): # return self.cell_print(dense=True) #def sparse(self): # return self.cell_print(dense=False) #@pv.verify_method(dense=pv.Bool("dense")) #def cell_print(self, dense=None): # sep= ';%s' % os.linesep # if dense: # f= Chunk.dense # else: # f= Chunk.sparse # return sep.join(map(f, list(self))) def create(self): return "create array %s <%s> [%s]" % (self.name, self.attribute_list.create(), self.dimension_list.create()) def remove(self): return "remove(%s)" % self._name