def test_brle_to_dense(self): np.testing.assert_equal( rl.brle_to_dense(np.array([300, 200, 1000, 0], dtype=np.int64)), [False] * 300 + [True] * 200 + [False] * 1000) np.testing.assert_equal( rl.brle_to_dense( np.array([255, 0, 45, 200, 255, 0, 255, 0, 255, 0, 235, 0], dtype=np.int64)), [False] * 300 + [True] * 200 + [False] * 1000)
def test_brle_mask(self): brle_data = random_brle_encoding() dense = rl.brle_to_dense(brle_data) mask = np.random.uniform(size=dense.shape) > 0.8 expected = dense[mask] actual = tuple(rl.brle_mask(brle_data, mask)) np.testing.assert_equal(actual, expected)
def test_brle_to_rle(self): brle_data = random_brle_encoding() brle_dense = rl.brle_to_dense(brle_data) rle_data = rl.brle_to_rle(brle_data) rle_dense = rl.rle_to_dense(rle_data) np.testing.assert_equal(brle_dense, rle_dense) np.testing.assert_equal(rl.brle_to_rle([0, 5, 2, 0]), [1, 5, 0, 2])
def test_brle_decode_encode(self): small = [3, 5, 5, 10, 2, 1] rand = random_brle_encoding() for original in [small, rand]: for dtype in [np.uint8, np.int64]: dec = rl.brle_to_dense(original) enc = rl.dense_to_brle(dec, dtype=dtype) np.testing.assert_equal(original, enc)
def test_brle_encode_decode(self): small = np.array([False] * 500 + [True] * 1000 + [False], dtype=bool) rand = np.random.uniform(size=(10000, )) > 0.05 for original in [small, rand]: for dtype in [np.uint8, np.int64]: enc = rl.dense_to_brle(original, dtype=dtype) dec = rl.brle_to_dense(enc) np.testing.assert_equal(original, dec)
def test_brle_logical_not(self): original = random_brle_encoding(dtype=np.int64) notted = rl.brle_logical_not(original) dense_notted = rl.brle_to_dense(notted) dense_original = rl.brle_to_dense(original) np.testing.assert_equal(dense_notted, np.logical_not(dense_original))
def test_brle_length(self): enc = random_brle_encoding(dtype=np.int64) dec = rl.brle_to_dense(enc) np.testing.assert_equal(len(dec), rl.brle_length(enc))