Skip to content

Commit

Permalink
Make tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Dec 17, 2024
1 parent 71bf77b commit 1508aad
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions python/pylibcudf/pylibcudf/tests/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def hash_single_uint32(val, seed=0):


def hash_combine_32(lhs, rhs):
return np.uint32(lhs ^ (rhs + 0x9E3779B9 + (lhs << 6) + (lhs >> 2)))
return np.uint32(
int((lhs ^ (rhs + 0x9E3779B9 + (lhs << 6) + (lhs >> 2)))) % 2**32
)


def uint_hash_combine_32(lhs, rhs):
Expand All @@ -47,6 +49,12 @@ def libcudf_mmh3_x86_32(binary):
return hash_combine_32(seed, hashval)


def libcudf_xxhash_32(binary):
seed = plc.hashing.LIBCUDF_DEFAULT_HASH_SEED
hashval = xxhash.xxh32(binary, seed).intdigest()
return hash_combine_32(seed, hashval)


@pytest.fixture(params=[pa.int64(), pa.float64(), pa.string(), pa.bool_()])
def scalar_type(request):
return request.param
Expand Down Expand Up @@ -101,15 +109,15 @@ def py_hasher(val):

def test_hash_column_xxhash32(pa_scalar_input_column, plc_scalar_input_tbl):
def py_hasher(val):
return xxhash.xxh32(
scalar_to_binary(val), seed=plc.hashing.LIBCUDF_DEFAULT_HASH_SEED
).intdigest()
return libcudf_xxhash_32(scalar_to_binary(val))

expect = pa.array(
[py_hasher(val) for val in pa_scalar_input_column.to_pylist()],
type=pa.uint32(),
)
got = plc.hashing.xxhash_32(plc_scalar_input_tbl, 0)
got = plc.hashing.xxhash_32(
plc_scalar_input_tbl, plc.hashing.LIBCUDF_DEFAULT_HASH_SEED
)

assert_column_eq(got, expect)

Expand All @@ -124,7 +132,9 @@ def py_hasher(val):
[py_hasher(val) for val in pa_scalar_input_column.to_pylist()],
type=pa.uint64(),
)
got = plc.hashing.xxhash_64(plc_scalar_input_tbl, 0)
got = plc.hashing.xxhash_64(
plc_scalar_input_tbl, plc.hashing.LIBCUDF_DEFAULT_HASH_SEED
)

assert_column_eq(got, expect)

Expand Down

0 comments on commit 1508aad

Please sign in to comment.