CHROMA
gramschm_array.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Gramm-Schmidt orthogonolization
3  */
4 
6 
7 namespace Chroma {
8 
9 //! Gramm-Schmidt orthogonolization
10 /*!
11  * \ingroup eig
12  *
13  * Templated version
14  *
15  * Arguments:
16  * \param psi 5D Pseudofermion field (Modify)
17  * \param vec 5D subspace wrt orthog (Read)
18  * \param Nvec Number of vectors (Read)
19  * \param Npsi Number of source vectors (Read)
20  * \param sub Subset to use (Read)
21  */
22 
23 // The multi2d is an annoyance.
24 // I anticipate that it is called as
25 // multi2d T(Nvec, N5) -- Nvec is "size2" and N5 is "size1"
26 // T[i] is a std::vector of size N5
27 template< typename T>
28 void GramSchmArray_T(multi2d<T>& psi, const int Npsi,
29  const multi2d<T>& vec, const int Nvec,
30  const Subset& sub)
31 {
32 
33  START_CODE();
34 
35  // if I was paranoid I'd assert that Npsi and Nvec are
36  // reasonable
37 #if 0
38  // Make sure the No of vecs is OK
39  if ( Npsi > psi.size2() || Nvec > vec.size2() ) {
40  QDP_error_exit("Npsi and Nvec are out of range in GramSchm. Npsi=%d, Nvec=%d, psi.size2()= %d, vec.size2() = %d", Npsi,Nvec, psi.size2(), vec.size2());
41  }
42 
43  if( psi.size1() != vec.size1() ) {
44  QDP_error_exit("psi and vec have different lengths in 5th Dim. psi.size1() = %d vec.size1() = %d\n", psi.size1(), vec.size1() );
45  }
46 #endif
47  int N5 = vec.size1();
48 
49  for(int s = 0; s < Npsi; ++s)
50  {
51  for(int i = 0; i < Nvec; ++i)
52  {
53  // Accumulate the 5D inner product into xp
54  Complex xp = innerProduct(vec[i][0], psi[s][0], sub);
55  for(int n = 1; n < N5; n++) {
56  xp += innerProduct(vec[i][n], psi[s][n], sub);
57  }
58 
59  // Now orthogonalise all N5 components
60  for(int n=0; n < N5; n++) {
61  psi[s][n][sub] -= vec[i][n] * xp;
62  }
63  }
64  }
65 
66  END_CODE();
67 }
68 
69 //! Gram Schmidt rothogonalisation
70 /*!
71  * \ingroup eig
72  *
73  * Orthogonalise single std::vector psi against
74  * the first Nvec vectors of vec
75  *
76  * Templated version
77  * Arguments:
78  * \param psi 5D Pseudofermion field (Modify)
79  * \param vec 5D subspace wrt orthog (Read)
80  * \param Nvec no of vectors to orthog against (Read)
81  * \param sub Subset to use (Read)
82  */
83 
84 // The multi2d is an annoyance.
85 // I anticipate that it is called as
86 // multi2d T(Nvec, N5) -- Nvec is "size2" and N5 is "size1"
87 // T[i] is a std::vector of size N5
88 template <typename T>
89 void GramSchmArray_T(multi1d<T>& psi,
90  const multi2d<T>& vec,
91  const int Nvec,
92  const Subset& sub)
93 {
94 
95  START_CODE();
96 #if 0
97  if ( Nvec > vec.size2() ) {
98  QDP_error_exit("Nvec out of range in GramSchm. Nvec=%d vec.size2()=%d\n",
99  Nvec, vec.size2());
100  }
101 
102  if( psi.size() != vec.size1() ) {
103  QDP_error_exit("psi and vec have different lengths in the 5th dimension. psi.size()=%d vec.size1()=%d", psi.size(), vec.size1());
104  }
105 #endif
106  int N5 = psi.size();
107 
108  for(int i = 0; i < Nvec; ++i)
109  {
110  Complex xp = innerProduct(vec[i][0], psi[0], sub);
111  for(int n = 0; n < N5; n++) {
112  xp += innerProduct(vec[i][n], psi[n], sub);
113  }
114 
115  for(int n=0; n < N5; n++)
116  psi[n][sub] -= vec[i][n] * xp;
117  }
118 
119  END_CODE();
120 }
121 
122 //! Gram Schmidt rothogonalisation
123 /*!
124  * \ingroup eig
125  *
126  * Orthogonalise single std::vector psi against
127  * vec
128  *
129  * Templated version
130  * Arguments:
131  * \param psi 5D Pseudofermion field (Modify)
132  * \param vec 5D std::vector to orthog. against (Read)
133  * \param sub Subset to use (Read)
134  */
135 template <typename T>
136 void GramSchmArray_T(multi1d<T>& psi,
137  const multi1d<T>& vec,
138  const Subset& sub)
139 {
140 
141  START_CODE();
142 
143 #if 0
144  if( psi.size() != vec.size() ) {
145  QDP_error_exit("psi and vec have different lengths in the 5th dimension: psi.size() = %d, vec.size()=%d\n", psi.size(), vec.size());
146  }
147 #endif
148 
149  int N5 = psi.size();
150 
151  Complex xp = innerProduct(vec[0], psi[0], sub);
152  for(int i = 1; i < N5; i++) {
153  xp += innerProduct(vec[i], psi[i], sub);
154  }
155 
156  for(int i=0; i < N5; i++) {
157  psi[i][sub] -= vec[i] * xp;
158  }
159 
160  END_CODE();
161 }
162 
163 
164 
165 //! Gramm-Schmidt orthogonolization
166 /*!
167  * \ingroup eig
168  *
169  * Arguments:
170  * \param psi 5D Pseudofermion field (Modify)
171  * \param vec 5D subspace wrt orthog (Read)
172  * \param Nvec Number of vectors (Read)
173  * \param Npsi Number of source vectors (Read)
174  */
175 
176 void GramSchmArray(multi2d<LatticeFermion>& psi, const int Npsi,
177  const multi2d<LatticeFermion>& vec, const int Nvec,
178  const Subset& sub)
179 {
180  GramSchmArray_T(psi, Npsi, vec, Nvec, sub);
181 }
182 
183 //! Gram Schmidt rothogonalisation
184 /*!
185  * \ingroup eig
186  *
187  * Orthogonalise single std::vector psi against
188  * the first Nvec vectors of vec
189  *
190  * Arguments:
191  * \param psi 5D Pseudofermion field (Modify)
192  * \param vec 5D subspace wrt orthog (Read)
193  * \param Nvec no of vectors to orthog against (Read)
194  * \param sub Subset to use (Read)
195  */
196 void GramSchmArray(multi1d<LatticeFermion>& psi,
197  const multi2d<LatticeFermion>& vec,
198  const int Nvec,
199  const Subset& sub)
200 {
201  START_CODE();
202 
203  GramSchmArray_T(psi, vec, Nvec, sub);
204 
205  END_CODE();
206 }
207 
208 //! Gram Schmidt rothogonalisation
209 /*!
210  * \ingroup eig
211  *
212  * Convenience function: Orthogonalise all vectors of psi against
213  * the first Nvec vectors of vec
214  *
215  * Arguments:
216  * \param psi 5D Pseudofermion field (Modify)
217  * \param vec 5D subspace wrt orthog (Read)
218  * \param Nvec Number of vectors (Read)
219  * \param sub Subset to use (Read)
220  */
221 void GramSchmArray(multi2d<LatticeFermion>& psi,
222  const multi2d<LatticeFermion>& vec, const int Nvec,
223  const Subset& sub)
224 {
225  GramSchmArray_T(psi, psi.size2(), vec, Nvec, sub);
226 }
227 
228 
229 
230 //! Gram Schmidt rothogonalisation
231 /*!
232  * \ingroup eig
233  *
234  * Convenience function: Orthogonalise all vectors of psi against
235  * the all the vectors of vec
236  *
237  * Arguments:
238  * \param psi 5D Pseudofermion fields (Modify)
239  * \param vec 5D subspace wrt orthog (Read)
240  * \param sub Subset to use (Read)
241  */
242 void GramSchmArray(multi2d<LatticeFermion>& psi,
243  const multi2d<LatticeFermion>& vec,
244  const Subset& sub)
245 {
246  GramSchmArray_T(psi, psi.size2(), vec, vec.size2(), sub);
247 }
248 
249 //! Gram Schmidt rothogonalisation
250 /*!
251  * \ingroup eig
252  *
253  * Convenience function: Orthogonalise single std::vector psi against
254  * all the vectors of vec
255  *
256  * Arguments:
257  * \param psi 5D Pseudofermion field (Modify)
258  * \param vec 5D subspace wrt orthog (Read)
259  * \param Nvec no of vectors to orthog against (Read)
260  * \param sub Subset to use (Read)
261  */
262 void GramSchmArray(multi1d<LatticeFermion>& psi,
263  const multi2d<LatticeFermion>& vec,
264  const Subset& sub)
265 {
266  GramSchmArray_T(psi, vec, vec.size2(), sub);
267 }
268 
269 
270 //! Gram Schmidt rothogonalisation
271 /*!
272  * \ingroup eig
273  *
274  * Orthogonalise single std::vector psi against
275  * a single std::vector vec
276  *
277  * Templated version
278  * Arguments:
279  * \param psi 5D Pseudofermion field (Modify)
280  * \param vec 5D subspace wrt orthog (Read)
281  * \param Nvec no of vectors to orthog against (Read)
282  * \param sub Subset to use (Read)
283  */
284 void GramSchmArray(multi1d<LatticeFermion>& psi,
285  const multi1d<LatticeFermion>& vec,
286  const Subset& sub)
287 {
288  GramSchmArray_T(psi,vec,sub);
289 }
290 
291 } // end namespace Chroma
Gramm-Schmidt orthogonolization.
void GramSchmArray(multi2d< LatticeFermion > &psi, const int Npsi, const multi2d< LatticeFermion > &vec, const int Nvec, const Subset &sub)
Gramm-Schmidt orthogonolization.
void GramSchmArray_T(multi2d< T > &psi, const int Npsi, const multi2d< T > &vec, const int Nvec, const Subset &sub)
Gramm-Schmidt orthogonolization.
unsigned n
Definition: ldumul_w.cc:36
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
int i
Definition: pbg5p_w.cc:55
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
multi1d< LatticeFermion > s(Ncb)