lin
vector_view.hpp
Go to the documentation of this file.
1 // vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab
2 
7 #ifndef LIN_VIEWS_VECTOR_VIEW_HPP_
8 #define LIN_VIEWS_VECTOR_VIEW_HPP_
9 
10 #include "../core.hpp"
11 #include "tensor_view.hpp"
12 
13 namespace lin {
14 namespace internal {
15 
30 template <typename T, size_t N, size_t MN = N>
31 class VectorView : public TensorView<VectorView<T, N, MN>> {
32  static_assert(is_col_vector<VectorView<T, N, MN>>::value,
33  "Invalid VectorView<...> parameters");
34 
35  public:
41 
47 
48  protected:
50 
51  public:
59  using TensorView<VectorView<T, N, MN>>::operator=;
60  using TensorView<VectorView<T, N, MN>>::operator();
61 
62  constexpr VectorView() = delete;
63  constexpr VectorView(VectorView<T, N, MN> const &) = default;
64  constexpr VectorView(VectorView<T, N, MN> &&) = default;
65  constexpr VectorView<T, N, MN> &operator=(VectorView<T, N, MN> const &) = default;
66  constexpr VectorView<T, N, MN> &operator=(VectorView<T, N, MN> &&) = default;
67 
83  constexpr VectorView(typename Traits::elem_t *elems, size_t n)
84  : TensorView<VectorView<T, N, MN>>(elems, n, 1) { }
85 
96  constexpr void resize(size_t n) {
97  resize(n, 1);
98  }
99 };
100 
115 template <typename T, size_t N, size_t MN = N>
116 class RowVectorView : public TensorView<RowVectorView<T, N, MN>> {
117  static_assert(is_row_vector<RowVectorView<T, N, MN>>::value,
118  "Invalid RowVectorView<...> parameters");
119 
120  public:
126 
132 
133  protected:
135 
136  public:
144  using TensorView<RowVectorView<T, N, MN>>::operator=;
145  using TensorView<RowVectorView<T, N, MN>>::operator();
146 
147  constexpr RowVectorView() = default;
148  constexpr RowVectorView(RowVectorView<T, N, MN> const &) = default;
149  constexpr RowVectorView(RowVectorView<T, N, MN> &&) = default;
150  constexpr RowVectorView<T, N, MN> &operator=(RowVectorView<T, N, MN> const &) = default;
151  constexpr RowVectorView<T, N, MN> &operator=(RowVectorView<T, N, MN> &&) = default;
152 
168  constexpr RowVectorView(typename Traits::elem_t *elems, size_t n)
169  : TensorView<RowVectorView<T, N, MN>>(elems, 1, n) { }
170 
181  constexpr void resize(size_t n) {
182  resize(1, n);
183  }
184 };
185 
186 template <typename T, size_t N, size_t MN>
187 struct _elem<VectorView<T, N, MN>> {
188  typedef T type;
189 };
190 
191 template <typename T, size_t N, size_t MN>
192 struct _dims<VectorView<T, N, MN>> {
193  static constexpr size_t rows = N;
194  static constexpr size_t cols = 1;
195  static constexpr size_t max_rows = MN;
196  static constexpr size_t max_cols = 1;
197 };
198 
199 template <typename T, size_t N, size_t MN>
200 struct _elem<RowVectorView<T, N, MN>> {
201  typedef T type;
202 };
203 
204 template <typename T, size_t N, size_t MN>
205 struct _dims<RowVectorView<T, N, MN>> {
206  static constexpr size_t rows = 1;
207  static constexpr size_t cols = N;
208  static constexpr size_t max_rows = 1;
209  static constexpr size_t max_cols = MN;
210 };
211 } // namespace internal
212 } // namespace lin
213 
214 #endif
Collection of compile time information describing a tensor type which is deemed a vector...
Definition: vector.hpp:103
traits< RowVectorView< T, N, MN > > Traits
Traits information for this type.
Definition: vector_view.hpp:118
constexpr size_t size() const
Definition: stream.hpp:90
Generic vector view.
Definition: vector_view.hpp:31
Provides a tensor type&#39;s element type.
Definition: tensor.hpp:28
constexpr size_t cols() const
Definition: dimensions.hpp:60
Collection of compile time information about a specific tensor class.
Definition: tensor.hpp:75
constexpr VectorView< T, N, MN > & derived()
Definition: stream.hpp:57
constexpr size_t rows() const
Definition: dimensions.hpp:56
constexpr void resize(size_t n)
Resizes the row vector view&#39;s length.
Definition: vector_view.hpp:181
Member pointer backed tensor.
Definition: tensor_view.hpp:31
constexpr Traits::elem_t * data()
Retrives a pointer to the element backing array.
Definition: tensor_view.hpp:113
constexpr VectorView(typename Traits::elem_t *elems, size_t n)
Constructs a vector view with the provided backing array and requested length.
Definition: vector_view.hpp:83
Generic row vector view.
Definition: vector_view.hpp:116
traits< VectorView< T, N, MN > > Traits
Traits information for this type.
Definition: vector_view.hpp:33
vector_traits< RowVectorView< T, N, MN > > VectorTraits
Vector traits information for this type.
Definition: vector_view.hpp:131
Tests if a tensor type is a column vector.
Definition: vector.hpp:54
vector_traits< VectorView< T, N, MN > > VectorTraits
Vector traits information for this type.
Definition: vector_view.hpp:46
_elem_t< C > elem_t
Tensor&#39;s element type.
Definition: tensor.hpp:81
constexpr void resize(size_t n)
Resizes the vector view&#39;s length.
Definition: vector_view.hpp:96
Definition: config.hpp:27
Tests if a tensor type is a row vector.
Definition: vector.hpp:33
constexpr RowVectorView(typename Traits::elem_t *elems, size_t n)
Constructs a vector view with the provided backing array and requested length.
Definition: vector_view.hpp:168
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