QMCPACK
determinant_operators.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_DETERMINANT_OPERATORS_FAST_H
16 #define QMCPLUSPLUS_DETERMINANT_OPERATORS_FAST_H
17 #include <complex>
18 #include <algorithm>
19 #include <cstring>
20 #include "OhmmsPETE/TinyVector.h"
21 #include "OhmmsPETE/OhmmsVector.h"
22 #include "OhmmsPETE/OhmmsMatrix.h"
23 //extern "C"
24 //{
25 // void dger_(const int& m, const int& n, const double& alpha
26 // , const double* x, const int& incx, const double* y, const int& incy
27 // , double* a, const int& lda);
28 //}
29 namespace qmcplusplus
30 {
31 template<typename T>
33 {};
34 
35 template<>
36 struct const_traits<double>
37 {
38  using value_type = double;
39  inline static double zero() { return 0.0; }
40  inline static double one() { return 1.0; }
41  inline static double minus_one() { return -1.0; }
42 };
43 
44 template<>
45 struct const_traits<std::complex<double>>
46 {
47  using value_type = std::complex<double>;
48  inline static std::complex<double> zero() { return value_type(); }
49  inline static std::complex<double> one() { return value_type(1.0, 0.0); }
50  inline static std::complex<double> minus_one() { return value_type(-1.0, 0.0); }
51 };
52 
53 template<>
54 struct const_traits<float>
55 {
56  using value_type = float;
57  inline static float zero() { return 0.0f; }
58  inline static float one() { return 1.0f; }
59  inline static float minus_one() { return -1.0f; }
60 };
61 
62 template<>
63 struct const_traits<std::complex<float>>
64 {
65  using value_type = std::complex<float>;
66  inline static std::complex<float> zero() { return value_type(); }
67  inline static std::complex<float> one() { return value_type(1.0f, 0.0f); }
68  inline static std::complex<float> minus_one() { return value_type(-1.0f, 0.0f); }
69 };
70 
71 template<typename T>
72 inline void det_row_update(T* restrict pinv,
73  const T* restrict tv,
74  int m,
75  int rowchanged,
76  T c_ratio,
77  T* restrict temp,
78  T* restrict rcopy) //pass buffer
79 {
80  //const T ratio_inv(1.0/c_ratio);
81  c_ratio = T(1) / c_ratio;
82  BLAS::gemv('T', m, m, c_ratio, pinv, m, tv, 1, const_traits<T>::zero(), temp, 1);
83  temp[rowchanged] = const_traits<T>::one() - c_ratio;
84  memcpy(rcopy, pinv + m * rowchanged, m * sizeof(T));
85  BLAS::ger(m, m, const_traits<T>::minus_one(), rcopy, 1, temp, 1, pinv, m);
86 }
87 
88 template<typename T>
89 inline void det_col_update(T* restrict pinv,
90  const T* restrict tv,
91  int m,
92  int colchanged,
93  T c_ratio,
94  T* restrict temp,
95  T* restrict rcopy)
96 {
97  const T cone(1);
98  c_ratio = cone / c_ratio;
99  BLAS::gemv('N', m, m, c_ratio, pinv, m, tv, 1, T(), temp, 1);
100  temp[colchanged] = cone - c_ratio;
101  BLAS::copy(m, pinv + colchanged, m, rcopy, 1);
102  BLAS::ger(m, m, -1.0, temp, 1, rcopy, 1, pinv, m);
103 }
104 
105 template<typename T>
106 inline void getRatiosByRowSubstitution(const T* restrict tm_new,
107  const T* restrict r_replaced,
108  T* restrict ratios,
109  int m,
110  int howmany)
111 {
112  BLAS::gemv('T', m, howmany, const_one(T()), tm_new, m, r_replaced, 1, T(), ratios, 1);
113 }
114 
115 template<typename T, typename INDARRAY>
116 inline void getRatiosByRowSubstitution(const T* restrict tm_new,
117  const T* restrict r_replaced,
118  T* restrict ratios,
119  int m,
120  const INDARRAY& ind)
121 {
122  for (int i = 0; i < ind.size(); ++i)
123  ratios[i] = BLAS::dot(r_replaced, tm_new + ind[i] * m, m);
124 }
125 
126 template<typename T>
127 inline void getRatiosByRowSubstitution_dummy(const T* restrict tm_new,
128  const T* restrict r_replaced,
129  T* restrict ratios,
130  int m,
131  int howmany)
132 {
133  for (int i = 0; i < howmany; ++i)
134  ratios[i] = BLAS::dot(r_replaced, tm_new + i * m, m);
135 }
136 
137 /** evaluate the determinant ratio with a column substitution
138 */
139 template<typename T>
140 inline T getRatioByColSubstitution(const T* restrict pinv, const T* restrict tc, int m, int colchanged)
141 {
142  return BLAS::dot(m, pinv + colchanged, m, tc, 1);
143 }
144 
145 template<typename MAT, typename VV>
146 inline typename MAT::value_type getRatioByColSubstitution(const MAT& pinv, const VV& tc, int colchanged)
147 {
148  return BLAS::dot(pinv.cols(), pinv.data() + colchanged, pinv.cols(), tc.data(), 1);
149 }
150 
151 
152 /** evaluate the ratio with a column substitution and multiple row substitutions
153  *
154  * @param refinv reference inverse(m,m)
155  * @param tcm new column whose size > m
156  * @param ratios ratios of the row substitutions with the column substitution
157  * @param m dimension
158  * @param colchanged ratio with a column substitution of refinv
159  * @param r_replaced row index for the excitations in ind
160  * @param ind indexes for the excited states (rows)
161  * @return the ratio when a column is replaced for the refinv
162  */
163 template<typename MAT, typename VV, typename IV>
164 inline typename MAT::value_type getRatioByColSubstitution(const MAT& refinv,
165  const VV& tcm,
166  VV& ratios,
167  int m,
168  int colchanged,
169  int r_replaced,
170  IV& ind)
171 {
172  using value_type = typename MAT::value_type;
173  //save the value of refinv(r,c)
174  value_type old_v = refinv(r_replaced, colchanged);
175  value_type pinned = tcm[r_replaced] * old_v;
176  typename MAT::value_type res0 = BLAS::dot(m, refinv.data() + colchanged, m, tcm.data(), 1);
177  for (int i = 0; i < ind.size(); ++i)
178  ratios[i] = res0 - pinned + old_v * tcm[ind[i] + m];
179  return res0;
180 }
181 
182 } // namespace qmcplusplus
183 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
static void gemv(int n, int m, const double *restrict amat, const double *restrict x, double *restrict y)
Definition: BLAS.hpp:118
void getRatiosByRowSubstitution_dummy(const T *restrict tm_new, const T *restrict r_replaced, T *restrict ratios, int m, int howmany)
static void ger(int m, int n, double alpha, const double *x, int incx, const double *y, int incy, double *a, int lda)
Definition: BLAS.hpp:437
static T dot(int n, const T *restrict a, const T *restrict b)
Definition: BLAS.hpp:304
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)
static void copy(int n, const T *restrict a, T *restrict b)
Definition: BLAS.hpp:381
void getRatiosByRowSubstitution(const T *restrict tm_new, const T *restrict r_replaced, T *restrict ratios, int m, int howmany)
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
T getRatioByColSubstitution(const T *restrict pinv, const T *restrict tc, int m, int colchanged)
evaluate the determinant ratio with a column substitution