lin
Classes | Functions
Views

Allows arbitrary data buffers to be interpreted as value backed tensor types. More...

Classes

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...
 

Functions

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...
 

Detailed Description

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 <lin/core.hpp>
#include <lin/views.hpp>
#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.

Function Documentation

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.

Template Parameters
CTensor type whose traits are replicated.
Parameters
elemsElement backing array.
Returns
internal::MatrixView, internal::RowVectorView, or internal::VectorView.

If the view's traits support variable dimensions, the view is constructed with the largest allowable dimensions (i.e. default dimensions).

See also
internal::traits
internal::view
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
CVector type whose traits are replicated.
Parameters
elemsElement backing array.
nInitial 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 
)

Creates a tensor view with the provided dimensions.

Template Parameters
CTensor type whose traits are replicated.
Parameters
elemsElement backing array.
rInitial row dimension.
cInitial column dimension.
Returns
internal::MatrixView, internal::RowVectorView, or internal::VectorView.

Lin assertions errors will be triggered if the requested dimensions aren't possible given the 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 const *  elems)

Creates a constant tensor view with default dimensions.

Template Parameters
CTensor type whose traits are replicated.
Parameters
elemsConstant element backing array.
Returns
internal::ConstMatrixView, internal::ConstRowVectorView, or internal::ConstVectorView.

If the view's traits support variable dimensions, the view is constructed with the largest allowable dimensions (i.e. default dimensions).

See also
internal::traits
internal::const_view
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.

Template Parameters
CVector type whose traits are replicated.
Parameters
elemsConstant element backing array.
nInitial length.
Returns
internal::ConstRowVectorView or internal::ConstVectorView.

Lin assertion errors will be triggered if the requested length isn't possible given the vector view's traits.

See also
internal::traits
internal::const_view
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.

Template Parameters
CTensor type whose traits are replicated.
Parameters
elemsConstant element backing array.
rInitial row dimension.
cInitial column dimension.
Returns
internal::ConstMatrixView, internal::ConstRowVectorView, or internal::ConstVectorView.

Lin assertions errors will be triggered if the requested dimensions aren't possible given the view's traits.

See also
internal::traits
internal::const_view