Tatooine
tensor_io.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_IO_H
2#define TATOOINE_TENSOR_IO_H
3//==============================================================================
4#include <tatooine/tensor.h>
5#include <ostream>
6//==============================================================================
7namespace tatooine {
8//==============================================================================
10template <typename Tensor, typename T, size_t N>
11auto operator<<(std::ostream& out, const base_tensor<Tensor, T, N>& v)
12 -> auto& {
13 out << "[ ";
14 out << std::scientific;
15 for (size_t i = 0; i < N; ++i) {
16 if constexpr (!is_complex<T>) {}
17 out << v(i) << ' ';
18 }
19 out << "]";
20 out << std::defaultfloat;
21 return out;
22}
23//------------------------------------------------------------------------------
24template <typename Tensor, typename T, size_t M, size_t N>
25auto operator<<(std::ostream& out, const base_tensor<Tensor, T, M, N>& m)
26 -> auto& {
27 out << std::scientific;
28 for (size_t j = 0; j < M; ++j) {
29 out << "[ ";
30 for (size_t i = 0; i < N; ++i) {
31 if constexpr (!is_complex<T>) {
32 if (m(j, i) >= 0) { out << ' '; }
33 }
34 out << m(j, i) << ' ';
35 }
36 out << "]\n";
37 }
38 out << std::defaultfloat;
39 return out;
40}
41//==============================================================================
43auto operator<<(std::ostream& out, dynamic_tensor auto const& t) -> auto& {
44 if (t.rank() == 1) {
45 out << "[ ";
46 out << std::scientific;
47 for (size_t i = 0; i < t.dimension(0); ++i) {
48 if constexpr (!is_complex<tatooine::value_type<decltype(t)>>) {
49 out << t(i) << ' ';
50 }
51 }
52 out << "]";
53 out << std::defaultfloat;
54 } else if (t.rank() == 2) {
55 out << std::scientific;
56 for (size_t r = 0; r < t.dimension(0); ++r) {
57 out << "[ ";
58 for (size_t c = 0; c < t.dimension(1); ++c) {
59 if constexpr (!is_complex<tatooine::value_type<decltype(t)>>) {
60 if (t(r, c) >= 0) {
61 out << ' ';
62 }
63 }
64 out << t(r, c) << ' ';
65 }
66 out << "]\n";
67 }
68 out << std::defaultfloat;
69 }
70 return out;
71}
72//==============================================================================
73} // namespace tatooine
74//==============================================================================
75#endif
Definition: tensor_concepts.h:17
Definition: algorithm.h:6
auto operator<<(std::ostream &out, linspace< Real > const &l) -> auto &
Definition: linspace.h:165
typename value_type_impl< T >::type value_type
Definition: type_traits.h:280
static constexpr auto is_complex
Definition: type_traits.h:126
Definition: base_tensor.h:23