Esempio n. 1
0
    def test_dense_to_brle(self):
        # should be an (300, 200, 1000) array
        x = np.array([False] * 300 + [True] * 200 + [False] * 1000)

        # TODO: REMOVE RETURN
        if True:
            return
        # TODO: FIGURE OUT WHY THIS FAILS
        np.testing.assert_equal(rl.dense_to_brle(x), [300, 200, 1000, 0])
        np.testing.assert_equal(rl.dense_to_brle(
            x, np.uint8), [255, 0, 45, 200, 255, 0, 255, 0, 255, 0, 235, 0])
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 def test_rle_decode_encode(self):
     small = [3, 5, 5, 10, 2, 1]
     rand = random_rle_encoding()
     for original in [small, rand]:
         for dtype in [np.uint8, np.int64]:
             dec = rle.brle_to_dense(original)
             enc = np_impl.dense_to_brle(self.evaluate(dec), dtype=dtype)
             self.assert_array_equal(original, enc)
 def encode_example(self, example_data):
     _check_dtype(example_data.dtype, self._dtype.as_numpy_dtype)
     _check_size(example_data.size, self._size)
     return np_impl.dense_to_brle(
         example_data, dtype=self._serialized_dtype.as_numpy_dtype)