Skip to content
44 changes: 28 additions & 16 deletions cpp/include/cuml/decomposition/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@

#pragma once

#include <raft/linalg/pca_types.hpp>

#include <cstdint>

namespace ML {

/**
* @param COV_EIG_DQ: covariance of input will be used along with eigen decomposition using divide
* and conquer method for symmetric matrices
* @param COV_EIG_JACOBI: covariance of input will be used along with eigen decomposition using
* jacobi method for symmetric matrices
*/
enum class solver : int {
COV_EIG_DQ,
COV_EIG_JACOBI,
};
using solver = raft::linalg::solver;
using mg_solver = raft::linalg::solver;
Comment thread
jcrist marked this conversation as resolved.

class params {
public:
Expand Down Expand Up @@ -53,10 +47,8 @@ class paramsTSVDTemplate : public paramsSolver {
* root of n_samples and then divided by the singular values to ensure uncorrelated outputs with
* unit component-wise variances.
* @param algorithm: the solver to be used in PCA.
* @param tol: Tolerance for singular values computed by svd_solver == ‘arpack’ or svd_solver ==
* ‘COV_EIG_JACOBI’
* @param n_iterations: Number of iterations for the power method computed by jacobi method
* (svd_solver == 'COV_EIG_JACOBI').
* @param tol: Tolerance for singular values computed by the Jacobi solver
* @param n_iterations: Number of iterations for the power method computed by the Jacobi solver
* @param verbose: 0: no error message printing, 1: print error messages
*/

Expand All @@ -70,9 +62,29 @@ class paramsPCATemplate : public paramsTSVDTemplate<enum_solver> {
typedef paramsTSVDTemplate<> paramsTSVD;
typedef paramsPCATemplate<> paramsPCA;

enum class mg_solver { COV_EIG_DQ, COV_EIG_JACOBI };

typedef paramsPCATemplate<mg_solver> paramsPCAMG;
typedef paramsTSVDTemplate<mg_solver> paramsTSVDMG;

template <typename enum_solver>
inline raft::linalg::paramsTSVD to_raft_params(const paramsTSVDTemplate<enum_solver>& ml_prms)
{
raft::linalg::paramsTSVD prms;
prms.tol = ml_prms.tol;
prms.n_iterations = ml_prms.n_iterations;
prms.algorithm = ml_prms.algorithm;
return prms;
}

template <typename enum_solver>
inline raft::linalg::paramsPCA to_raft_params(const paramsPCATemplate<enum_solver>& ml_prms)
{
raft::linalg::paramsPCA prms;
prms.tol = ml_prms.tol;
prms.n_iterations = ml_prms.n_iterations;
prms.algorithm = ml_prms.algorithm;
prms.copy = ml_prms.copy;
prms.whiten = ml_prms.whiten;
return prms;
}

}; // end namespace ML
18 changes: 9 additions & 9 deletions cpp/include/cuml/decomposition/pca.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -13,7 +13,7 @@ class handle_t;

namespace ML {

void pcaFit(raft::handle_t& handle,
void pcaFit(const raft::handle_t& handle,
float* input,
float* components,
float* explained_var,
Expand All @@ -23,7 +23,7 @@ void pcaFit(raft::handle_t& handle,
float* noise_vars,
const paramsPCA& prms,
bool flip_signs_based_on_U);
void pcaFit(raft::handle_t& handle,
void pcaFit(const raft::handle_t& handle,
double* input,
double* components,
double* explained_var,
Expand All @@ -33,7 +33,7 @@ void pcaFit(raft::handle_t& handle,
double* noise_vars,
const paramsPCA& prms,
bool flip_signs_based_on_U);
void pcaFitTransform(raft::handle_t& handle,
void pcaFitTransform(const raft::handle_t& handle,
float* input,
float* trans_input,
float* components,
Expand All @@ -44,7 +44,7 @@ void pcaFitTransform(raft::handle_t& handle,
float* noise_vars,
const paramsPCA& prms,
bool flip_signs_based_on_U);
void pcaFitTransform(raft::handle_t& handle,
void pcaFitTransform(const raft::handle_t& handle,
double* input,
double* trans_input,
double* components,
Expand All @@ -55,28 +55,28 @@ void pcaFitTransform(raft::handle_t& handle,
double* noise_vars,
const paramsPCA& prms,
bool flip_signs_based_on_U);
void pcaInverseTransform(raft::handle_t& handle,
void pcaInverseTransform(const raft::handle_t& handle,
float* trans_input,
float* components,
float* singular_vals,
float* mu,
float* input,
const paramsPCA& prms);
void pcaInverseTransform(raft::handle_t& handle,
void pcaInverseTransform(const raft::handle_t& handle,
double* trans_input,
double* components,
double* singular_vals,
double* mu,
double* input,
const paramsPCA& prms);
void pcaTransform(raft::handle_t& handle,
void pcaTransform(const raft::handle_t& handle,
float* input,
float* components,
float* trans_input,
float* singular_vals,
float* mu,
const paramsPCA& prms);
void pcaTransform(raft::handle_t& handle,
void pcaTransform(const raft::handle_t& handle,
double* input,
double* components,
double* trans_input,
Expand Down
18 changes: 9 additions & 9 deletions cpp/include/cuml/decomposition/tsvd.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -13,39 +13,39 @@ class handle_t;

namespace ML {

void tsvdFit(raft::handle_t& handle,
void tsvdFit(const raft::handle_t& handle,
float* input,
float* components,
float* singular_vals,
const paramsTSVD& prms,
bool flip_signs_based_on_U);
void tsvdFit(raft::handle_t& handle,
void tsvdFit(const raft::handle_t& handle,
double* input,
double* components,
double* singular_vals,
const paramsTSVD& prms,
bool flip_signs_based_on_U);
void tsvdInverseTransform(raft::handle_t& handle,
void tsvdInverseTransform(const raft::handle_t& handle,
float* trans_input,
float* components,
float* input,
const paramsTSVD& prms);
void tsvdInverseTransform(raft::handle_t& handle,
void tsvdInverseTransform(const raft::handle_t& handle,
double* trans_input,
double* components,
double* input,
const paramsTSVD& prms);
void tsvdTransform(raft::handle_t& handle,
void tsvdTransform(const raft::handle_t& handle,
float* input,
float* components,
float* trans_input,
const paramsTSVD& prms);
void tsvdTransform(raft::handle_t& handle,
void tsvdTransform(const raft::handle_t& handle,
double* input,
double* components,
double* trans_input,
const paramsTSVD& prms);
void tsvdFitTransform(raft::handle_t& handle,
void tsvdFitTransform(const raft::handle_t& handle,
float* input,
float* trans_input,
float* components,
Expand All @@ -54,7 +54,7 @@ void tsvdFitTransform(raft::handle_t& handle,
float* singular_vals,
const paramsTSVD& prms,
bool flip_signs_based_on_U);
void tsvdFitTransform(raft::handle_t& handle,
void tsvdFitTransform(const raft::handle_t& handle,
double* input,
double* trans_input,
double* components,
Expand Down
Loading
Loading