RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
addTransposedMatrix.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_UTIL_ADDTRANSPOSEDMATRIX_HH
22 #define RFFGEN_UTIL_ADDTRANSPOSEDMATRIX_HH
23 
24 #include <cassert>
25 #include <type_traits>
26 #include "../LinearAlgebra/dimension.hh"
27 #include "../Util/staticChecks.hh"
28 
29 namespace RFFGen
30 {
35  template <class Matrix ,
36  class = std::enable_if_t<Checks::isConstantSizeMatrix<Matrix>()> >
37  Matrix addTransposed(Matrix& A)
38  {
39  using Index = decltype(LinearAlgebra::dimension<Matrix>());
40  for(Index i=0; i<LinearAlgebra::dimension<Matrix>(); ++i)
41  for(Index j=i+1; j<LinearAlgebra::dimension<Matrix>(); ++j)
42  at(A,j,i) = at(A,i,j) = at(A,i,j) + at(A,j,i);
43  for(Index i=0; i<LinearAlgebra::dimension<Matrix>(); ++i) at(A,i,i) *= 2;
44  return A;
45  }
46 
51  template <class Matrix ,
52  class = std::enable_if_t<!Checks::isConstantSizeMatrix<Matrix>()> ,
53  class = std::enable_if_t<Checks::isDynamicMatrix<Matrix>()> >
54  Matrix addTransposed(Matrix& A)
55  {
56  assert( LinearAlgebra::rows(A) == LinearAlgebra::cols(A) );
57  using Index = decltype(LinearAlgebra::rows(std::declval<Matrix>()));
58  for(Index i=0; i<LinearAlgebra::rows(A); ++i)
59  for(Index j=i+1; j<LinearAlgebra::cols(A); ++j)
60  at(A,j,i) = at(A,i,j) = at(A,i,j) + at(A,j,i);
61  for(Index i=0; i<LinearAlgebra::rows(A); ++i) at(A,i,i) *= 2;
62  return A;
63  }
64 }
65 
66 #endif // RFFGEN_UTIL_ADDTRANSPOSEDMATRIX_HH
Matrix addTransposed(Matrix &A)
Overwrites with .
Definition: addTransposedMatrix.hh:37