CHROMA
norm_gram_schm.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Gram-Schmidt with normalization
4  */
5 
7 
8 namespace Chroma
9 {
10 
11  //! Gram-Schmidt with normalization
12  /*! \ingroup invert */
13  template<typename T>
14  void normGramSchmidt_T(multi1d<T>& vec,
15  int f,
16  int t,
17  const Subset& sub)
18  {
19  // this need not to be done... we assume 0..f vectors are normal already
20  for(int i(0);i<f;i++){// normalize the first vectors...
21  vec[i][sub] /= Real(sqrt(norm2(vec[i],sub)));
22  }
23  if(!(t<=vec.size())){
24  QDPIO::cerr << __func__ << ": f="<<f<<" t="<<t<<" vec.size()="<<vec.size()<<std::endl;
25  QDPIO::cerr << __func__ << ": Out of bound!\n";
26  exit(1);
27  }
28  for(int i(f);i<t;i++)
29  { // now orthonormalize ther rest
30  for(int k(0);k<i;k++){
31  DComplex dcc = innerProduct(vec[k], vec[i], sub);
32  Complex cc = dcc;
33  //QDPIO::cout<<"GramS: "<<i<<" "<<k<<" "<<cc<<" "<<dcc<<std::endl;
34  vec[i][sub] = vec[i] - cc*vec[k];
35  }
36  Double in = 1.0/sqrt(norm2(vec[i],sub));
37  vec[i][sub] *= Real(in);
38  }
39  }
40 
41 
42  //! Gram-Schmidt with normalization
43  /*! \ingroup invert */
44  template<typename T>
45  void normGramSchmidtArray_T(multi2d<T>& vec,
46  int f,
47  int t,
48  const Subset& sub)
49  {
50  // this need not to be done... we assume 0..f vectors are normal already
51  for(int i(0);i<f;i++){// normalize the first vectors...
52  Real in = Real(1) / Real(sqrt(norm2(vec[i],sub)));
53  for(int s=0; s < vec.size1(); ++s)
54  vec[i][s][sub] *= in;
55  }
56  if(!(t<=vec.size2())){
57  QDPIO::cerr << __func__ << ": f="<<f<<" t="<<t<<" vec.size2()="<<vec.size2()<<std::endl;
58  QDPIO::cerr << __func__ << ": Out of bound!\n";
59  exit(1);
60  }
61  for(int i(f);i<t;i++)
62  { // now orthonormalize ther rest
63  for(int k(0);k<i;k++){
64  DComplex dcc = innerProduct(vec[k], vec[i], sub);
65  Complex cc = dcc;
66  //QDPIO::cout<<"GramS: "<<i<<" "<<k<<" "<<cc<<" "<<dcc<<std::endl;
67  for(int s=0; s < vec.size1(); ++s)
68  vec[i][s][sub] = vec[i][s] - cc*vec[k][s];
69  }
70  Real in = Real(1.0) / sqrt(norm2(vec[i],sub));
71  for(int s=0; s < vec.size1(); ++s)
72  vec[i][s][sub] *= Real(in);
73  }
74  }
75 
76  //
77  // Wrappers
78  //
79  // 4D versions
80  void normGramSchmidt(multi1d<LatticeFermionF>& vec,
81  int f,
82  int t,
83  const Subset& sub)
84  {
85  normGramSchmidt_T<LatticeFermionF>(vec, f, t, sub);
86  }
87 
88  void normGramSchmidt(multi1d<LatticeFermionD>& vec,
89  int f,
90  int t,
91  const Subset& sub)
92  {
93  normGramSchmidt_T<LatticeFermionD>(vec, f, t, sub);
94  }
95 
96  void normGramSchmidt(multi1d<LatticeStaggeredFermionF>& vec,
97  int f,
98  int t,
99  const Subset& sub)
100  {
101  normGramSchmidt_T<LatticeStaggeredFermionF>(vec, f, t, sub);
102  }
103 
104  void normGramSchmidt(multi1d<LatticeStaggeredFermionD>& vec,
105  int f,
106  int t,
107  const Subset& sub)
108  {
109  normGramSchmidt_T<LatticeStaggeredFermionD>(vec, f, t, sub);
110  }
111 
112 
113  // 5D versions
114  void normGramSchmidt(multi2d<LatticeFermionF>& vec,
115  int f,
116  int t,
117  const Subset& sub)
118  {
119  normGramSchmidtArray_T(vec, f, t, sub);
120  }
121 
122  void normGramSchmidt(multi2d<LatticeFermionD>& vec,
123  int f,
124  int t,
125  const Subset& sub)
126  {
127  normGramSchmidtArray_T(vec, f, t, sub);
128  }
129 
130 } // End Namespace Chroma
131 
void normGramSchmidt_T(multi1d< T > &vec, int f, int t, const Subset &sub)
Gram-Schmidt with normalization.
void normGramSchmidtArray_T(multi2d< T > &vec, int f, int t, const Subset &sub)
Gram-Schmidt with normalization.
void normGramSchmidt(multi1d< LatticeFermionF > &vec, int f, int t, const Subset &sub)
Gram-Schmidt with normalization.
int t
Definition: meslate.cc:37
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
int i
Definition: pbg5p_w.cc:55
static QDP_ColorVector * in
int k
Definition: invbicg.cc:119
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
Gram-Schmidt with normalization.