10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_IO_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_IO_H 18 template <
typename Tensor,
int Rank>
19 struct TensorPrinter {
20 static void run (std::ostream& os,
const Tensor& tensor) {
21 typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
22 typedef typename Tensor::Index
Index;
23 const Index total_size = internal::array_prod(tensor.dimensions());
25 const Index first_dim = Eigen::internal::array_get<0>(tensor.dimensions());
26 static const int layout = Tensor::Layout;
27 Map<const Array<Scalar, Dynamic, Dynamic, layout> > matrix(const_cast<Scalar*>(tensor.data()), first_dim, total_size/first_dim);
35 template <
typename Tensor>
36 struct TensorPrinter<Tensor, 1> {
37 static void run (std::ostream& os,
const Tensor& tensor) {
38 typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
39 typedef typename Tensor::Index
Index;
40 const Index total_size = internal::array_prod(tensor.dimensions());
42 Map<const Array<Scalar, Dynamic, 1> > array(const_cast<Scalar*>(tensor.data()), total_size);
50 template <
typename Tensor>
51 struct TensorPrinter<Tensor, 0> {
52 static void run (std::ostream& os,
const Tensor& tensor) {
53 os << tensor.coeff(0);
59 std::ostream& operator << (std::ostream& os, const TensorBase<T, ReadOnlyAccessors>& expr) {
60 typedef TensorEvaluator<const TensorForcedEvalOp<const T>, DefaultDevice> Evaluator;
61 typedef typename Evaluator::Dimensions Dimensions;
64 TensorForcedEvalOp<const T> eval = expr.eval();
65 Evaluator tensor(eval, DefaultDevice());
66 tensor.evalSubExprsIfNeeded(NULL);
69 static const int rank = internal::array_size<Dimensions>::value;
70 internal::TensorPrinter<Evaluator, rank>::run(os, tensor);
79 #endif // EIGEN_CXX11_TENSOR_TENSOR_IO_H Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index