v0.14.0
Tensor2_times_Tensor1.hpp
Go to the documentation of this file.
1 // This file has all of the declarations for expressions like
2 // Tensor2*Tensor1 and Tensor1*Tensor2, yielding a Tensor1 or Tensor3.
3 
4 #pragma once
5 
6 #include "../permute.hpp"
7 
8 namespace FTensor
9 {
10  // A(i,j) * B(k) single contraction
11  template <class A, class B, class T, class U, int Dim0, int Dim1, int Dim2,
12  char i, char j, char k, int DimA, int DimX, char a, char x>
14  {
17 
18  public:
20  const Tensor1_Expr<B, U, Dim2, k> &iter_b)
21  : iterA(iter_a), iterB(iter_b)
22  {}
23  typename promote<T, U>::V operator()(const int N1) const
24  {
25  typename promote<T, U>::V result(0);
26  for(int xx = 0; xx < DimX; ++xx)
27  {
28  result += iterB(xx)
30  }
31  return result;
32  }
33  };
34 
35  // A(i,j)*B(j)
36  template <class A, class B, class T, class U, int Dim0, int Dim1, char i,
37  char j>
40  {
41  using TensorExpr
42  = Tensor2_times_Tensor1_single<A, B, T, U, Dim0, Dim1, Dim1, i, j, j,
43  Dim0, Dim1, i, j>;
45  TensorExpr(a, b));
46  }
47 
48  // B(j)*A(i,j)
49  template <class A, class B, class T, class U, int Dim0, int Dim1, char i,
50  char j>
53  {
54  return a * b;
55  }
56 
57  // A(i,j)*B(i)
58  template <class A, class B, class T, class U, int Dim0, int Dim1, char i,
59  char j>
62  {
63  using TensorExpr
64  = Tensor2_times_Tensor1_single<A, B, T, U, Dim0, Dim1, Dim0, i, j, i,
65  Dim1, Dim0, j, i>;
67  TensorExpr(a, b));
68  }
69 
70  // B(i)*A(i,j)
71  template <class A, class B, class T, class U, int Dim0, int Dim1, char i,
72  char j>
75  {
76  return a * b;
77  }
78 
79  /* A(i,j)*B(k) -> Tensor3 */
80 
81  template <class A, class B, class T, class U, int Dim0, int Dim1, int Dim2,
82  char i, char j, char k>
84  {
87 
88  public:
91  : iterA(a), iterB(b)
92  {}
93  typename promote<T, U>::V
94  operator()(const int N1, const int N2, const int N3) const
95  {
96  return iterA(N1, N2) * iterB(N3);
97  }
98  };
99 
100  template <class A, class B, class T, class U, int Dim0, int Dim1, int Dim2,
101  char i, char j, char k>
102  Tensor3_Expr<Tensor2_times_Tensor1<A, B, T, U, Dim0, Dim1, Dim2, i, j, k>,
103  typename promote<T, U>::V, Dim0, Dim1, Dim2, i, j, k>
106  {
107  using TensorExpr
110  Dim2, i, j, k>(TensorExpr(a, b));
111  }
112 
113  /* B(k)*A(i,j) -> Tensor3 */
114 
115  template <class A, class B, class T, class U, int Dim0, int Dim1, int Dim2,
116  char i, char j, char k>
117  Tensor3_Expr<Tensor2_times_Tensor1<A, B, T, U, Dim0, Dim1, Dim2, i, j, k>,
118  typename promote<T, U>::V, Dim0, Dim1, Dim2, i, j, k>
121  {
122  using TensorExpr
125  Dim2, i, j, k>(TensorExpr(a, b));
126  }
127 }
FTensor::Tensor2_times_Tensor1::iterB
const Tensor1_Expr< B, U, Dim2, k > iterB
Definition: Tensor2_times_Tensor1.hpp:86
FTensor::Permutation2::eval
U eval(const Tensor2_Expr< B, U, Dim0, Dim1, i, j > &rhs, const int N0, const int N1)
Definition: Permutation2.hpp:12
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::operator*
promote< T, U >::V operator*(const Ddg_Expr< A, T, Dim, Dim, i, j, k, l > &a, const Ddg_Expr< B, U, Dim, Dim, i, k, j, l > &b)
Definition: Ddg_times_Ddg.hpp:79
FTensor::Tensor2_times_Tensor1::iterA
const Tensor2_Expr< A, T, Dim0, Dim1, i, j > iterA
Definition: Tensor2_times_Tensor1.hpp:85
FTensor::Tensor2_Expr
Definition: Tensor2_Expr.hpp:26
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
FTensor::Tensor2_times_Tensor1::Tensor2_times_Tensor1
Tensor2_times_Tensor1(const Tensor2_Expr< A, T, Dim0, Dim1, i, j > &a, const Tensor1_Expr< B, U, Dim2, k > &b)
Definition: Tensor2_times_Tensor1.hpp:89
FTensor::Tensor1_Expr< B, U, Dim2, k >
a
constexpr double a
Definition: approx_sphere.cpp:30
FTensor::Tensor2_times_Tensor1_single::operator()
promote< T, U >::V operator()(const int N1) const
Definition: Tensor2_times_Tensor1.hpp:23
FTensor::promote::V
T1 V
Definition: promote.hpp:17
FTensor::Tensor3_Expr
Definition: Tensor3_Expr.hpp:24
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Tensor2_times_Tensor1
Definition: Tensor2_times_Tensor1.hpp:83
FTensor::Tensor2_times_Tensor1_single::iterB
const Tensor1_Expr< B, U, Dim2, k > iterB
Definition: Tensor2_times_Tensor1.hpp:16
FTensor::Tensor2_times_Tensor1_single::Tensor2_times_Tensor1_single
Tensor2_times_Tensor1_single(const Tensor2_Expr< A, T, Dim0, Dim1, i, j > &iter_a, const Tensor1_Expr< B, U, Dim2, k > &iter_b)
Definition: Tensor2_times_Tensor1.hpp:19
FTensor::Tensor2_times_Tensor1_single::iterA
const Tensor2_Expr< A, T, Dim0, Dim1, i, j > iterA
Definition: Tensor2_times_Tensor1.hpp:15
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
FTensor::Tensor2_times_Tensor1_single
Definition: Tensor2_times_Tensor1.hpp:13
FTensor::Permutation2
Definition: Permutation2.hpp:7
FTensor::Tensor2_times_Tensor1::operator()
promote< T, U >::V operator()(const int N1, const int N2, const int N3) const
Definition: Tensor2_times_Tensor1.hpp:94
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
EshelbianPlasticity::U
@ U
Definition: EshelbianContact.cpp:197