Ejemplo n.º 1
0
    def testStoreTileDB(self):
        ctx = tiledb.Ctx()
        tempdir = tempfile.mkdtemp()
        try:
            t = random.rand(50, 30, chunk_size=13)
            t2 = t + 1

            saved = totiledb(tempdir, t2)
            self.assertEqual(saved.shape, (0, 0))
            self.assertIsNone(saved.op.tiledb_config)
            self.assertEquals(saved.op.tiledb_uri, tempdir)

            with self.assertRaises(tiledb.TileDBError):
                tiledb.DenseArray(ctx=ctx, uri=tempdir)

            # tiledb array is created in the tile
            saved.tiles()

            # no error
            tiledb.DenseArray(ctx=ctx, uri=tempdir)

            self.assertEqual(saved.chunks[0].op.axis_offsets, (0, 0))
            self.assertEqual(saved.chunks[1].op.axis_offsets, (0, 13))
            self.assertEqual(saved.cix[0, 2].op.axis_offsets, (0, 26))
            self.assertEqual(saved.cix[1, 2].op.axis_offsets, (13, 26))
            self.assertEqual(saved.cix[3, 2].op.axis_offsets, (39, 26))

            with self.assertRaises(ValueError):
                t3 = random.rand(30, 50)
                totiledb(tempdir, t3, ctx=ctx)  # shape incompatible
        finally:
            shutil.rmtree(tempdir)
Ejemplo n.º 2
0
    def testCheckTileDB(self):
        ctx = tiledb.Ctx()

        tempdir = tempfile.mkdtemp()
        try:
            np_a = np.random.rand(2, 3)
            tiledb_a = tiledb.DenseArray.from_numpy(ctx=ctx,
                                                    uri=tempdir,
                                                    array=np_a)

            with self.assertRaises(ValueError):
                # ndim not match
                check_tiledb_array_with_tensor(random.rand(2, 3, 4), tiledb_a)

            with self.assertRaises(ValueError):
                # shape not matchn
                check_tiledb_array_with_tensor(random.rand(2, 4), tiledb_a)

            with self.assertRaises(ValueError):
                # dtype not match
                check_tiledb_array_with_tensor(
                    random.rand(2, 3, dtype=np.float32), tiledb_a)

            # legal
            check_tiledb_array_with_tensor(random.rand(2, 3), tiledb_a)
        finally:
            shutil.rmtree(tempdir)
Ejemplo n.º 3
0
    def testShuffle(self):
        with self.assertRaises(TypeError):
            shuffle('abc')

        x = rand(10, 10, chunk_size=2)
        shuffle(x)
        self.assertIsInstance(x.op, TensorPermutation)

        x = rand(10, 10, chunk_size=2)
        shuffle(x, axis=1)
        self.assertIsInstance(x.op, TensorPermutation)
        self.assertEqual(x.op.axis, 1)
Ejemplo n.º 4
0
def test_shuffle():
    with pytest.raises(TypeError):
        shuffle('abc')

    x = rand(10, 10, chunk_size=2)
    shuffle(x)
    assert isinstance(x.op, TensorPermutation)

    x = rand(10, 10, chunk_size=2)
    shuffle(x, axis=1)
    assert isinstance(x.op, TensorPermutation)
    assert x.op.axis == 1
Ejemplo n.º 5
0
    def testRandom(self):
        arr = rand(2, 3)

        self.assertIsNotNone(arr.dtype)

        arr = beta(1, 2, chunk_size=2).tiles()

        self.assertEqual(arr.shape, ())
        self.assertEqual(len(arr.chunks), 1)
        self.assertEqual(arr.chunks[0].shape, ())
        self.assertEqual(arr.chunks[0].op.dtype, np.dtype('f8'))

        arr = beta([1, 2], [3, 4], chunk_size=2).tiles()

        self.assertEqual(arr.shape, (2, ))
        self.assertEqual(len(arr.chunks), 1)
        self.assertEqual(arr.chunks[0].shape, (2, ))
        self.assertEqual(arr.chunks[0].op.dtype, np.dtype('f8'))

        arr = beta([[2, 3]],
                   from_ndarray([[4, 6], [5, 2]], chunk_size=2),
                   chunk_size=1,
                   size=(3, 2, 2)).tiles()

        self.assertEqual(arr.shape, (3, 2, 2))
        self.assertEqual(len(arr.chunks), 12)
        self.assertEqual(arr.chunks[0].op.dtype, np.dtype('f8'))
Ejemplo n.º 6
0
def test_random():
    arr = rand(2, 3)

    assert arr.dtype is not None

    arr = tile(beta(1, 2, chunk_size=2))

    assert arr.shape == ()
    assert len(arr.chunks) == 1
    assert arr.chunks[0].shape == ()
    assert arr.chunks[0].op.dtype == np.dtype('f8')

    arr = tile(beta([1, 2], [3, 4], chunk_size=2))

    assert arr.shape == (2, )
    assert len(arr.chunks) == 1
    assert arr.chunks[0].shape == (2, )
    assert arr.chunks[0].op.dtype == np.dtype('f8')

    arr = tile(
        beta([[2, 3]],
             from_ndarray([[4, 6], [5, 2]], chunk_size=2),
             chunk_size=1,
             size=(3, 2, 2)))

    assert arr.shape == (3, 2, 2)
    assert len(arr.chunks) == 12
    assert arr.chunks[0].op.dtype == np.dtype('f8')
Ejemplo n.º 7
0
def test_get_tile_db_schema():
    ctx = tiledb.Ctx()

    nsplits = ((1, 2), (3, 1), (2, 2, 1))
    a = random.rand(3, 4, 5, dtype=np.float64, chunk_size=nsplits)
    schema = get_tiledb_schema_from_tensor(a, ctx, nsplits)
    assert schema.ndim == 3
    assert schema.shape == (3, 4, 5)
    assert [schema.domain.dim(i).tile for i in range(a.ndim)] == [2, 3, 2]
    assert schema.attr(0).dtype == a.dtype
Ejemplo n.º 8
0
    def testGetTileDBSchema(self):
        ctx = tiledb.Ctx()

        nsplits = ((1, 2), (3, 1), (2, 2, 1))
        a = random.rand(3, 4, 5, dtype=np.float64, chunk_size=nsplits)
        schema = get_tiledb_schema_from_tensor(a, ctx, nsplits)
        self.assertEqual(schema.ndim, 3)
        self.assertEqual(schema.shape, (3, 4, 5))
        self.assertEqual([schema.domain.dim(i).tile for i in range(a.ndim)],
                         [2, 3, 2])
        self.assertEqual(schema.attr(0).dtype, a.dtype)
Ejemplo n.º 9
0
def test_store_tile_db():
    ctx = tiledb.Ctx()
    tempdir = tempfile.mkdtemp()
    try:
        t = random.rand(50, 30, chunk_size=13)
        t2 = t + 1

        saved = totiledb(tempdir, t2)
        assert saved.shape == (0, 0)
        assert saved.op.tiledb_config is None
        assert saved.op.tiledb_uri == tempdir

        with pytest.raises(tiledb.TileDBError):
            tiledb.DenseArray(ctx=ctx, uri=tempdir)

        # tiledb array is created in the tile
        saved = tile(saved)

        # no error
        tiledb.DenseArray(ctx=ctx, uri=tempdir)

        # TileDB consolidation
        assert len(saved.chunks) == 1

        assert saved.chunks[0].inputs[0].op.axis_offsets == (0, 0)
        assert saved.chunks[0].inputs[1].op.axis_offsets == (0, 13)
        assert saved.chunks[0].inputs[2].op.axis_offsets == (0, 26
                                                             )  # input (0, 2)
        assert saved.chunks[0].inputs[5].op.axis_offsets == (13, 26
                                                             )  # input (1, 2)
        assert saved.chunks[0].inputs[11].op.axis_offsets == (39, 26
                                                              )  # input (3, 2)

        with pytest.raises(ValueError):
            t3 = random.rand(30, 50)
            totiledb(tempdir, t3, ctx=ctx)  # shape incompatible
    finally:
        shutil.rmtree(tempdir)
Ejemplo n.º 10
0
    def testPermutation(self):
        x = permutation(10)

        self.assertEqual(x.shape, (10, ))
        self.assertIsInstance(x.op, TensorPermutation)

        x = x.tiles()

        self.assertEqual(len(x.chunks), 1)
        self.assertIsInstance(x.chunks[0].op, TensorPermutation)

        arr = from_ndarray([1, 4, 9, 12, 15], chunk_size=2)
        x = permutation(arr)

        self.assertEqual(x.shape, (5, ))
        self.assertIsInstance(x.op, TensorPermutation)

        x = x.tiles()
        arr = get_tiled(arr)

        self.assertEqual(len(x.chunks), 3)
        self.assertTrue(np.isnan(x.chunks[0].shape[0]))
        self.assertIs(x.chunks[0].inputs[0].inputs[0].inputs[0],
                      arr.chunks[0].data)

        arr = rand(3, 3, chunk_size=2)
        x = permutation(arr)

        self.assertEqual(x.shape, (3, 3))
        self.assertIsInstance(x.op, TensorPermutation)

        x = x.tiles()
        arr = get_tiled(arr)

        self.assertEqual(len(x.chunks), 4)
        self.assertTrue(np.isnan(x.chunks[0].shape[0]))
        self.assertEqual(x.chunks[0].shape[1], 2)
        self.assertIs(x.cix[0, 0].inputs[0].inputs[0].inputs[0],
                      arr.cix[0, 0].data)
        self.assertIs(x.cix[0, 0].inputs[0].inputs[1].inputs[0],
                      arr.cix[1, 0].data)
        self.assertEqual(x.cix[0, 0].op.seed, x.cix[0, 1].op.seed)
        self.assertEqual(x.cix[0, 0].inputs[0].inputs[0].inputs[0].op.seed,
                         x.cix[1, 0].inputs[0].inputs[0].inputs[0].op.seed)

        with self.assertRaises(np.AxisError):
            self.assertRaises(permutation('abc'))
Ejemplo n.º 11
0
def test_permutation():
    x = permutation(10)

    assert x.shape == (10, )
    assert isinstance(x.op, TensorPermutation)

    x = tile(x)

    assert len(x.chunks) == 1
    assert isinstance(x.chunks[0].op, TensorPermutation)

    arr = from_ndarray([1, 4, 9, 12, 15], chunk_size=2)
    x = permutation(arr)

    assert x.shape == (5, )
    assert isinstance(x.op, TensorPermutation)

    x = tile(x)
    arr = tile(arr)

    assert len(x.chunks) == 3
    assert np.isnan(x.chunks[0].shape[0])
    assert x.chunks[0].inputs[0].inputs[0].inputs[0].key == arr.chunks[
        0].data.key

    arr = rand(3, 3, chunk_size=2)
    x = permutation(arr)

    assert x.shape == (3, 3)
    assert isinstance(x.op, TensorPermutation)

    x = tile(x)
    arr = tile(arr)

    assert len(x.chunks) == 4
    assert np.isnan(x.chunks[0].shape[0])
    assert x.chunks[0].shape[1] == 2
    assert x.cix[0, 0].op.seed == x.cix[0, 1].op.seed
    assert x.cix[0, 0].inputs[0].inputs[0].inputs[0].op.seed == \
           x.cix[1, 0].inputs[0].inputs[0].inputs[0].op.seed

    with pytest.raises(np.AxisError):
        pytest.raises(permutation('abc'))
Ejemplo n.º 12
0
    def testUnexpectedKey(self):
        with self.assertRaises(ValueError):
            rand(10, 10, chunks=5)

        with self.assertRaises(ValueError):
            randn(10, 10, chunks=5)
Ejemplo n.º 13
0
def test_unexpected_key():
    with pytest.raises(ValueError):
        rand(10, 10, chunks=5)

    with pytest.raises(ValueError):
        randn(10, 10, chunks=5)