17 #ifndef QMCPLUSPLUS_MATRIXOPERATORS_H 18 #define QMCPLUSPLUS_MATRIXOPERATORS_H 29 namespace MatrixOperators
38 const char transa =
'N';
39 const char transb =
'N';
42 BLAS::gemm(transa, transb,
B.cols(),
A.rows(),
B.rows(), one,
B.data(),
B.cols(),
A.data(),
A.cols(), zero,
C.data(),
49 const char transa =
't';
50 const char transb =
'n';
53 BLAS::gemm(transa, transb,
B.rows(),
A.rows(),
B.cols(), one,
B.data(),
B.cols(),
A.data(),
A.cols(), zero,
C.data(),
60 const char transa =
'n';
61 const char transb =
't';
64 BLAS::gemm(transa, transb,
B.cols(),
A.cols(),
B.rows(), one,
B.data(),
B.cols(),
A.data(),
A.cols(), zero,
C.data(),
71 for (
int i = 0; i <
C.rows(); i++)
72 for (
int j = 0; j <
C.cols(); j++)
73 C(iat, i) += M(i, j) *
B[j];
80 for (
int i = 0; i <
C.rows(); i++)
81 for (
int j = 0; j <
C.cols(); j++)
82 C(i, iat) += M(i, j) *
B[j];
90 for (
int i = 0; i <
A.size(); i++)
100 for (
int i = 0; i <
A.extent(0); i++)
101 for (
int j = 0; j < i; j++)
102 std::swap(
A(i, j),
A(j, i));
113 template<
typename T1,
typename T2,
typename T3>
116 for (
int i = 0; i <
C.rows(); ++i)
117 for (
int j = 0; j <
C.cols(); ++j)
118 C(i, j) =
A(i, j) *
B[j];
128 template<
typename T1,
typename T2,
typename T3>
131 for (
int i = 0; i <
C.rows(); ++i)
132 for (
int j = 0; j <
C.cols(); ++j)
133 C(i, j) =
A[i] *
B(i, j);
161 std::cerr <<
" Undefined C=AB with real A and complex B " << std::endl;
169 const char transa =
'T';
172 BLAS::gemv(transa,
A.cols(),
A.rows(), one,
A.data(),
A.cols(), x.
data(), 1, zero, y.
data(), 1);
180 const char transa =
'N';
183 BLAS::gemv(transa,
A.cols(),
A.rows(), one,
A.data(),
A.cols(), x.
data(), 1, zero, y.
data(), 1);
188 template<
typename T,
unsigned D>
193 const char transa =
'N';
194 const char transb =
'N';
195 BLAS::gemm(transa, transb, D,
A.rows(),
A.cols(), one, xvPtr->
begin(), D,
A.data(),
A.cols(), zero, yptr->
begin(), D);
198 template<
typename T,
unsigned D>
203 const char transa =
'N';
204 const char transb =
'N';
205 BLAS::gemm(transa, transb, D * D,
A.rows(),
A.cols(), one, xvPtr->
begin(), D * D,
A.data(),
A.cols(), zero,
206 yptr->
begin(), D * D);
216 const double one = 1.0;
217 const double zero = 0.0;
218 const char transa =
'N';
219 const char transb =
'N';
220 dgemm(transa, transb, D,
A.rows(), x.size(), one, x.data()->begin(), D,
A.data(),
A.cols(), zero, yptr->
begin(), D);
228 TinyVector<std::complex<double>, D>* restrict yptr)
230 const char transa =
'N';
231 const char transb =
'N';
232 const std::complex<double>
zone(1.0, 0.0);
233 const std::complex<double> zero(0.0, 0.0);
234 zgemm(transa, transb, D,
A.rows(), x.size(),
zone, x.data()->begin(), D,
A.data(),
A.cols(), zero, yptr->begin(), D);
241 const Vector<std::complex<double>>& x,
242 std::complex<double>* restrict yptr)
244 const char transa =
'T';
245 const std::complex<double>
zone(1.0, 0.0);
246 const std::complex<double> zero(0.0, 0.0);
247 zgemv(transa,
A.cols(),
A.rows(),
zone,
A.data(),
A.cols(), x.data(), 1, zero, yptr, 1);
254 const int n =
A.rows();
255 const int m =
A.cols();
256 const std::complex<double>* restrict aptr =
A.data();
257 for (
int i = 0, ij = 0; i <
n; ++i)
259 std::complex<double> t = 0.0;
260 for (
int j = 0; j <
m; ++j, ++ij)
261 t += aptr[ij] * x[j];
void zgemm(const char &, const char &, const int &, const int &, const int &, const std::complex< double > &, const std::complex< double > *, const int &, const std::complex< double > *, const int &, const std::complex< double > &, std::complex< double > *, const int &)
helper functions for EinsplineSetBuilder
double innerProduct(const Vector< double > &A, const Vector< double > &B)
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 product_Atx(const Matrix< T > &A, const Vector< T > &x, Vector< T > &y)
static function to perform y = A^t x for generic matrix and vector
void dgemm(const char &, const char &, const int &, const int &, const int &, const double &, const double *, const int &, const double *, const int &, const double &, double *, const int &)
static void gemv(int n, int m, const double *restrict amat, const double *restrict x, double *restrict y)
constexpr std::complex< double > zone
void zgemv(const char &trans, const int &nr, const int &nc, const std::complex< double > &alpha, const std::complex< double > *amat, const int &lda, const std::complex< double > *bv, const int &incx, const std::complex< double > &beta, std::complex< double > *cv, const int &incy)
Tensor<T,D> class for D by D tensor.
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
void product_ABt(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
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)
void transpose(Matrix< T > &A)
double B(double x, int k, int i, const std::vector< double > &t)
void other_half_outerProduct(const Matrix< double > &M, const Vector< double > &B, int iat, Matrix< double > &C)
SIMD version of functions in algorithm.
void product_AtB(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
void half_outerProduct(const Matrix< double > &M, const Vector< double > &B, int iat, Matrix< double > &C)
void diag_product(const Matrix< T1 > &A, const Vector< T2 > &B, Matrix< T3 > &C)
C = A*diag(B)