From d8811614d3800a635f14e50e14204699a2ef9a30 Mon Sep 17 00:00:00 2001 From: Ben Frederickson Date: Wed, 9 Nov 2022 16:18:20 -0800 Subject: [PATCH 1/2] Add `except +` to cython extern cdef declarations RAFT is using exceptions for error's, but these weren't always being declared to cython in the `cdef extern` blocks. This means that if the function were to throw an exception, the python program would core dump on an uncaught c++ exception - instead of translating the exception into a python exception. --- python/pylibraft/pylibraft/cluster/kmeans.pyx | 4 ++-- python/pylibraft/pylibraft/distance/fused_l2_nn.pyx | 4 ++-- python/pylibraft/pylibraft/distance/pairwise_distance.pyx | 4 ++-- .../pylibraft/pylibraft/random/rmat_rectangular_generator.pyx | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/pylibraft/pylibraft/cluster/kmeans.pyx b/python/pylibraft/pylibraft/cluster/kmeans.pyx index fa106fd796..940d118c3b 100644 --- a/python/pylibraft/pylibraft/cluster/kmeans.pyx +++ b/python/pylibraft/pylibraft/cluster/kmeans.pyx @@ -52,7 +52,7 @@ cdef extern from "raft_distance/kmeans.hpp" \ const double *centroids, const int* labels, double *new_centroids, - double *weight_per_cluster) + double *weight_per_cluster) except + cdef void update_centroids( const handle_t& handle, @@ -64,7 +64,7 @@ cdef extern from "raft_distance/kmeans.hpp" \ const float *centroids, const int* labels, float *new_centroids, - float *weight_per_cluster) + float *weight_per_cluster) except + @auto_sync_handle diff --git a/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx b/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx index 5b11f6b2af..75b9670005 100644 --- a/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx +++ b/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx @@ -47,7 +47,7 @@ cdef extern from "raft_distance/fused_l2_min_arg.hpp" \ int m, int n, int k, - bool sqrt) + bool sqrt) except + void fused_l2_nn_min_arg( const handle_t &handle, @@ -57,7 +57,7 @@ cdef extern from "raft_distance/fused_l2_min_arg.hpp" \ int m, int n, int k, - bool sqrt) + bool sqrt) except + @auto_sync_handle diff --git a/python/pylibraft/pylibraft/distance/pairwise_distance.pyx b/python/pylibraft/pylibraft/distance/pairwise_distance.pyx index 40f2fa668c..b6b73a86a1 100644 --- a/python/pylibraft/pylibraft/distance/pairwise_distance.pyx +++ b/python/pylibraft/pylibraft/distance/pairwise_distance.pyx @@ -49,7 +49,7 @@ cdef extern from "raft_distance/pairwise_distance.hpp" \ int k, DistanceType metric, bool isRowMajor, - float metric_arg) + float metric_arg) except + cdef void pairwise_distance(const handle_t &handle, double *x, @@ -60,7 +60,7 @@ cdef extern from "raft_distance/pairwise_distance.hpp" \ int k, DistanceType metric, bool isRowMajor, - float metric_arg) + float metric_arg) except + DISTANCE_TYPES = { "l2": DistanceType.L2SqrtUnexpanded, diff --git a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx index 0aa90b6bc4..285cb16ca1 100644 --- a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx +++ b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx @@ -41,7 +41,7 @@ cdef extern from "raft_distance/random/rmat_rectangular_generator.hpp" \ int r_scale, int c_scale, int n_edges, - RngState& r) + RngState& r) except + cdef void rmat_rectangular_gen(const handle_t &handle, int64_t* out, @@ -51,7 +51,7 @@ cdef extern from "raft_distance/random/rmat_rectangular_generator.hpp" \ int64_t r_scale, int64_t c_scale, int64_t n_edges, - RngState& r) + RngState& r) except + cdef void rmat_rectangular_gen(const handle_t &handle, int* out, From 8c4e32b4a69c2f8d63b1b70d310eb5a378f5773c Mon Sep 17 00:00:00 2001 From: Ben Frederickson Date: Wed, 9 Nov 2022 16:26:23 -0800 Subject: [PATCH 2/2] add two more --- .../pylibraft/pylibraft/random/rmat_rectangular_generator.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx index 285cb16ca1..56359ff8a3 100644 --- a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx +++ b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx @@ -61,7 +61,7 @@ cdef extern from "raft_distance/random/rmat_rectangular_generator.hpp" \ int r_scale, int c_scale, int n_edges, - RngState& r) + RngState& r) except + cdef void rmat_rectangular_gen(const handle_t &handle, int64_t* out, @@ -71,7 +71,7 @@ cdef extern from "raft_distance/random/rmat_rectangular_generator.hpp" \ int64_t r_scale, int64_t c_scale, int64_t n_edges, - RngState& r) + RngState& r) except + @auto_sync_handle