CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Template_Algorithms.hh
Go to the documentation of this file.
1 #ifndef TEMPLATE_ALGORITHMS_HH
2 #define TEMPLATE_ALGORITHMS_HH
3 
4 #include <cmath>
5 
6 namespace CASM {
7 
8 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 
11 template <class Container, class T>
12 class GramSchmidt {
13  public:
14  static void orthogonalize(Array<Container> &rows) {
15  Index i, j;
16  T tcoeff;
17  for (i = 0; i < rows.size(); i++) {
18  for (j = 0; j < i; j++) rows[i] -= dot(rows[i], rows[j]) * rows[j];
19 
20  tcoeff = norm(rows[i]);
21  if (TOL < tcoeff)
22  rows[i] /= tcoeff;
23 
24  else {
25  rows.remove(i);
26  i--;
27  }
28  }
29  return;
30  }
31 };
32 
33 }; // namespace CASM
34 #endif
Basic std::vector like container (deprecated)
Definition: Array.hh:45
Index size() const
Definition: Array.hh:131
static void orthogonalize(Array< Container > &rows)
void remove(Index ind)
Definition: Array.hh:462
T dot(const Tensor< T > &LHS, const Tensor< T > &RHS)
Definition: Tensor.hh:925
T norm(const Tensor< T > &ttens)
Definition: Tensor.hh:932
Main CASM namespace.
Definition: APICommand.hh:8
const double TOL
Definition: definitions.hh:30
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39