Skip to content

Commit

Permalink
Applying clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Feb 1, 2024
1 parent 360d052 commit caac290
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
61 changes: 28 additions & 33 deletions lapack/src/KokkosLapack_svd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ namespace KokkosLapack {
///
/// \param space [in] execution space instance used to specified how to execute
/// the svd kernels.
/// \param jobu [in] flag to control the computation of the left singular vectors
/// when set to: 'A' all vectors are computed, 'S' the first min(m,n) singular
/// vectors are computed, 'O' the first min(m,n) singular vectors are overwritten
/// into A, 'N' no singular vectors are computed.
/// \param jobvt [in] flag to control the computation of the right singular vectors
/// when set to: 'A' all vectors are computed, 'S' the first min(m,n) singular
/// vectors are computed, 'O' the first min(m,n) singular vectors are overwritten
/// into A, 'N' no singular vectors are computed.
/// \param jobvt [in]
/// \param A [in] An m-by-n matrix to be decomposed using its singular values.
/// \param S [out] Vector of the min(m, n) singular values of A.
/// \param U [out] the first min(m, n) columns of U are the left singular
/// vectors of A.
/// \param Vt [out] the first min(m, n) columns of Vt are the
/// right singular vectors of A.
/// \param jobu [in] flag to control the computation of the left singular
/// vectors when set to: 'A' all vectors are computed, 'S' the first min(m,n)
/// singular vectors are computed, 'O' the first min(m,n) singular vectors are
/// overwritten into A, 'N' no singular vectors are computed. \param jobvt [in]
/// flag to control the computation of the right singular vectors when set to:
/// 'A' all vectors are computed, 'S' the first min(m,n) singular vectors are
/// computed, 'O' the first min(m,n) singular vectors are overwritten into A,
/// 'N' no singular vectors are computed. \param jobvt [in] \param A [in] An
/// m-by-n matrix to be decomposed using its singular values. \param S [out]
/// Vector of the min(m, n) singular values of A. \param U [out] the first
/// min(m, n) columns of U are the left singular vectors of A. \param Vt [out]
/// the first min(m, n) columns of Vt are the right singular vectors of A.
///
template <class ExecutionSpace, class AMatrix, class SVector, class UMatrix,
class VMatrix>
Expand Down Expand Up @@ -133,8 +130,8 @@ void svd(const ExecutionSpace& space, const char jobu[], const char jobvt[],
KokkosKernels::Impl::throw_runtime_exception(oss.str());
}

if(((jobu[0] == 'O') || (jobu[0] == 'o')) &&
((jobvt[0] == 'O') || (jobvt[0] == 'o'))) {
if (((jobu[0] == 'O') || (jobu[0] == 'o')) &&
((jobvt[0] == 'O') || (jobvt[0] == 'o'))) {
std::ostringstream oss;
oss << "KokkosLapack::svd: jobu and jobvt cannot be O at the same time!\n";
KokkosKernels::Impl::throw_runtime_exception(oss.str());
Expand All @@ -155,15 +152,15 @@ void svd(const ExecutionSpace& space, const char jobu[], const char jobvt[],
if (U.extent_int(0) != m || U.extent_int(1) != m) {
is_extent_invalid = true;
os << "KokkosLapack::svd: U has extents (" << U.extent(0) << ", "
<< U.extent(1) << ") instead of (" << m << ", " << m << ").\n";
<< U.extent(1) << ") instead of (" << m << ", " << m << ").\n";
}
}
if ((jobvt[0] == 'A') || (jobvt[0] == 'a') || (jobvt[0] == 'S') ||
(jobvt[0] == 's')) {
if (Vt.extent_int(0) != n || Vt.extent_int(1) != n) {
is_extent_invalid = true;
os << "KokkosLapack::svd: V has extents (" << Vt.extent(0) << ", "
<< Vt.extent(1) << ") instead of (" << n << ", " << n << ").\n";
<< Vt.extent(1) << ") instead of (" << n << ", " << n << ").\n";
}
}
if (is_extent_invalid) {
Expand Down Expand Up @@ -216,20 +213,18 @@ void svd(const ExecutionSpace& space, const char jobu[], const char jobvt[],
/// \tparam UMatrix (mxm) matrix as a rank-2 Kokkos::View
/// \tparam VMatrix () matrix as a rank-2 Kokkos::View
///
/// \param jobu [in] flag to control the computation of the left singular vectors
/// when set to: 'A' all vectors are computed, 'S' the first min(m,n) singular
/// vectors are computed, 'O' the first min(m,n) singular vectors are overwritten
/// into A, 'N' no singular vectors are computed.
/// \param jobvt [in] flag to control the computation of the right singular vectors
/// when set to: 'A' all vectors are computed, 'S' the first min(m,n) singular
/// vectors are computed, 'O' the first min(m,n) singular vectors are overwritten
/// into A, 'N' no singular vectors are computed.
/// \param A [in] An m-by-n matrix to be decomposed using its singular values.
/// \param S [out] Vector of the min(m, n) singular values of A.
/// \param U [out] the first min(m, n) columns of U are the left singular
/// vectors of A.
/// \param Vt [out] the first min(m, n) columns of Vt are the
/// right singular vectors of A.
/// \param jobu [in] flag to control the computation of the left singular
/// vectors when set to: 'A' all vectors are computed, 'S' the first min(m,n)
/// singular vectors are computed, 'O' the first min(m,n) singular vectors are
/// overwritten into A, 'N' no singular vectors are computed. \param jobvt [in]
/// flag to control the computation of the right singular vectors when set to:
/// 'A' all vectors are computed, 'S' the first min(m,n) singular vectors are
/// computed, 'O' the first min(m,n) singular vectors are overwritten into A,
/// 'N' no singular vectors are computed. \param A [in] An m-by-n matrix to be
/// decomposed using its singular values. \param S [out] Vector of the min(m, n)
/// singular values of A. \param U [out] the first min(m, n) columns of U are
/// the left singular vectors of A. \param Vt [out] the first min(m, n) columns
/// of Vt are the right singular vectors of A.
///
template <class AMatrix, class SVector, class UMatrix, class VMatrix>
void svd(const char jobu[], const char jobvt[], const AMatrix& A,
Expand Down
4 changes: 2 additions & 2 deletions lapack/tpls/KokkosLapack_svd_tpl_spec_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void lapackSvdWrapper(const ExecutionSpace& /* space */, const char jobu[],
rwork.data(), info);
} else {
HostLapack<Scalar>::gesvd(jobu[0], jobvt[0], m, n, A.data(), lda, S.data(),
U.data(), ldu, Vt.data(), ldvt, work.data(), lwork,
rwork.data(), info);
U.data(), ldu, Vt.data(), ldvt, work.data(),
lwork, rwork.data(), info);

lwork = static_cast<int>(work(0));

Expand Down
40 changes: 22 additions & 18 deletions lapack/unit_test/Test_Lapack_svd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
namespace Test {

template <class AMatrix, class SVector, class UMatrix, class VMatrix>
void check_triple_product(const AMatrix& A, const SVector& S, const UMatrix& U,
const VMatrix& Vt,
typename Kokkos::ArithTraits<typename AMatrix::non_const_value_type>::mag_type tol) {
void check_triple_product(
const AMatrix& A, const SVector& S, const UMatrix& U, const VMatrix& Vt,
typename Kokkos::ArithTraits<
typename AMatrix::non_const_value_type>::mag_type tol) {
// After a successful SVD decomposition we have A=U*S*V
// So using gemm we should be able to compare the above
// triple product to the original matrix A.
Expand Down Expand Up @@ -70,13 +71,15 @@ void check_triple_product(const AMatrix& A, const SVector& S, const UMatrix& U,
}

template <class Matrix>
void check_unitary_orthogonal_matrix(const Matrix& M, typename Kokkos::ArithTraits<typename Matrix::non_const_value_type>::mag_type tol) {
void check_unitary_orthogonal_matrix(
const Matrix& M, typename Kokkos::ArithTraits<
typename Matrix::non_const_value_type>::mag_type tol) {
// After a successful SVD decomposition the matrices
// U and V are unitary matrices. Thus we can check
// the property UUt=UtU=I and VVt=VtV=I using gemm.

using scalar_type = typename Matrix::non_const_value_type;
using mag_type = typename Kokkos::ArithTraits<scalar_type>::mag_type;
using scalar_type = typename Matrix::non_const_value_type;
using mag_type = typename Kokkos::ArithTraits<scalar_type>::mag_type;

Matrix I0("M*Mt", M.extent(0), M.extent(0));
KokkosBlas::gemm("N", "C", 1, M, M, 0, I0);
Expand Down Expand Up @@ -234,9 +237,10 @@ int impl_analytic_2x3_svd() {

// A = [3 2 2]
// [2 3 -2]
// USVt = 1/sqrt(2) [1 1] * [5 0 0] * 1/(3*sqrt(2)) [ 3 3 0]
// [1 -1] [0 3 0] [ 1 -1 4]
// [2*sqrt(2) -2*sqrt(2) -sqrt(2)]
// USVt = 1/sqrt(2) [1 1] * [5 0 0] * 1/(3*sqrt(2)) [ 3 3 0]
// [1 -1] [0 3 0] [ 1 -1 4]
// [2*sqrt(2) -2*sqrt(2)
// -sqrt(2)]
A_h(0, 0) = 3;
A_h(0, 1) = 2;
A_h(0, 2) = 2;
Expand Down Expand Up @@ -369,11 +373,11 @@ int impl_analytic_3x2_svd() {
// USVt = 1/(3*sqrt(2)) [3 1 2*sqrt(2)] * [5 0] * 1/sqrt(2) [1 1]
// [3 -1 -2*sqrt(2)] [0 3] [1 -1]
// [0 4 sqrt(2)] [0 0]
A_h(0, 0) = 3;
A_h(0, 1) = 2;
A_h(1, 0) = 2;
A_h(1, 1) = 3;
A_h(2, 0) = 2;
A_h(0, 0) = 3;
A_h(0, 1) = 2;
A_h(1, 0) = 2;
A_h(1, 1) = 3;
A_h(2, 0) = 2;
A_h(2, 1) = -2;

Kokkos::deep_copy(A, A_h);
Expand Down Expand Up @@ -445,7 +449,7 @@ int impl_analytic_3x2_svd() {
EXPECT_NEAR_KK_REL(Kokkos::abs(U_real(1, 0)), one_sqrt2, tol);
EXPECT_NEAR_KK_REL(Kokkos::abs(U_real(1, 1)), one_sqrt18, tol);
EXPECT_NEAR_KK_REL(Kokkos::abs(U_real(1, 2)), 2 * one_third, tol);
EXPECT_NEAR_KK (Kokkos::abs(U_real(2, 0)), 0, tol);
EXPECT_NEAR_KK(Kokkos::abs(U_real(2, 0)), 0, tol);
EXPECT_NEAR_KK_REL(Kokkos::abs(U_real(2, 1)), 4 * one_sqrt18, tol);
EXPECT_NEAR_KK_REL(Kokkos::abs(U_real(2, 2)), one_third, tol);

Expand All @@ -472,7 +476,7 @@ int impl_test_svd(const int m, const int n) {
using scalar_type = typename AMatrix::value_type;
using KAT_S = Kokkos::ArithTraits<scalar_type>;
using mag_type = typename KAT_S::mag_type;
using vector_type =
using vector_type =
Kokkos::View<mag_type*, typename AMatrix::array_layout, Device>;

const mag_type tol = 1000 * KAT_S::eps();
Expand All @@ -481,7 +485,7 @@ int impl_test_svd(const int m, const int n) {
vector_type S("S", Kokkos::min(m, n));

const uint64_t seed =
std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::chrono::high_resolution_clock::now().time_since_epoch().count();
Kokkos::Random_XorShift64_Pool<execution_space> rand_pool(seed);

// Initialize A with random numbers
Expand All @@ -497,7 +501,7 @@ int impl_test_svd(const int m, const int n) {

// For larger sizes with the triple product
// we accumulate a bit more error apparently?
check_triple_product(Aref, S, U, Vt, 1000*tol);
check_triple_product(Aref, S, U, Vt, 1000 * tol);

return 0;
}
Expand Down

0 comments on commit caac290

Please sign in to comment.