v0.16.0
Loading...
Searching...
No Matches
One.hpp
Go to the documentation of this file.
1/**
2 * @file One.hpp
3 * @brief Constant Tensor1 expression with all components equal to one.
4 */
5
6#pragma once
7
8namespace FTensor {
9
10/**
11 * @brief Stateless vector whose components are all equal to one.
12 *
13 * Contracting this expression with a Tensor1 sums its components:
14 * @code
15 * Index<'i', 3> i;
16 * One<> t_one;
17 * const auto sum = t_v(i) * t_one(i);
18 * @endcode
19 *
20 * @tparam T Component type
21 */
22template <class T = int> class One {
23public:
24 constexpr T operator()(const int) const { return T(1); }
25
26 template <char i, int Dim>
27 Tensor1_Expr<One<T>, T, Dim, i>
28 operator()(const Index<i, Dim> &) const {
29 return Tensor1_Expr<One<T>, T, Dim, i>(*this);
30 }
31};
32
33} // namespace FTensor
Stateless vector whose components are all equal to one.
Definition One.hpp:22
Tensor1_Expr< One< T >, T, Dim, i > operator()(const Index< i, Dim > &) const
Definition One.hpp:28
constexpr T operator()(const int) const
Definition One.hpp:24
FTensor::Index< 'i', SPACE_DIM > i
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51