dune-common  2.8.0
transpose.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_COMMON_TRANSPOSE_HH
4 #define DUNE_COMMON_TRANSPOSE_HH
5 
6 #include <cstddef>
7 
8 #include <dune/common/fmatrix.hh>
10 
11 namespace Dune {
12 
13 namespace Impl {
14 
15  // Wrapper representing the transposed of a matrix.
16  // Creating the wrapper does not compute anything
17  // but only serves for tagging the wrapped matrix
18  // for transposition.
19  template<class M>
20  class TransposedMatrixWrapper
21  {
22  public:
23 
24  enum {
26  rows = M::cols,
28  cols = M::rows
29  };
30 
31  TransposedMatrixWrapper(const M& matrix) : matrix_(matrix) {}
32  TransposedMatrixWrapper(const TransposedMatrixWrapper&) = delete;
33  TransposedMatrixWrapper(TransposedMatrixWrapper&&) = delete;
34 
35  template<class OtherField, int otherRows>
36  friend auto operator* (const FieldMatrix<OtherField, otherRows, rows>& matrixA,
37  const TransposedMatrixWrapper& matrixB)
38  {
39  using ThisField = typename FieldTraits<M>::field_type;
41  FieldMatrix<Field, otherRows, cols> result;
42  for (std::size_t j=0; j<otherRows; ++j)
43  matrixB.matrix_.mv(matrixA[j], result[j]);
44  return result;
45  }
46 
47  private:
48 
49  const M& matrix_;
50  };
51 
52 } // namespace Impl
53 
69 template<class Matrix>
70 auto transpose(const Matrix& matrix) {
71  return Impl::TransposedMatrixWrapper<Matrix>(matrix);
72 }
73 
74 
75 } // namespace Dune
76 
77 #endif // DUNE_COMMON_TRANSPOSE_HH
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Compute type of the result of an arithmetic operation involving two different number types.
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:544
Dune namespace.
Definition: alignedallocator.hh:11
auto transpose(const Matrix &matrix)
Create a wrapper modelling the transposed matrix.
Definition: transpose.hh:70
T field_type
export the type representing the field
Definition: ftraits.hh:26
decltype(std::declval< T1 >()+std::declval< T2 >()) typedef PromotedType
Definition: promotiontraits.hh:26