diff --git a/cpp/test/linalg/divide.cu b/cpp/test/linalg/divide.cu index 914ef21269..d620979c2f 100644 --- a/cpp/test/linalg/divide.cu +++ b/cpp/test/linalg/divide.cu @@ -57,7 +57,6 @@ class DivideTest : public ::testing::TestWithParamx_cai["data"][0] y_ptr = y_cai["data"][0] @@ -132,6 +152,12 @@ def distance(X, Y, dists, metric="euclidean"): y_dt = np.dtype(y_cai["typestr"]) d_dt = np.dtype(dists_cai["typestr"]) + x_c_contiguous = is_c_cont(x_cai, x_dt) + y_c_contiguous = is_c_cont(y_cai, y_dt) + + if x_c_contiguous != y_c_contiguous: + raise ValueError("Inputs must have matching strides") + if metric not in SUPPORTED_DISTANCES: raise ValueError("metric %s is not supported" % metric) @@ -147,10 +173,10 @@ def distance(X, Y, dists, metric="euclidean"): d_ptr, m, n, - k, + x_k, distance_type, - True, - 0.0) + x_c_contiguous, + p) elif x_dt == np.float64: pairwise_distance(deref(h), x_ptr, @@ -158,9 +184,9 @@ def distance(X, Y, dists, metric="euclidean"): d_ptr, m, n, - k, + x_k, distance_type, - True, - 0.0) + x_c_contiguous, + p) else: raise ValueError("dtype %s not supported" % x_dt) diff --git a/python/pylibraft/pylibraft/test/test_distance.py b/python/pylibraft/pylibraft/test/test_distance.py index 594f6e2f66..d4f73ecf2b 100644 --- a/python/pylibraft/pylibraft/test/test_distance.py +++ b/python/pylibraft/pylibraft/test/test_distance.py @@ -24,10 +24,10 @@ class TestDeviceBuffer: - def __init__(self, ndarray): + def __init__(self, ndarray, order): self.ndarray_ = ndarray self.device_buffer_ = \ - rmm.DeviceBuffer.to_device(ndarray.ravel(order="C").tobytes()) + rmm.DeviceBuffer.to_device(ndarray.ravel(order=order).tobytes()) @property def __cuda_array_interface__(self): @@ -49,10 +49,13 @@ def copy_to_host(self): @pytest.mark.parametrize("n_cols", [100]) @pytest.mark.parametrize("metric", ["euclidean", "cityblock", "chebyshev", "canberra", "correlation", "hamming", - "jensenshannon", "russellrao"]) + "jensenshannon", "russellrao", "cosine", + "sqeuclidean"]) +@pytest.mark.parametrize("order", ["F", "C"]) @pytest.mark.parametrize("dtype", [np.float32, np.float64]) -def test_distance(n_rows, n_cols, metric, dtype): - input1 = np.random.random_sample((n_rows, n_cols)).astype(dtype) +def test_distance(n_rows, n_cols, metric, order, dtype): + input1 = np.random.random_sample((n_rows, n_cols)) + input1 = np.asarray(input1, order=order).astype(dtype) # RussellRao expects boolean arrays if metric == "russellrao": @@ -70,8 +73,8 @@ def test_distance(n_rows, n_cols, metric, dtype): expected[expected <= 1e-5] = 0.0 - input1_device = TestDeviceBuffer(input1) - output_device = TestDeviceBuffer(output) + input1_device = TestDeviceBuffer(input1, order) + output_device = TestDeviceBuffer(output, order) pairwise_distance(input1_device, input1_device, output_device, metric) actual = output_device.copy_to_host()