10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_IO_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_IO_H
18 struct TensorIOFormat;
21 template <
typename Tensor, std::
size_t rank,
typename Format,
typename EnableIf =
void>
25 template <
typename Derived_>
52 for (std::size_t
k = 1;
k <
prefix.size();
k++) {
82 :
Base({
", ",
",\n",
"\n"}, {
"",
"{"}, {
"",
"}"},
116 template <
typename T,
int Layout,
int rank,
typename Format>
119 template <
typename T,
int rank,
typename Format>
129 tensor.evalSubExprsIfNeeded(NULL);
141 template <
typename T,
int rank,
typename Format>
148 typedef typename T::Index IndexType;
149 std::array<IndexType, rank>
shuffle;
150 std::array<IndexType, rank> id;
151 std::iota(
id.begin(),
id.
end(), IndexType(0));
159 tensor.evalSubExprsIfNeeded(NULL);
171 template <
typename T,
typename Format>
181 tensor.evalSubExprsIfNeeded(NULL);
196 template <
typename Scalar,
typename Format,
typename EnableIf =
void>
198 static void run(std::ostream& stream,
const Scalar& scalar,
const Format&) { stream << scalar; }
201 template <
typename Scalar>
208 template <
typename Scalar>
215 template <
typename Tensor, std::
size_t rank,
typename Format,
typename EnableIf>
217 using Scalar = std::remove_const_t<typename Tensor::Scalar>;
219 static void run(std::ostream&
s,
const Tensor& tensor,
const Format& fmt) {
226 std::conditional_t<is_same<Scalar, std::complex<char>>
::value ||
230 std::complex<int>,
const Scalar&>>
235 std::streamsize explicit_precision;
237 explicit_precision = 0;
240 explicit_precision = 0;
245 explicit_precision = fmt.precision;
248 std::streamsize old_precision = 0;
249 if (explicit_precision) old_precision =
s.precision(explicit_precision);
255 for (IndexType
i = 0;
i < total_size;
i++) {
256 std::stringstream sstr;
259 width = std::max<IndexType>(width, IndexType(sstr.str().length()));
263 for (IndexType
i = 0;
i < total_size;
i++) {
264 std::array<bool, rank> is_at_end{};
265 std::array<bool, rank> is_at_begin{};
268 for (std::size_t
k = 0;
k < rank;
k++) {
270 std::multiplies<IndexType>())) ==
277 for (std::size_t
k = 0;
k < rank;
k++) {
279 std::multiplies<IndexType>())) ==
281 is_at_begin[
k] =
true;
286 bool is_at_begin_after_newline =
false;
287 for (std::size_t
k = 0;
k < rank;
k++) {
288 if (is_at_begin[
k]) {
289 std::size_t separator_index = (
k < fmt.separator.size()) ?
k : fmt.separator.size() - 1;
290 if (fmt.separator[separator_index].find(
'\n') != std::string::npos) {
291 is_at_begin_after_newline =
true;
296 bool is_at_end_before_newline =
false;
297 for (std::size_t
k = 0;
k < rank;
k++) {
299 std::size_t separator_index = (
k < fmt.separator.size()) ?
k : fmt.separator.size() - 1;
300 if (fmt.separator[separator_index].find(
'\n') != std::string::npos) {
301 is_at_end_before_newline =
true;
306 std::stringstream suffix, prefix, separator;
307 for (std::size_t
k = 0;
k < rank;
k++) {
308 std::size_t suffix_index = (
k < fmt.suffix.size()) ?
k : fmt.suffix.size() - 1;
310 suffix << fmt.suffix[suffix_index];
313 for (std::size_t
k = 0;
k < rank;
k++) {
314 std::size_t separator_index = (
k < fmt.separator.size()) ?
k : fmt.separator.size() - 1;
316 (!is_at_end_before_newline || fmt.separator[separator_index].find(
'\n') != std::string::npos)) {
317 separator << fmt.separator[separator_index];
320 for (std::size_t
k = 0;
k < rank;
k++) {
321 std::size_t spacer_index = (
k < fmt.spacer.size()) ?
k : fmt.spacer.size() - 1;
322 if (
i != 0 && is_at_begin_after_newline && (!is_at_begin[
k] ||
k == 0)) {
323 prefix << fmt.spacer[spacer_index];
326 for (
int k = rank - 1;
k >= 0;
k--) {
327 std::size_t prefix_index = (
static_cast<std::size_t
>(
k) < fmt.prefix.size()) ?
k : fmt.prefix.size() - 1;
328 if (is_at_begin[
k]) {
329 prefix << fmt.prefix[prefix_index];
335 std::stringstream sstr;
339 IndexType scalar_width = scalar_str.length();
340 if (width && scalar_width < width) {
342 for (IndexType
j = scalar_width;
j < width; ++
j) {
343 filler.push_back(fmt.fill);
349 if (
i < total_size - 1) {
350 s << separator.str();
354 if (explicit_precision)
s.precision(old_precision);
358 template <
typename Tensor, std::
size_t rank>
361 using Scalar = std::remove_const_t<typename Tensor::Scalar>;
368 if (total_size > 0) {
369 const IndexType first_dim = Eigen::internal::array_get<0>(tensor.
dimensions());
371 total_size / first_dim);
378 template <
typename Tensor,
typename Format>
380 static void run(std::ostream&
s,
const Tensor& tensor,
const Format& fmt) {
381 using Scalar = std::remove_const_t<typename Tensor::Scalar>;
383 std::streamsize explicit_precision;
385 explicit_precision = 0;
388 explicit_precision = 0;
393 explicit_precision = fmt.precision;
396 std::streamsize old_precision = 0;
397 if (explicit_precision) old_precision =
s.precision(explicit_precision);
401 if (explicit_precision)
s.precision(old_precision);
406 template <
typename T>
AnnoyingScalar imag(const AnnoyingScalar &)
Definition: AnnoyingScalar.h:132
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
SCALAR Scalar
Definition: bench_gemm.cpp:45
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
The tensor base class.
Definition: TensorBase.h:1026
Definition: TensorForcedEval.h:57
The tensor class.
Definition: Tensor.h:68
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: Tensor.h:100
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const
Definition: Tensor.h:112
static constexpr int Layout
Definition: Tensor.h:81
internal::traits< Self >::Index Index
Definition: Tensor.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:102
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
float real
Definition: datatypes.h:10
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE Packet2d shuffle(const Packet2d &m, const Packet2d &n, int mask)
Definition: LSX/PacketMath.h:150
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE auto array_prod(const array< T, N > &arr) -> decltype(array_reduce< product_op, T, N >(arr, static_cast< T >(1)))
Definition: MoreMeta.h:497
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
std::ostream & operator<<(std::ostream &s, const DiagonalBase< Derived > &m)
Definition: IO.h:227
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
@ StreamPrecision
Definition: IO.h:20
@ FullPrecision
Definition: IO.h:20
@ DontAlignCols
Definition: IO.h:19
Definition: Eigen_Colamd.h:49
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
t
Definition: plotPSD.py:36
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:217
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
Definition: TensorDeviceDefault.h:19
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:31
Definition: TensorIO.h:197
static void run(std::ostream &stream, const Scalar &scalar, const Format &)
Definition: TensorIO.h:198
Definition: TensorIO.h:216
std::remove_const_t< typename Tensor::Scalar > Scalar
Definition: TensorIO.h:217
static void run(std::ostream &s, const Tensor &tensor, const Format &fmt)
Definition: TensorIO.h:219
static int run()
Definition: IO.h:121
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2