Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cython fixes / cleanup #1072

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pylibraft/pylibraft/cluster/cpp/kmeans.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from pylibraft.common.handle cimport handle_t


cdef extern from "raft_runtime/cluster/kmeans.hpp" \
namespace "raft::runtime::cluster::kmeans":
namespace "raft::runtime::cluster::kmeans" nogil:

cdef void update_centroids(
const handle_t& handle,
Expand Down
19 changes: 5 additions & 14 deletions python/pylibraft/pylibraft/cluster/kmeans.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ from pylibraft.common.cpp.optional cimport optional
from pylibraft.common.handle cimport handle_t


def is_c_cont(cai, dt):
return "strides" not in cai or \
cai["strides"] is None or \
cai["strides"][1] == dt.itemsize


@auto_sync_handle
def compute_new_centroids(X,
centroids,
Expand All @@ -63,9 +57,6 @@ def compute_new_centroids(X,
"""
Compute new centroids given an input matrix and existing centroids

Valid values for metric:
["euclidean", "sqeuclidean"]

Parameters
----------

Expand Down Expand Up @@ -167,9 +158,9 @@ def compute_new_centroids(X,
handle = handle if handle is not None else Handle()
cdef handle_t *h = <handle_t*><size_t>handle.getHandle()

x_c_contiguous = is_c_cont(x_cai, x_dt)
centroids_c_contiguous = is_c_cont(centroids_cai, centroids_dt)
new_centroids_c_contiguous = is_c_cont(new_centroids_cai, new_centroids_dt)
x_c_contiguous = is_c_contiguous(x_cai)
centroids_c_contiguous = is_c_contiguous(centroids_cai)
new_centroids_c_contiguous = is_c_contiguous(new_centroids_cai)

if not x_c_contiguous or not centroids_c_contiguous \
or not new_centroids_c_contiguous:
Expand Down Expand Up @@ -258,8 +249,8 @@ def cluster_cost(X, centroids, handle=None):
handle = handle if handle is not None else Handle()
cdef handle_t *h = <handle_t*><size_t>handle.getHandle()

x_c_contiguous = is_c_cont(x_cai, x_dt)
centroids_c_contiguous = is_c_cont(centroids_cai, centroids_dt)
x_c_contiguous = is_c_contiguous(x_cai)
centroids_c_contiguous = is_c_contiguous(centroids_cai)

if not x_c_contiguous or not centroids_c_contiguous:
raise ValueError("Inputs must all be c contiguous")
Expand Down
2 changes: 1 addition & 1 deletion python/pylibraft/pylibraft/distance/fused_l2_nn.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from pylibraft.common.handle cimport handle_t


cdef extern from "raft_runtime/distance/fused_l2_nn.hpp" \
namespace "raft::runtime::distance":
namespace "raft::runtime::distance" nogil:

void fused_l2_nn_min_arg(
const handle_t &handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from pylibraft.common import cai_wrapper, device_ndarray


cdef extern from "raft_runtime/distance/pairwise_distance.hpp" \
namespace "raft::runtime::distance":
namespace "raft::runtime::distance" nogil:

cdef void pairwise_distance(const handle_t &handle,
float *x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from pylibraft.random.cpp.rng_state cimport RngState


cdef extern from "raft_runtime/random/rmat_rectangular_generator.hpp" \
namespace "raft::runtime::random":
namespace "raft::runtime::random" nogil:

cdef void rmat_rectangular_gen(const handle_t &handle,
int* out,
Expand Down