def test_3D(self): sequence = [ [[3, 4, 5, 6], [8, 8]], [[7]], [[], [10, 0, 0, 1]] ] expected = [ [[3, 4, 5, 6], [8, 8, 0, 0]], [[7, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [10, 0, 0, 1]] ] self.assertEqual(expected, pad_sequences(sequence, self.padding_val).tolist())
def test_3D_numpy_different_shapes(self): sequence = [ [np.array([3, 4, 5, 6]), np.array([8, 8])], [np.array([7])], [np.array([]), np.array([10, 0, 0, 1])] ] expected = [ [[3, 4, 5, 6], [8, 8, 0, 0]], [[7, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [10, 0, 0, 1]] ] # padding value must have the same type as sequence elements self.assertEqual(expected, pad_sequences(sequence, np.int64(0)).tolist())
def test_3D_numpy(self): sequence = [ [np.array([10.1, 15.0]), np.array([0, 1.2])], [np.array([7.0, 100.0])], [np.array([5.0, 5.0]), np.array([20.2, 20.0]), np.array([100.1, 100.0])] ] expected = [ [[10.1, 15], [0, 1.2], [0, 0]], [[7, 100], [0, 0], [0, 0]], [[5, 5], [20.2, 20], [100.1, 100]] ] # padding value must have the same type as sequence elements self.assertEqual(expected, pad_sequences(sequence, 0.0).tolist())
def test_2D_numpy(self): sequence = [np.array([3, 4, 5, 6]), np.array([7]), np.array([]), np.array([10, 0, 0, 1])] expected = [[3, 4, 5, 6], [7, 0, 0, 0], [0, 0, 0, 0], [10, 0, 0, 1]] self.assertEqual(expected, pad_sequences(sequence, np.int64(0)).tolist())
def test_1D(self): sequence = [3, 4, 5, 6] expected = sequence self.assertEqual(expected, pad_sequences(sequence, self.padding_val).tolist())