Skip to content

Commit

Permalink
Add new hypothesis test for 2d dense comparing refactored and legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
ihnorton committed Mar 7, 2024
1 parent 57e96b6 commit 0ec82f8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
21 changes: 16 additions & 5 deletions tiledb/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ def bounded_ntuple(draw, *, length=1, min_value=0, max_value=10):
return draw(st.tuples(*[st.integers(min_value, max_value) for _ in range(length)]))


@composite
def bounded_anytuple(draw, *, min_value=0, max_value=10):
"""hypothesis composite strategy that returns a `length` tuple of integers
within the range (min_value, max_value)
"""

n = draw(st.integers(min_value=1, max_value=100))
return draw(st.tuples(*[st.integers(min_value, max_value) for _ in range(n)]))


@composite
def ranged_slices(draw, min_value=0, max_value=10):
bdd = st.one_of(st.none(), st.integers(min_value=min_value, max_value=max_value))
start = draw(bdd)
stop = draw(bdd)
step = draw(bdd)
bdd = st.integers(min_value=min_value, max_value=max_value)
start = draw(bdd.filter(lambda x: x is not None))
stop = draw(bdd.filter(lambda x: x is not None))
start, stop = sorted((start, stop))
# step = draw(bdd)

return slice(start, stop, step)
return slice(start, stop, None)
66 changes: 65 additions & 1 deletion tiledb/tests/test_multi_index-hp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import tiledb
from tiledb import SparseArray

from .strategies import bounded_ntuple, ranged_slices
from .strategies import bounded_anytuple, bounded_ntuple, ranged_slices


def is_boundserror(exc: Exception):
Expand Down Expand Up @@ -164,3 +164,67 @@ def test_multi_index_inputs(self, sparse_array_1d, ind):
assume(False)
else:
raise


class TestMultiIndexTwoWayDense:
@classmethod
@pytest.fixture(scope="class")
def dense_array_2d(cls, checked_path):
def create_array(uri):
dims = [
tiledb.Dim(name="d1", dtype=np.int64, domain=(0, 99), tile=3),
tiledb.Dim(name="d2", dtype=np.int64, domain=(1, 100), tile=2),
]
domain = tiledb.Domain(*dims)

attrs = [tiledb.Attr(name="a1", dtype=np.int64)]

schema = tiledb.ArraySchema(
domain,
attrs=attrs,
cell_order="row-major",
tile_order="row-major",
sparse=False,
)

tiledb.Array.create(uri, schema)

def write_dense(uri):
data = np.arange(100**2, dtype=np.int64).reshape(100, 100)
with tiledb.open(uri, "w") as A:
A[:] = data

uri = checked_path.path()
create_array(uri)
write_dense(uri)

a1 = tiledb.open(uri, config={"sm.query.dense.reader": "legacy"})
a2 = tiledb.open(uri, config={"sm.query.dense.reader": "refactored"})

return a1, a2

@given(
bounded_anytuple(min_value=0, max_value=99),
bounded_anytuple(min_value=1, max_value=100),
)
def test_ref_2d_points(self, dense_array_2d, pts1, pts2):
a1_legacy, a1_ref = dense_array_2d

# print(r1,r2)
np.testing.assert_array_equal(
a1_legacy.multi_index[list(pts1), list(pts2)]["a1"],
a1_ref.multi_index[list(pts1), list(pts2)]["a1"],
)

@given(
st.lists(ranged_slices(min_value=0, max_value=99)).filter(lambda x: x != []),
st.lists(ranged_slices(min_value=1, max_value=100).filter(lambda x: x != [])),
)
def test_ref_2d_slicing(self, dense_array_2d, ranges1, ranges2):
a1_legacy, a1_ref = dense_array_2d

# print(ranges1, ranges2)
np.testing.assert_array_equal(
a1_legacy.multi_index[list(ranges1), list(ranges2)]["a1"],
a1_ref.multi_index[list(ranges1), list(ranges2)]["a1"],
)

0 comments on commit 0ec82f8

Please sign in to comment.