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

Changing Overloads for GCC 11/12 bug #995

Merged
merged 6 commits into from
Nov 14, 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
88 changes: 68 additions & 20 deletions cpp/include/raft/linalg/rsvd.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ void rsvdPerc(const raft::handle_t& handle,
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using QR decomposition, by specifying no. of PCs and
* upsamples directly
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] p no. of upsamples
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -216,13 +222,19 @@ void rsvd_fixed_rank(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using symmetric Eigen decomposition, by specifying no. of PCs and
* upsamples directly. The rectangular input matrix is made square and symmetric using B @ B^T
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] p no. of upsamples
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -285,15 +297,21 @@ void rsvd_fixed_rank_symmetric(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using Jacobi method, by specifying no. of PCs and
* upsamples directly
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] p no. of upsamples
* @param[in] tol tolerance for Jacobi-based solvers
* @param[in] max_sweeps maximum number of sweeps for Jacobi-based solvers
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -357,15 +375,21 @@ void rsvd_fixed_rank_jacobi(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using Jacobi method, by specifying no. of PCs and
* upsamples directly. The rectangular input matrix is made square and symmetric using B @ B^T
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] p no. of upsamples
* @param[in] tol tolerance for Jacobi-based solvers
* @param[in] max_sweeps maximum number of sweeps for Jacobi-based solvers
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -430,14 +454,20 @@ void rsvd_fixed_rank_symmetric_jacobi(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using QR decomposition, by specifying the PC and upsampling
* ratio
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] PC_perc percentage of singular values to be computed
* @param[in] UpS_perc upsampling percentage
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -490,7 +520,7 @@ void rsvd_perc(const raft::handle_t& handle,
*
* Please see above for documentation of `rsvd_perc`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 4>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 5>>
void rsvd_perc(Args... args)
{
rsvd_perc(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand All @@ -500,14 +530,20 @@ void rsvd_perc(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using symmetric Eigen decomposition, by specifying the PC and upsampling
* ratio. The rectangular input matrix is made square and symmetric using B @ B^T
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] PC_perc percentage of singular values to be computed
* @param[in] UpS_perc upsampling percentage
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -560,7 +596,7 @@ void rsvd_perc_symmetric(const raft::handle_t& handle,
*
* Please see above for documentation of `rsvd_perc_symmetric`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 4>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 5>>
void rsvd_perc_symmetric(Args... args)
{
rsvd_perc_symmetric(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand All @@ -570,16 +606,22 @@ void rsvd_perc_symmetric(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using Jacobi method, by specifying the PC and upsampling
* ratio
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] PC_perc percentage of singular values to be computed
* @param[in] UpS_perc upsampling percentage
* @param[in] tol tolerance for Jacobi-based solvers
* @param[in] max_sweeps maximum number of sweeps for Jacobi-based solvers
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -634,7 +676,7 @@ void rsvd_perc_jacobi(const raft::handle_t& handle,
*
* Please see above for documentation of `rsvd_perc_jacobi`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 6>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 7>>
void rsvd_perc_jacobi(Args... args)
{
rsvd_perc_jacobi(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand All @@ -644,16 +686,22 @@ void rsvd_perc_jacobi(Args... args)
* @brief randomized singular value decomposition (RSVD) on a column major
* rectangular matrix using Jacobi method, by specifying the PC and upsampling
* ratio. The rectangular input matrix is made square and symmetric using B @ B^T
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] M input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] S_vec singular values raft::device_vector_view of shape (K)
* @param[in] PC_perc percentage of singular values to be computed
* @param[in] UpS_perc upsampling percentage
* @param[in] tol tolerance for Jacobi-based solvers
* @param[in] max_sweeps maximum number of sweeps for Jacobi-based solvers
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major
* @param[out] V_in optional right singular values of raft::device_matrix_view with layout
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with layout
* raft::col_major
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -709,7 +757,7 @@ void rsvd_perc_symmetric_jacobi(
*
* Please see above for documentation of `rsvd_perc_symmetric_jacobi`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 6>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 7>>
void rsvd_perc_symmetric_jacobi(Args... args)
{
rsvd_perc_symmetric_jacobi(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand Down
24 changes: 18 additions & 6 deletions cpp/include/raft/linalg/svd.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,18 @@ bool evaluateSVDByL2Norm(const raft::handle_t& handle,
/**
* @brief singular value decomposition (SVD) on a column major
* matrix using QR decomposition
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] in input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] sing_vals singular values raft::device_vector_view of shape (K)
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major and dimensions (m, n)
* @param[out] V_in optional right singular values of raft::device_matrix_view with
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with
* layout raft::col_major and dimensions (n, n)
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -237,7 +243,7 @@ void svd_qr(const raft::handle_t& handle,
*
* Please see above for documentation of `svd_qr`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 2>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 3>>
void svd_qr(Args... args)
{
svd_qr(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand All @@ -246,12 +252,18 @@ void svd_qr(Args... args)
/**
* @brief singular value decomposition (SVD) on a column major
* matrix using QR decomposition. Right singular vector matrix is transposed before returning
* @tparam ValueType value type of parameters
* @tparam IndexType index type of parameters
* @tparam UType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* U_in
* @tparam VType std::optional<raft::device_matrix_view<ValueType, IndexType, raft::col_major>> @c
* V_in
* @param[in] handle raft::handle_t
* @param[in] in input raft::device_matrix_view with layout raft::col_major of shape (M, N)
* @param[out] sing_vals singular values raft::device_vector_view of shape (K)
* @param[out] U_in optional left singular values of raft::device_matrix_view with layout
* @param[out] U_in std::optional left singular values of raft::device_matrix_view with layout
* raft::col_major and dimensions (m, n)
* @param[out] V_in optional right singular values of raft::device_matrix_view with
* @param[out] V_in std::optional right singular values of raft::device_matrix_view with
* layout raft::col_major and dimensions (n, n)
*/
template <typename ValueType, typename IndexType, typename UType, typename VType>
Expand Down Expand Up @@ -295,7 +307,7 @@ void svd_qr_transpose_right_vec(
*
* Please see above for documentation of `svd_qr_transpose_right_vec`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 2>>
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 3>>
void svd_qr_transpose_right_vec(Args... args)
{
svd_qr_transpose_right_vec(std::forward<Args>(args)..., std::nullopt, std::nullopt);
Expand Down
46 changes: 11 additions & 35 deletions cpp/include/raft/matrix/col_wise_sort.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ void sort_cols_per_row(const InType* in,
* @tparam in_t: element type of input matrix
* @tparam out_t: element type of output matrix
* @tparam matrix_idx_t: integer type for matrix indexing
* @tparam sorted_keys_t: std::optional<raft::device_matrix_view<in_t, matrix_idx_t,
* raft::row_major>> @c sorted_keys_opt
* @param[in] handle: raft handle
* @param[in] in: input matrix
* @param[out] out: output value(index) matrix
* @param[out] sorted_keys: Optional, output matrix for sorted keys (input)
* @param[out] sorted_keys_opt: std::optional, output matrix for sorted keys (input)
*/
template <typename in_t, typename out_t, typename matrix_idx_t>
template <typename in_t, typename out_t, typename matrix_idx_t, typename sorted_keys_t>
void sort_cols_per_row(const raft::handle_t& handle,
raft::device_matrix_view<const in_t, matrix_idx_t, raft::row_major> in,
raft::device_matrix_view<out_t, matrix_idx_t, raft::row_major> out,
std::optional<raft::device_matrix_view<in_t, matrix_idx_t, raft::row_major>>
sorted_keys = std::nullopt)
sorted_keys_t&& sorted_keys_opt)
{
std::optional<raft::device_matrix_view<in_t, matrix_idx_t, raft::row_major>> sorted_keys =
std::forward<sorted_keys_t>(sorted_keys_opt);

RAFT_EXPECTS(in.extent(1) == out.extent(1) && in.extent(0) == out.extent(0),
"Input and output matrices must have the same shape.");

Expand Down Expand Up @@ -109,45 +113,17 @@ void sort_cols_per_row(const raft::handle_t& handle,
}
}

namespace sort_cols_per_row_impl {
template <typename T>
struct sorted_keys_alias {
};

template <>
struct sorted_keys_alias<std::nullopt_t> {
using type = double;
};

template <typename in_t, typename matrix_idx_t>
struct sorted_keys_alias<
std::optional<raft::device_matrix_view<in_t, matrix_idx_t, raft::row_major>>> {
using type = typename raft::device_matrix_view<in_t, matrix_idx_t, raft::row_major>::value_type;
};

template <typename T>
using sorted_keys_t = typename sorted_keys_alias<T>::type;
} // namespace sort_cols_per_row_impl

/**
* @brief Overload of `sort_keys_per_row` to help the
* compiler find the above overload, in case users pass in
* `std::nullopt` for one or both of the optional arguments.
*
* Please see above for documentation of `sort_keys_per_row`.
*/
template <typename in_t, typename out_t, typename matrix_idx_t, typename sorted_keys_vector_type>
void sort_cols_per_row(const raft::handle_t& handle,
raft::device_matrix_view<const in_t, matrix_idx_t, raft::row_major> in,
raft::device_matrix_view<out_t, matrix_idx_t, raft::row_major> out,
sorted_keys_vector_type sorted_keys)
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 3>>
void sort_cols_per_row(Args... args)
{
using sorted_keys_type = sort_cols_per_row_impl::sorted_keys_t<
std::remove_const_t<std::remove_reference_t<sorted_keys_vector_type>>>;
std::optional<raft::device_matrix_view<in_t, matrix_idx_t, raft::row_major>> sorted_keys_opt =
std::forward<sorted_keys_vector_type>(sorted_keys);

sort_cols_per_row(handle, in, out, sorted_keys_opt);
sort_cols_per_row(std::forward<Args>(args)..., std::nullopt);
}

}; // end namespace raft::matrix
Expand Down
Loading