Allows arbitrary data buffers to be interpreted as value backed tensor types.
More...
|
class | lin::internal::TensorView< D > |
| Member pointer backed tensor. More...
|
|
class | lin::internal::MatrixView< T, R, C, MR, MC > |
| Generic matrix view. More...
|
|
class | lin::internal::VectorView< T, N, MN > |
| Generic vector view. More...
|
|
class | lin::internal::RowVectorView< T, N, MN > |
| Generic row vector view. More...
|
|
class | lin::internal::ConstTensorView< D > |
| Member pointer backed constant tensor. More...
|
|
class | lin::internal::ConstMatrixView< T, R, C, MR, MC > |
| Generic constant matrix view. More...
|
|
class | lin::internal::ConstVectorView< T, N, MN > |
| Generic constant vector view. More...
|
|
class | lin::internal::ConstRowVectorView< T, N, MN > |
| Generic constant row vector view. More...
|
|
|
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t *elems) |
| Creates a tensor view with default dimensions. More...
|
|
template<class C , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t *elems, size_t n) |
| Creates a vector view with the provided length. More...
|
|
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t *elems, size_t r, size_t c) |
| Creates a tensor view with the provided dimensions. More...
|
|
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t const *elems) |
| Creates a constant tensor view with default dimensions. More...
|
|
template<class C , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t const *elems, size_t n) |
| Creates a constant vector view with the provided length. More...
|
|
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>> |
constexpr auto | lin::view (typename C::Traits::elem_t const *elems, size_t r, size_t c) |
| Creates a constant tensor view with the provided dimensions. More...
|
|
Allows arbitrary data buffers to be interpreted as value backed tensor types.
Overview
The views module serves one main purpose: to allows external buffers to be interpretted as tensor objects within lin.
This can be extremely helpful, say for example, if you'd like to treat an array from the STL as a three dimensional vector and perform some operations in a function to mutate it. All that's required is to use the lin::view function to create a vector view and then leverage the rest of the lin library.
See the following example which treats an array as a three dimensional vector and rotates it in place about the z-axis by an angle alpha
:
#include <array>
#include <cmath>
void rotate_z(std::array<float, 3> &array, float alpha) {
auto v = lin::view<lin::Vector3f>(array.data());
std::cos(alpha), -std::sin(alpha), 0.0f,
std::sin(alpha), std::cos(alpha), 0.0f,
0.0f, 0.0f, 1.0f
};
v = (R * v).eval();
}
It's important to note that there are actually two types of views that can be returned by lin::view. The first is a standard view which allows read and write access to the underlying elements (this is seen in the example above). The second is known as a constant view and only allows read access to the underlying elements. This is done automatically if the buffer passed to lin::view points to const elements.
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t * |
elems | ) |
|
template<class C , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t * |
elems, |
|
|
size_t |
n |
|
) |
| |
Creates a vector view with the provided length.
- Template Parameters
-
C | Vector type whose traits are replicated. |
- Parameters
-
elems | Element backing array. |
n | Initial length. |
- Returns
- internal::RowVectorView or internal::VectorView.
Lin assertion errors will be triggered if the requested length isn't possible given the vector view's traits.
- See also
- internal::traits
-
internal::view
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t * |
elems, |
|
|
size_t |
r, |
|
|
size_t |
c |
|
) |
| |
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t const * |
elems | ) |
|
template<class C , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t const * |
elems, |
|
|
size_t |
n |
|
) |
| |
template<class C , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::view |
( |
typename C::Traits::elem_t const * |
elems, |
|
|
size_t |
r, |
|
|
size_t |
c |
|
) |
| |