lin
stream_transpose.hpp
Go to the documentation of this file.
1 // vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab
2 
7 #ifndef LIN_CORE_OPERATIONS_STREAM_TRANSPOSE_HPP_
8 #define LIN_CORE_OPERATIONS_STREAM_TRANSPOSE_HPP_
9 
10 namespace lin {
11 namespace internal {
12 
21 template <class C>
22 class StreamTranspose : public Stream<StreamTranspose<C>> {
23  private:
26  Stream<C> const &c;
27 
28  public:
34 
35  protected:
37 
38  public:
41 
42  constexpr StreamTranspose() = delete;
43  constexpr StreamTranspose(StreamTranspose<C> const &) = default;
44  constexpr StreamTranspose(StreamTranspose<C> &&) = default;
45  constexpr StreamTranspose<C> &operator=(StreamTranspose<C> const &) = default;
46  constexpr StreamTranspose<C> &operator=(StreamTranspose<C> &&) = default;
47 
52  constexpr StreamTranspose(Stream<C> const &c)
53  : c(c) { }
54 
57  constexpr size_t rows() const {
58  return c.cols();
59  }
60 
63  constexpr size_t cols() const {
64  return c.rows();
65  }
66 
76  constexpr typename Traits::elem_t operator()(size_t i, size_t j) const {
77  return c(j, i);
78  }
79 
91  constexpr typename Traits::elem_t operator()(size_t i) const {
92  return (*this)(i / cols(), i % cols());
93  }
94 };
95 
96 template <class C>
97 struct _elem<StreamTranspose<C>> : _elem<C> { };
98 
99 template <class C>
100 struct _dims<StreamTranspose<C>> {
101  static constexpr size_t rows = _dims<C>::cols;
102  static constexpr size_t cols = _dims<C>::rows;
103  static constexpr size_t max_rows = _dims<C>::max_cols;
104  static constexpr size_t max_cols = _dims<C>::max_rows;
105 };
106 } // namespace internal
107 } // namespace lin
108 
109 #endif
Tensor interface providing read only access to elements.
Definition: stream.hpp:43
constexpr size_t size() const
Definition: stream.hpp:90
traits< StreamTranspose< C > > Traits
Traits information for this type.
Definition: stream_transpose.hpp:33
Provides a tensor type&#39;s element type.
Definition: tensor.hpp:28
Collection of compile time information about a specific tensor class.
Definition: tensor.hpp:75
constexpr StreamTranspose< C > & derived()
Definition: stream.hpp:57
constexpr StreamTranspose(Stream< C > const &c)
Constructs a proxy to a tensor transpose operation.
Definition: stream_transpose.hpp:52
constexpr Traits::elem_t operator()(size_t i, size_t j) const
Lazily evaluates the requested tensor element.
Definition: stream_transpose.hpp:76
constexpr size_t rows() const
Definition: stream.hpp:76
constexpr size_t cols() const
Definition: stream_transpose.hpp:63
constexpr size_t cols() const
Definition: stream.hpp:82
_elem_t< C > elem_t
Tensor&#39;s element type.
Definition: tensor.hpp:81
Definition: config.hpp:27
Proxy to a lazily evalutated transpose operation.
Definition: stream_transpose.hpp:22
constexpr Traits::elem_t operator()(size_t i) const
Lazily evaluates the requested tensor element.
Definition: stream_transpose.hpp:91
Stream< C > const & c
Stream reference.
Definition: stream_transpose.hpp:26
constexpr size_t rows() const
Definition: stream_transpose.hpp:57
Provides a specific tensor type&#39;s compile time dimensions.
Definition: tensor.hpp:60
constexpr Traits::eval_t eval() const
Forces evaluation of this stream to a value backed type.
Definition: stream.hpp:157