'Applies translations to data at index i in batch.'

def TranslateData(self, batch, i):

    sizeX = self.sizeX
    sizex = self.sizex
    batchsize = batch[i].shape[1]
    shift = ((sizeX - sizex) / 2)
    offset_x = np.array([(random.choice(self.translate_range_x) + shift) for k in range(batchsize)]).reshape(1, (-1))
    offset_y = np.array([(random.choice(self.translate_range_y) + shift) for k in range(batchsize)]).reshape(1, (-1))
    num_channels = self.num_channels
    d = batch[i]
    if (self.offset_x is None):
        self.offset_x = cm.CUDAMatrix(offset_x)
    else:
        self.offset_x.overwrite(offset_x)
    if (self.offset_y is None):
        self.offset_y = cm.CUDAMatrix(offset_y)
    else:
        self.offset_y.overwrite(offset_y)
    if ((self.translated_d is None) or (self.translated_d.shape[1] != batchsize)):
        self.translated_d = cm.empty((((sizex ** 2) * num_channels), batchsize))
    d.generate_translations(sizeX, sizex, self.offset_x, self.offset_y, target=self.translated_d)
    batch[i] = self.translated_d
