Skip to content

Commit 1554e22

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 dd2e749 commit 1554e22

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
@@ -129,7 +129,7 @@ struct distance_params {
129129
/** Specialized parameters to build the Mutual Reachability graph */
130130
struct mutual_reachability_params {
131131
/** this neighborhood will be selected for core distances. */
132-
int min_samples;
132+
int min_samples = 5;
133133

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

cpp/include/cuvs/distance/distance.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ enum KernelType { LINEAR, POLYNOMIAL, RBF, TANH };
9393
*/
9494
struct KernelParams {
9595
// Kernel function parameters
96-
KernelType kernel; //!< Type of the kernel function
97-
int degree; //!< Degree of polynomial kernel (ignored by others)
98-
double gamma; //!< multiplier in the
99-
double coef0; //!< additive constant in poly and tanh kernels
96+
KernelType kernel = KernelType::LINEAR; //!< Type of the kernel function
97+
int degree = 3; //!< Degree of polynomial kernel (ignored by others)
98+
double gamma = 1.0; //!< multiplier in the
99+
double coef0 = 0.0; //!< additive constant in poly and tanh kernels
100100
};
101101
} // end namespace kernels
102102

cpp/include/cuvs/distance/grammian.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ using csr_input_matrix_view_t = raft::device_csr_matrix_view<const math_t, int,
3636
template <typename math_t>
3737
class GramMatrixBase {
3838
protected:
39-
cublasHandle_t cublas_handle;
39+
cublasHandle_t cublas_handle = nullptr;
4040
bool legacy_interface;
4141

4242
public:
43-
GramMatrixBase() : legacy_interface(false) {};
43+
GramMatrixBase() : legacy_interface(false) {}
4444
[[deprecated]] GramMatrixBase(cublasHandle_t cublas_handle)
45-
: cublas_handle(cublas_handle), legacy_interface(true) {};
45+
: cublas_handle(cublas_handle), legacy_interface(true) {}
4646

47-
virtual ~GramMatrixBase() {};
47+
virtual ~GramMatrixBase() = default;
4848

4949
/** Convenience function to evaluate the Gram matrix for two vector sets.
5050
* Vector sets are provided in Matrix format
@@ -320,10 +320,10 @@ class PolynomialKernel : public GramMatrixBase<math_t> {
320320
* @param offset
321321
*/
322322
PolynomialKernel(exp_t exponent, math_t gain, math_t offset)
323-
: GramMatrixBase<math_t>(), exponent(exponent), gain(gain), offset(offset) {};
323+
: GramMatrixBase<math_t>(), exponent(exponent), gain(gain), offset(offset) {}
324324

325325
[[deprecated]] PolynomialKernel(exp_t exponent, math_t gain, math_t offset, cublasHandle_t handle)
326-
: GramMatrixBase<math_t>(handle), exponent(exponent), gain(gain), offset(offset) {};
326+
: GramMatrixBase<math_t>(handle), exponent(exponent), gain(gain), offset(offset) {}
327327

328328
/** Evaluate kernel matrix using polynomial kernel.
329329
*
@@ -436,7 +436,7 @@ class TanhKernel : public GramMatrixBase<math_t> {
436436
TanhKernel(math_t gain, math_t offset) : GramMatrixBase<math_t>(), gain(gain), offset(offset) {}
437437

438438
[[deprecated]] TanhKernel(math_t gain, math_t offset, cublasHandle_t handle)
439-
: GramMatrixBase<math_t>(handle), gain(gain), offset(offset) {};
439+
: GramMatrixBase<math_t>(handle), gain(gain), offset(offset) {}
440440

441441
/** Evaluate kernel matrix using tanh kernel.
442442
*
@@ -551,10 +551,10 @@ class RBFKernel : public GramMatrixBase<math_t> {
551551
* @tparam math_t floating point type
552552
* @param gain
553553
*/
554-
RBFKernel(math_t gain) : GramMatrixBase<math_t>(), gain(gain) {};
554+
RBFKernel(math_t gain) : GramMatrixBase<math_t>(), gain(gain) {}
555555

556556
[[deprecated]] RBFKernel(math_t gain, cublasHandle_t handle)
557-
: GramMatrixBase<math_t>(handle), gain(gain) {};
557+
: GramMatrixBase<math_t>(handle), gain(gain) {}
558558

559559
void matrixRowNormL2(raft::resources const& handle,
560560
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
@@ -135,7 +135,7 @@ struct index : cuvs::neighbors::index {
135135
raft::device_matrix<float, int64_t, raft::row_major> X_reordered;
136136

137137
protected:
138-
bool index_trained;
138+
bool index_trained = false;
139139
};
140140

141141
/** @} */

cpp/include/cuvs/neighbors/common.hpp

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

504504
struct base_filter {
505-
~base_filter() = default;
505+
virtual ~base_filter() = default;
506506
virtual FilterType get_filter_type() const = 0;
507507
};
508508

@@ -975,7 +975,7 @@ struct mg_index {
975975
auto operator=(mg_index&&) -> mg_index& = default;
976976

977977
distribution_mode mode_;
978-
int num_ranks_;
978+
int num_ranks_ = 0;
979979
std::vector<iface<AnnIndexType, T, IdxT>> ann_interfaces_;
980980

981981
// for load balancing mechanism

cpp/include/cuvs/neighbors/hnsw.hpp

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

740740
struct search_params : cuvs::neighbors::search_params {
741-
int ef; // size of the candidate list
741+
int ef = 200; // size of the candidate list
742742
int num_threads = 0; // number of host threads to use for concurrent searches. Value of 0
743743
// automatically maximizes parallelism
744744
};

cpp/include/cuvs/neighbors/vamana.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace cuvs::neighbors::vamana {
3333
*/
3434
template <typename T = float>
3535
struct codebook_params {
36-
int pq_codebook_size;
37-
int pq_dim;
36+
int pq_codebook_size = 0;
37+
int pq_dim = 0;
3838
std::vector<T> pq_encoding_table;
3939
std::vector<T> rotation_matrix;
4040
};

cpp/include/cuvs/preprocessing/spectral_embedding.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace cuvs::preprocessing::spectral_embedding {
2424
*/
2525
struct params {
2626
/** @brief The number of components to reduce the data to. */
27-
int n_components;
27+
int n_components = 2;
2828

2929
/** @brief The number of neighbors to use for the nearest neighbors graph. */
30-
int n_neighbors;
30+
int n_neighbors = 15;
3131

3232
/**
3333
* @brief Whether to normalize the Laplacian matrix.
@@ -36,7 +36,7 @@ struct params {
3636
* If false, uses the unnormalized graph Laplacian (L = D - W).
3737
* Normalized Laplacian often leads to better results for clustering tasks.
3838
*/
39-
bool norm_laplacian;
39+
bool norm_laplacian = true;
4040

4141
/**
4242
* @brief Whether to drop the first eigenvector.
@@ -45,7 +45,7 @@ struct params {
4545
* uninformative. Setting this to true drops it from the embedding.
4646
* This is typically set to true when norm_laplacian is true.
4747
*/
48-
bool drop_first;
48+
bool drop_first = true;
4949

5050
/**
5151
* @brief Tolerance for the eigenvalue solver.

0 commit comments

Comments
 (0)