Skip to content

Commit

Permalink
WIP add new hypothesis test for 2d dense comparing refactored and legacy
Browse files Browse the repository at this point in the history
WIP update
  • Loading branch information
ihnorton committed Apr 1, 2022
1 parent d502413 commit 5a41a2c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
19 changes: 14 additions & 5 deletions tiledb/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ 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 != None))
stop = draw(bdd.filter(lambda x: x != None))
start,stop = sorted((start,stop))
#step = draw(bdd)

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

import pytest
from tiledb.tests.common import checked_path
from tiledb.tests.strategies import bounded_ntuple, ranged_slices
from tiledb.tests.strategies import bounded_ntuple, bounded_anytuple, ranged_slices

from hypothesis import given, assume
from hypothesis import strategies as st
Expand Down Expand Up @@ -151,3 +151,68 @@ 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 5a41a2c

Please sign in to comment.