|
14 | 14 | import tiledb
|
15 | 15 | from tiledb import SparseArray
|
16 | 16 |
|
17 |
| -from .strategies import bounded_ntuple, ranged_slices |
| 17 | +from .strategies import bounded_anytuple, bounded_ntuple, ranged_slices |
18 | 18 |
|
19 | 19 |
|
20 | 20 | def is_boundserror(exc: Exception):
|
@@ -164,3 +164,67 @@ def test_multi_index_inputs(self, sparse_array_1d, ind):
|
164 | 164 | assume(False)
|
165 | 165 | else:
|
166 | 166 | raise
|
| 167 | + |
| 168 | + |
| 169 | +class TestMultiIndexTwoWayDense: |
| 170 | + @classmethod |
| 171 | + @pytest.fixture(scope="class") |
| 172 | + def dense_array_2d(cls, checked_path): |
| 173 | + def create_array(uri): |
| 174 | + dims = [ |
| 175 | + tiledb.Dim(name="d1", dtype=np.int64, domain=(0, 99), tile=3), |
| 176 | + tiledb.Dim(name="d2", dtype=np.int64, domain=(1, 100), tile=2), |
| 177 | + ] |
| 178 | + domain = tiledb.Domain(*dims) |
| 179 | + |
| 180 | + attrs = [tiledb.Attr(name="a1", dtype=np.int64)] |
| 181 | + |
| 182 | + schema = tiledb.ArraySchema( |
| 183 | + domain, |
| 184 | + attrs=attrs, |
| 185 | + cell_order="row-major", |
| 186 | + tile_order="row-major", |
| 187 | + sparse=False, |
| 188 | + ) |
| 189 | + |
| 190 | + tiledb.Array.create(uri, schema) |
| 191 | + |
| 192 | + def write_dense(uri): |
| 193 | + data = np.arange(100**2, dtype=np.int64).reshape(100, 100) |
| 194 | + with tiledb.open(uri, "w") as A: |
| 195 | + A[:] = data |
| 196 | + |
| 197 | + uri = checked_path.path() |
| 198 | + create_array(uri) |
| 199 | + write_dense(uri) |
| 200 | + |
| 201 | + a1 = tiledb.open(uri, config={"sm.query.dense.reader": "legacy"}) |
| 202 | + a2 = tiledb.open(uri, config={"sm.query.dense.reader": "refactored"}) |
| 203 | + |
| 204 | + return a1, a2 |
| 205 | + |
| 206 | + @given( |
| 207 | + bounded_anytuple(min_value=0, max_value=99), |
| 208 | + bounded_anytuple(min_value=1, max_value=100), |
| 209 | + ) |
| 210 | + def test_ref_2d_points(self, dense_array_2d, pts1, pts2): |
| 211 | + a1_legacy, a1_ref = dense_array_2d |
| 212 | + |
| 213 | + # print(r1,r2) |
| 214 | + np.testing.assert_array_equal( |
| 215 | + a1_legacy.multi_index[list(pts1), list(pts2)]["a1"], |
| 216 | + a1_ref.multi_index[list(pts1), list(pts2)]["a1"], |
| 217 | + ) |
| 218 | + |
| 219 | + @given( |
| 220 | + st.lists(ranged_slices(min_value=0, max_value=99)).filter(lambda x: x != []), |
| 221 | + st.lists(ranged_slices(min_value=1, max_value=100).filter(lambda x: x != [])), |
| 222 | + ) |
| 223 | + def test_ref_2d_slicing(self, dense_array_2d, ranges1, ranges2): |
| 224 | + a1_legacy, a1_ref = dense_array_2d |
| 225 | + |
| 226 | + # print(ranges1, ranges2) |
| 227 | + np.testing.assert_array_equal( |
| 228 | + a1_legacy.multi_index[list(ranges1), list(ranges2)]["a1"], |
| 229 | + a1_ref.multi_index[list(ranges1), list(ranges2)]["a1"], |
| 230 | + ) |
0 commit comments