Test from_padded function
@@ -30,6 +30,21 @@ def test_ragged_to_padded(extra_dims, lengths, pad_to, expected_shape):
assert padded.shape == expected_shape
+@pytest.mark.parametrize("shape,lengths,expected_shape", [
+ ((1,2), [3], (3,)),
+ ((2,3), [3,2], (5,)),
+ ((2,4,4), [4,2], (6,4)),
+ ((4,5,2), [5,2,1,3], (11,2)),
+])
+def test_ragged_from_padded(shape, lengths, expected_shape):
+ padded = numpy.ones(shape, dtype="i")
+ for i, length in enumerate(lengths):
+ padded[i, length:] = 0
+ ragged = RaggedArray.from_padded(padded, lengths)
+ assert ragged.data.shape == expected_shape
+ assert ragged.data.sum() == padded.sum()
+
+
@pytest.mark.parametrize("shape,lengths,expected_shape", [
((1,2), [3], (3,)),
((2,2), [3,2], (5,)),
