if len(set(seq.shape[1:] for seq in seqs)) != 1:
raise ValueError("Cannot pad sequences that differ on other dimensions")
// Find the maximum dimension along each axis. That"s what we"ll pad to.
shapes = [tuple(s.shape) for s in seqs]dim_sizes = zip(*[shape for shape in shapes])
max_dims = [max(sizes) for sizes in dim_sizes]
final_shape = (len(seqs),) + tuple(max_dims)
output = self.alloc(final_shape, dtype=seqs[0].dtype)
for i, arr in enumerate(seqs):
region = [i] + [slice(0, dim) for dim in arr.shape]
output = index_update(output, index[region], arr)
return output
def list2padded(self, seqs: List[Array2d]) -> Padded:
Pack a sequence of 2d arrays into a Padded datatype.
After Change
length = max(len(seq) for seq in seqs)
// Round the length
length = (length + (round_to-1)) // round_to * round_to
final_shape = (len(seqs), length) + seqs[0].shape[1:]
output = self.alloc(final_shape, dtype=seqs[0].dtype)
for i, arr in enumerate(seqs):
output[i, :arr.shape[0]] = arr