| 5322 | |
| 5323 | |
| 5324 | def test_tiledb_roundtrip(): |
| 5325 | tiledb = pytest.importorskip("tiledb") |
| 5326 | # 1) load with default chunking |
| 5327 | # 2) load from existing tiledb.DenseArray |
| 5328 | # 3) write to existing tiledb.DenseArray |
| 5329 | rng = da.random.default_rng() |
| 5330 | a = rng.random((3, 3)) |
| 5331 | with tmpdir() as uri: |
| 5332 | da.to_tiledb(a, uri) |
| 5333 | tdb = da.from_tiledb(uri) |
| 5334 | |
| 5335 | assert_eq(a, tdb) |
| 5336 | assert a.chunks == tdb.chunks |
| 5337 | |
| 5338 | # from tiledb.array |
| 5339 | with tiledb.open(uri) as t: |
| 5340 | tdb2 = da.from_tiledb(t) |
| 5341 | assert_eq(a, tdb2) |
| 5342 | |
| 5343 | with tmpdir() as uri2: |
| 5344 | with tiledb.empty_like(uri2, a) as t: |
| 5345 | a.to_tiledb(t) |
| 5346 | assert_eq(da.from_tiledb(uri2), a) |
| 5347 | |
| 5348 | # specific chunking |
| 5349 | with tmpdir() as uri: |
| 5350 | a = rng.random((3, 3), chunks=(1, 1)) |
| 5351 | a.to_tiledb(uri) |
| 5352 | tdb = da.from_tiledb(uri) |
| 5353 | |
| 5354 | assert_eq(a, tdb) |
| 5355 | assert a.chunks == tdb.chunks |
| 5356 | |
| 5357 | |
| 5358 | def test_tiledb_multiattr(): |