예제 #1
0
 def __getitem__(self, index):
     start, stop, shape = convert_multislice(index, self.shape, self._offsets)
     if not shape:
         log("YaskGrid: Getting single entry %s" % str(start))
         assert start == stop
         out = self.grid.get_element(*start)
     else:
         log("YaskGrid: Getting full-array/block via index [%s]" % str(index))
         out = np.empty(shape, self.dtype, 'C')
         self.grid.get_elements_in_slice(out.data, start, stop)
     return out
예제 #2
0
 def __setitem__(self, index, val):
     start, stop, shape = convert_multislice(index, self.shape, self._offsets, 'set')
     if all(i == 1 for i in shape):
         log("YaskGrid: Setting single entry %s" % str(start))
         assert start == stop
         self.grid.set_element(val, *start)
     elif isinstance(val, np.ndarray):
         log("YaskGrid: Setting full-array/block via index [%s]" % str(index))
         self.grid.set_elements_in_slice(val, start, stop)
     elif all(i == j-1 for i, j in zip(shape, self.shape)):
         log("YaskGrid: Setting full-array to given scalar via single grid sweep")
         self.grid.set_all_elements_same(val)
     else:
         log("YaskGrid: Setting block to given scalar via index [%s]" % str(index))
         self.grid.set_elements_in_slice_same(val, start, stop, True)