Skip to content

Commit 8ee22d9

Browse files
maxwbuckleyclaude
andcommitted
Fix uninitialized class/struct members in public headers
Initialize POD members with sensible defaults to prevent undefined behavior when users create instances without explicitly setting all fields: - cluster/agglomerative.hpp: min_samples = 5 - distance/distance.hpp: KernelParams defaults (LINEAR, degree=3, gamma=1.0, coef0=0.0) - distance/grammian.hpp: cublas_handle = nullptr, fix empty constructor syntax - neighbors/ball_cover.hpp: index_trained = false - neighbors/common.hpp: make base_filter destructor virtual, num_ranks_ = 0 - neighbors/hnsw.hpp: ef = 200 - neighbors/vamana.hpp: pq_codebook_size = 0, pq_dim = 0 - preprocessing/spectral_embedding.hpp: n_components=2, n_neighbors=15, etc. Also fixes base_filter to have a virtual destructor for safe polymorphic deletion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c6b52fa commit 8ee22d9

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

cpp/include/cuvs/cluster/agglomerative.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct distance_params {
140140
/** Specialized parameters to build the Mutual Reachability graph */
141141
struct mutual_reachability_params {
142142
/** this neighborhood will be selected for core distances. */
143-
int min_samples;
143+
int min_samples = 5;
144144

145145
/** weight applied when internal distance is chosen for mutual reachability (value of 1.0 disables
146146
* the weighting) */

cpp/include/cuvs/distance/distance.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ enum KernelType { LINEAR, POLYNOMIAL, RBF, TANH };
5858
*/
5959
struct KernelParams {
6060
// Kernel function parameters
61-
KernelType kernel; //!< Type of the kernel function
62-
int degree; //!< Degree of polynomial kernel (ignored by others)
63-
double gamma; //!< multiplier in the
64-
double coef0; //!< additive constant in poly and tanh kernels
61+
KernelType kernel = KernelType::LINEAR; //!< Type of the kernel function
62+
int degree = 3; //!< Degree of polynomial kernel (ignored by others)
63+
double gamma = 1.0; //!< multiplier in the
64+
double coef0 = 0.0; //!< additive constant in poly and tanh kernels
6565
};
6666
} // end namespace kernels
6767

cpp/include/cuvs/distance/grammian.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ using csr_input_matrix_view_t = raft::device_csr_matrix_view<const math_t, int,
4747
template <typename math_t>
4848
class GramMatrixBase {
4949
protected:
50-
cublasHandle_t cublas_handle;
50+
cublasHandle_t cublas_handle = nullptr;
5151
bool legacy_interface;
5252

5353
public:
54-
GramMatrixBase() : legacy_interface(false) {};
54+
GramMatrixBase() : legacy_interface(false) {}
5555
[[deprecated]] GramMatrixBase(cublasHandle_t cublas_handle)
56-
: cublas_handle(cublas_handle), legacy_interface(true) {};
56+
: cublas_handle(cublas_handle), legacy_interface(true) {}
5757

58-
virtual ~GramMatrixBase() {};
58+
virtual ~GramMatrixBase() = default;
5959

6060
/** Convenience function to evaluate the Gram matrix for two vector sets.
6161
* Vector sets are provided in Matrix format
@@ -331,10 +331,10 @@ class PolynomialKernel : public GramMatrixBase<math_t> {
331331
* @param offset
332332
*/
333333
PolynomialKernel(exp_t exponent, math_t gain, math_t offset)
334-
: GramMatrixBase<math_t>(), exponent(exponent), gain(gain), offset(offset) {};
334+
: GramMatrixBase<math_t>(), exponent(exponent), gain(gain), offset(offset) {}
335335

336336
[[deprecated]] PolynomialKernel(exp_t exponent, math_t gain, math_t offset, cublasHandle_t handle)
337-
: GramMatrixBase<math_t>(handle), exponent(exponent), gain(gain), offset(offset) {};
337+
: GramMatrixBase<math_t>(handle), exponent(exponent), gain(gain), offset(offset) {}
338338

339339
/** Evaluate kernel matrix using polynomial kernel.
340340
*
@@ -447,7 +447,7 @@ class TanhKernel : public GramMatrixBase<math_t> {
447447
TanhKernel(math_t gain, math_t offset) : GramMatrixBase<math_t>(), gain(gain), offset(offset) {}
448448

449449
[[deprecated]] TanhKernel(math_t gain, math_t offset, cublasHandle_t handle)
450-
: GramMatrixBase<math_t>(handle), gain(gain), offset(offset) {};
450+
: GramMatrixBase<math_t>(handle), gain(gain), offset(offset) {}
451451

452452
/** Evaluate kernel matrix using tanh kernel.
453453
*
@@ -562,10 +562,10 @@ class RBFKernel : public GramMatrixBase<math_t> {
562562
* @tparam math_t floating point type
563563
* @param gain
564564
*/
565-
RBFKernel(math_t gain) : GramMatrixBase<math_t>(), gain(gain) {};
565+
RBFKernel(math_t gain) : GramMatrixBase<math_t>(), gain(gain) {}
566566

567567
[[deprecated]] RBFKernel(math_t gain, cublasHandle_t handle)
568-
: GramMatrixBase<math_t>(handle), gain(gain) {};
568+
: GramMatrixBase<math_t>(handle), gain(gain) {}
569569

570570
void matrixRowNormL2(raft::resources const& handle,
571571
dense_input_matrix_view_t<math_t> matrix,

cpp/include/cuvs/neighbors/ball_cover.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct index : cuvs::neighbors::index {
146146
raft::device_matrix<float, int64_t, raft::row_major> X_reordered;
147147

148148
protected:
149-
bool index_trained;
149+
bool index_trained = false;
150150
};
151151

152152
/** @} */

cpp/include/cuvs/neighbors/common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ namespace filtering {
485485
enum class FilterType { None, Bitmap, Bitset };
486486

487487
struct base_filter {
488-
~base_filter() = default;
488+
virtual ~base_filter() = default;
489489
virtual FilterType get_filter_type() const = 0;
490490
};
491491

@@ -891,7 +891,7 @@ struct mg_index {
891891
auto operator=(mg_index&&) -> mg_index& = default;
892892

893893
distribution_mode mode_;
894-
int num_ranks_;
894+
int num_ranks_ = 0;
895895
std::vector<iface<AnnIndexType, T, IdxT>> ann_interfaces_;
896896

897897
// for load balancing mechanism

cpp/include/cuvs/neighbors/hnsw.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void extend(raft::resources const& res,
471471
*/
472472

473473
struct search_params : cuvs::neighbors::search_params {
474-
int ef; // size of the candidate list
474+
int ef = 200; // size of the candidate list
475475
int num_threads = 0; // number of host threads to use for concurrent searches. Value of 0
476476
// automatically maximizes parallelism
477477
};

cpp/include/cuvs/neighbors/vamana.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace cuvs::neighbors::vamana {
4444
*/
4545
template <typename T = float>
4646
struct codebook_params {
47-
int pq_codebook_size;
48-
int pq_dim;
47+
int pq_codebook_size = 0;
48+
int pq_dim = 0;
4949
std::vector<T> pq_encoding_table;
5050
std::vector<T> rotation_matrix;
5151
};

cpp/include/cuvs/preprocessing/spectral_embedding.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace cuvs::preprocessing::spectral_embedding {
3333
*/
3434
struct params {
3535
/** @brief The number of components to reduce the data to. */
36-
int n_components;
36+
int n_components = 2;
3737

3838
/** @brief The number of neighbors to use for the nearest neighbors graph. */
39-
int n_neighbors;
39+
int n_neighbors = 15;
4040

4141
/**
4242
* @brief Whether to normalize the Laplacian matrix.
@@ -45,7 +45,7 @@ struct params {
4545
* If false, uses the unnormalized graph Laplacian (L = D - W).
4646
* Normalized Laplacian often leads to better results for clustering tasks.
4747
*/
48-
bool norm_laplacian;
48+
bool norm_laplacian = true;
4949

5050
/**
5151
* @brief Whether to drop the first eigenvector.
@@ -54,7 +54,7 @@ struct params {
5454
* uninformative. Setting this to true drops it from the embedding.
5555
* This is typically set to true when norm_laplacian is true.
5656
*/
57-
bool drop_first;
57+
bool drop_first = true;
5858

5959
/**
6060
* @brief Random seed for reproducibility.

0 commit comments

Comments
 (0)