TensorInitializer.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H
12 
13 #include <initializer_list>
14 
15 // IWYU pragma: private
16 #include "./InternalHeaderCheck.h"
17 
18 namespace Eigen {
19 
25 namespace internal {
26 
27 template <typename Derived, int N>
28 struct Initializer {
29  typedef std::initializer_list<typename Initializer<Derived, N - 1>::InitList> InitList;
30 
33  const InitList& vals) {
34  int i = 0;
35  for (const auto& v : vals) {
36  (*indices)[traits<Derived>::NumDimensions - N] = i++;
37  Initializer<Derived, N - 1>::run(tensor, indices, v);
38  }
39  }
40 };
41 
42 template <typename Derived>
43 struct Initializer<Derived, 1> {
45 
48  const InitList& vals) {
49  int i = 0;
50  // There is likely a faster way to do that than iterating.
51  for (const auto& v : vals) {
52  (*indices)[traits<Derived>::NumDimensions - 1] = i++;
53  tensor.coeffRef(*indices) = v;
54  }
55  }
56 };
57 
58 template <typename Derived>
59 struct Initializer<Derived, 0> {
61 
64  tensor.coeffRef(0) = v;
65  }
66 };
67 
68 template <typename Derived, int N>
70  const typename Initializer<Derived, traits<Derived>::NumDimensions>::InitList& vals) {
73 }
74 
75 } // namespace internal
76 } // namespace Eigen
77 
78 #endif // EIGEN_CXX11_TENSOR_TENSOR_INITIALIZER_H
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
SCALAR Scalar
Definition: bench_gemm.cpp:45
@ N
Definition: constructor.cpp:22
void initialize_tensor(TensorEvaluator< Derived, DefaultDevice > &tensor, const typename Initializer< Derived, traits< Derived >::NumDimensions >::InitList &vals)
Definition: TensorInitializer.h:69
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
std::array< T, N > array
Definition: EmulateArray.h:231
Definition: Eigen_Colamd.h:49
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:31
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index) const
Definition: TensorEvaluator.h:94
static void run(TensorEvaluator< Derived, DefaultDevice > &tensor, Eigen::array< typename traits< Derived >::Index, traits< Derived >::NumDimensions > *, const InitList &v)
Definition: TensorInitializer.h:62
traits< Derived >::Scalar InitList
Definition: TensorInitializer.h:60
std::initializer_list< typename traits< Derived >::Scalar > InitList
Definition: TensorInitializer.h:44
static void run(TensorEvaluator< Derived, DefaultDevice > &tensor, Eigen::array< typename traits< Derived >::Index, traits< Derived >::NumDimensions > *indices, const InitList &vals)
Definition: TensorInitializer.h:46
Definition: TensorInitializer.h:28
std::initializer_list< typename Initializer< Derived, N - 1 >::InitList > InitList
Definition: TensorInitializer.h:29
static void run(TensorEvaluator< Derived, DefaultDevice > &tensor, Eigen::array< typename traits< Derived >::Index, traits< Derived >::NumDimensions > *indices, const InitList &vals)
Definition: TensorInitializer.h:31
Definition: ForwardDeclarations.h:21