20 #ifndef OHMMS_NUMERIC_DETERMINANT_H 21 #define OHMMS_NUMERIC_DETERMINANT_H 44 inline void LUFactorization(
int n,
int m,
float* restrict a,
const int& n0,
int* restrict piv)
51 inline void LUFactorization(
int n,
int m, std::complex<double>* restrict a,
int n0,
int* restrict piv)
58 inline void LUFactorization(
int n,
int m, std::complex<float>* restrict a,
int n0,
int* restrict piv)
65 inline void InvertLU(
int n,
double* restrict a,
int n0,
int* restrict piv,
double* restrict work,
int n1)
68 dgetri(
n, a, n0, piv, work, n1, status);
80 sgetri(
n, a, n0, piv, work, n1, status);
85 std::complex<double>* restrict a,
88 std::complex<double>* restrict work,
92 zgetri(
n, a, n0, piv, work, n1, status);
97 std::complex<float>* restrict a,
100 std::complex<float>* restrict work,
104 cgetri(
n, a, n0, piv, work, n1, status);
118 inline T
Invert(T* restrict x,
int n,
int m, T* restrict work,
int* restrict pivot)
122 for (
int i = 0, ip = 1; i <
m; i++, ip++)
125 detvalue *= x[i *
m + i];
127 detvalue *= -x[i *
m + i];
145 for (
int i = 0, ip = 1; i <
m; i++, ip++)
148 detvalue *= x[i *
m + i];
150 detvalue *= -x[i *
m + i];
166 std::vector<int> pivot(
n);
167 std::vector<T> work(
n);
168 return Invert(x,
n,
m, work.data(), pivot.data());
171 template<
class T,
class T1>
172 inline void InvertWithLog(T* restrict x,
int n,
int m, T* restrict work,
int* restrict pivot, std::complex<T1>& logdet)
175 logdet = std::complex<T1>();
176 for (
int i = 0; i <
n; i++)
177 logdet +=
std::log(std::complex<T1>((pivot[i] == i + 1) ? x[i *
m + i] : -x[i *
m + i]));
186 template<
class MatrixA>
191 const int n = M.rows();
192 std::vector<int> pivot(
n);
193 std::vector<value_type> work(
n);
200 for (
int i = 0; i <
n; ++i)
202 if (pivot[i] != i + 1)
208 InvertLU(
n, M.data(),
n, pivot.data(), work.data(),
n);
218 template<
typename MatA,
typename VecB>
221 return simd::dot(Minv[rowchanged], newv.data(), Minv.cols());
231 template<
typename MatA,
typename VecB>
235 return simd::dot(Minv.cols(), Minv.data() + colchanged, Minv.cols(), newv.data(), 1);
246 template<
typename T,
typename ALLOC>
268 template<
typename T,
typename ALLOC>
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
helper functions for EinsplineSetBuilder
T Determinant(T *restrict x, int n, int m, int *restrict pivot)
determinant of a matrix
T dot(const T *restrict a, const T *restrict b, int n, TRES res=TRES())
dot product
void InverseUpdateByRow(Matrix< T, ALLOC > &Minv, Vector< T, ALLOC > &newrow, Vector< T, ALLOC > &rvec, Vector< T, ALLOC > &rvecinv, int rowchanged, T c_ratio)
update a inverse matrix by a row substitution
void cgetri(const int &n, std::complex< float > *a, const int &n0, int const *piv, std::complex< float > *work, const int &, int &st)
void LUFactorization(int n, int m, double *restrict a, int n0, int *restrict piv)
LU factorization of double.
void InvertLU(int n, double *restrict a, int n0, int *restrict piv, double *restrict work, int n1)
Inversion of a double matrix after LU factorization.
MatA::value_type DetRatioByRow(const MatA &Minv, const VecB &newv, int rowchanged)
determinant ratio with a row substitution
void sgetri(const int &n, float *a, const int &n0, int const *piv, float *work, const int &, int &st)
void InvertWithLog(T *restrict x, int n, int m, T *restrict work, int *restrict pivot, std::complex< T1 > &logdet)
MatA::value_type DetRatioByColumn(const MatA &Minv, const VecB &newv, int colchanged)
determinant ratio with a column substitution
void dgetrf(const int &n, const int &m, double *a, const int &n0, int *piv, int &st)
void cgetrf(const int &n, const int &m, std::complex< float > *a, const int &n0, int *piv, int &st)
void zgetri(const int &n, std::complex< double > *a, const int &n0, int const *piv, std::complex< double > *work, const int &, int &st)
void sgetrf(const int &n, const int &m, float *a, const int &n0, int *piv, int &st)
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
void det_row_update(T *restrict pinv, const T *restrict tv, int m, int rowchanged, T c_ratio, T *restrict temp, T *restrict rcopy)
T Invert(T *restrict x, int n, int m, T *restrict work, int *restrict pivot)
inverse a matrix
void det_col_update(T *restrict pinv, const T *restrict tv, int m, int colchanged, T c_ratio, T *restrict temp, T *restrict rcopy)
QMCTraits::FullPrecRealType value_type
void zgetrf(const int &n, const int &m, std::complex< double > *a, const int &n0, int *piv, int &st)
void dgetri(const int &n, double *a, const int &n0, int const *piv, double *work, const int &, int &st)
void InverseUpdateByColumn(Matrix< T, ALLOC > &Minv, Vector< T, ALLOC > &newcol, Vector< T, ALLOC > &rvec, Vector< T, ALLOC > &rvecinv, int colchanged, T c_ratio)