TR-mbed 1.0
Loading...
Searching...
No Matches
TensorIO.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_IO_H
11#define EIGEN_CXX11_TENSOR_TENSOR_IO_H
12
13namespace Eigen {
14
15namespace internal {
16
17// Print the tensor as a 2d matrix
18template <typename Tensor, int Rank>
20 static void run (std::ostream& os, const Tensor& tensor) {
22 typedef typename Tensor::Index Index;
23 const Index total_size = internal::array_prod(tensor.dimensions());
24 if (total_size > 0) {
26 static const int layout = Tensor::Layout;
28 os << matrix;
29 }
30 }
31};
32
33
34// Print the tensor as a vector
35template <typename Tensor>
37 static void run (std::ostream& os, const Tensor& tensor) {
39 typedef typename Tensor::Index Index;
40 const Index total_size = internal::array_prod(tensor.dimensions());
41 if (total_size > 0) {
42 Map<const Array<Scalar, Dynamic, 1> > array(const_cast<Scalar*>(tensor.data()), total_size);
43 os << array;
44 }
45 }
46};
47
48
49// Print the tensor as a scalar
50template <typename Tensor>
52 static void run (std::ostream& os, const Tensor& tensor) {
53 os << tensor.coeff(0);
54 }
55};
56}
57
58template <typename T>
59std::ostream& operator << (std::ostream& os, const TensorBase<T, ReadOnlyAccessors>& expr) {
61 typedef typename Evaluator::Dimensions Dimensions;
62
63 // Evaluate the expression if needed
65 Evaluator tensor(eval, DefaultDevice());
66 tensor.evalSubExprsIfNeeded(NULL);
67
68 // Print the result
69 static const int rank = internal::array_size<Dimensions>::value;
71
72 // Cleanup.
73 tensor.cleanup();
74 return os;
75}
76
77} // end namespace Eigen
78
79#endif // EIGEN_CXX11_TENSOR_TENSOR_IO_H
SCALAR Scalar
Definition bench_gemm.cpp:46
The tensor base class.
Definition TensorBase.h:973
Definition TensorForcedEval.h:60
The tensor class.
Definition Tensor.h:64
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(const array< Index, NumIndices > &indices) const
Definition Tensor.h:124
@ Layout
Definition Tensor.h:77
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition Tensor.h:104
internal::traits< Self >::Index Index
Definition Tensor.h:70
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition Tensor.h:102
Definition EmulateArray.h:21
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition common.h:110
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition TensorDimensions.h:140
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
std::ostream & operator<<(std::ostream &os, const DSizes< IndexType, NumDims > &dims)
Definition TensorDimensions.h:387
Definition BandTriangularSolver.h:13
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition sparse_permutations.cpp:38
Definition TensorDeviceDefault.h:17
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition TensorEvaluator.h:29
static void run(std::ostream &os, const Tensor &tensor)
Definition TensorIO.h:52
static void run(std::ostream &os, const Tensor &tensor)
Definition TensorIO.h:37
Definition TensorIO.h:19
static void run(std::ostream &os, const Tensor &tensor)
Definition TensorIO.h:20
Definition Meta.h:445
Definition ForwardDeclarations.h:17