def __len__(self): if self.expr_list or self.expr_tensor: return super(LazyNumpyExpressionSequence, self).__len__() else: if Batcher.is_batched(self.lazy_data): return self.lazy_data[0].shape[0] else: return self.lazy_data.shape[0]
def __getitem__(self, key): if self.expr_list or self.expr_tensor: return super(LazyNumpyExpressionSequence, self).__getitem__(key) else: if Batcher.is_batched(self.lazy_data): return dy.inputTensor([ self.lazy_data[batch][key] for batch in range(len(self.lazy_data)) ], batched=True) else: return dy.inputTensor(self.lazy_data[key], batched=False)
def as_tensor(self): if not (self.expr_list or self.expr_tensor): self.expr_tensor = dy.inputTensor(self.lazy_data, batched=Batcher.is_batched( self.lazy_data)) return super(LazyNumpyExpressionSequence, self).as_tensor()