12 #include <type_traits> 27 using RngValueType =
typename std::disjunction<OnTypesEqual<T, float, float>,
28 OnTypesEqual<T, double, double>,
29 OnTypesEqual<T, std::complex<float>,
float>,
30 OnTypesEqual<T, std::complex<double>,
double>,
36 template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value,
void>::type>
39 int n = mat_spd.
rows();
42 rng.fillBufferRng(mat_a.
data(), mat_a.
size());
53 std::vector<T> singular_values(
n);
54 std::vector<T> work_vec(5 *
n);
56 const char trans =
't';
57 const char notrans =
'n';
59 BLAS::gemm(trans, notrans,
n,
n,
n, 1.0, mat_a.
data(),
n, mat_a_t.
data(),
n, 0.0, mat_c.
data(),
n);
60 LAPACK::gesvd(all, all,
n,
n, mat_c.
data(),
n, singular_values.data(), mat_u.
data(),
n, mat_v.
data(),
n,
61 work_vec.data(), work_vec.size(), info);
64 for (
int i = 0; i <
n; ++i)
65 mat_diag(i, i) = rng();
68 BLAS::gemm(notrans, notrans,
n,
n,
n, 1.0, mat_u.
data(),
n, mat_diag.
data(),
n, 0.0, mat_a_t.
data(),
n);
70 BLAS::gemm(notrans, notrans,
n,
n,
n, 1.0, mat_a_t.
data(),
n, mat_v.
data(),
n, 0.0, mat_u.
data(),
n);
75 template<
typename T, IsComplex<T> = true>
78 int n = mat_spd.
rows();
81 rng.fillBufferRng(mat_a.
data(), mat_a.
size());
92 std::vector<typename T::value_type> singular_values(
n);
93 std::vector<T> work_vec(5 *
n);
94 std::vector<typename T::value_type> real_work_vec(5 *
n);
96 const char trans =
't';
97 const char notrans =
'n';
99 BLAS::gemm(trans, notrans,
n,
n,
n, 1.0, mat_a.
data(),
n, mat_a_t.data(),
n, 0.0, mat_c.
data(),
n);
100 LAPACK::gesvd(all, all,
n,
n, mat_c.
data(),
n, singular_values.data(), mat_u.
data(),
n, mat_v.
data(),
n,
101 work_vec.data(), work_vec.size(), real_work_vec.data(), info);
104 for (
int i = 0; i <
n; ++i)
105 mat_diag(i, i) = rng();
108 BLAS::gemm(notrans, notrans,
n,
n,
n, 1.0, mat_u.
data(),
n, mat_diag.
data(),
n, 0.0, mat_a_t.data(),
n);
110 BLAS::gemm(notrans, notrans,
n,
n,
n, 1.0, mat_a_t.data(),
n, mat_v.
data(),
n, 0.0, mat_u.
data(),
n);
129 template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value,
void>::type>
133 rng.fillBufferRng(vec.
data(), vec.
size());
helper functions for EinsplineSetBuilder
testing::RandomForTest< RngValueType< T > > rng
Get a known sequence of random numbers for testing.
void operator()(Vector< T > &vec)
void transpose(const T *restrict A, size_t m, size_t lda, TO *restrict B, size_t n, size_t ldb)
transpose of A(m,n) to B(n,m)
void resize(size_type n, size_type m)
Resize the container.
void operator()(Matrix< T > &mat_spd)
Functor to provide scope for rng when making SpdMatrix for testing.
void makeRngSpdMatrix(testing::RandomForTest< RngValueType< T >> &rng, Matrix< T > &mat_spd)
size_type size() const
return the current size
static void gesvd(const char &jobu, const char &jobvt, const int &m, const int &n, float *a, const int &lda, float *s, float *u, const int &ldu, float *vt, const int &ldvt, float *work, const int &lwork, int &info)
void makeRngVector(testing::RandomForTest< RngValueType< T >> &rng, Vector< T > &vec)
make a random Vector
typename std::disjunction< OnTypesEqual< T, float, float >, OnTypesEqual< T, double, double >, OnTypesEqual< T, std::complex< float >, float >, OnTypesEqual< T, std::complex< double >, double >, default_type< void > >::type RngValueType
Get the right type for rng in case of complex T.
static void gemm(char Atrans, char Btrans, int M, int N, int K, double alpha, const double *A, int lda, const double *restrict B, int ldb, double beta, double *restrict C, int ldc)
SIMD version of functions in algorithm.
testing::RandomForTest< RngValueType< T > > rng
Functor to provide scope for rng when making SpdMatrix for testing.