lin
Classes | Functions
References

Allows interpretting portions of larger tensor as other tensor types. More...

Classes

class  lin::internal::TensorMappingReference< D, E >
 Generic tensor reference with read and write access. More...
 
class  lin::internal::MatrixMappingReference< E, R, C, MR, MC >
 Generic matrix reference with read and write access. More...
 
class  lin::internal::VectorMappingReference< E, N, MN >
 Generic vector reference with read and write access. More...
 
class  lin::internal::RowVectorMappingReference< E, N, MN >
 Generic row vector reference with read and write access. More...
 
class  lin::internal::TensorStreamReference< D, E >
 Generic tensor reference with read only access. More...
 
class  lin::internal::MatrixStreamReference< E, R, C, MR, MC >
 Generic matrix reference with read-only access. More...
 
class  lin::internal::VectorStreamReference< E, N, MN >
 Generic vector reference with read only access. More...
 
class  lin::internal::RowVectorStreamReference< E, N, MN >
 Generic row vector reference with read only access. More...
 

Functions

template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref (internal::Mapping< D > &mapping, size_t i, size_t j)
 Creates a mapping reference with default dimensions. More...
 
template<class C , class D , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::ref (internal::Mapping< D > &mapping, size_t i, size_t j, size_t n)
 Creates a vector mapping reference with the provided length. More...
 
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref (internal::Mapping< D > &mapping, size_t i, size_t j, size_t r, size_t c)
 Creates a mapping reference with the provided dimensions. More...
 
template<class D >
constexpr auto lin::col (internal::Mapping< D > &mapping, size_t j)
 Creates a mapping reference of a particular column of a given tensor. More...
 
template<class D >
constexpr auto lin::row (internal::Mapping< D > &mapping, size_t i)
 Creates a mapping reference of a particular row of a given tensor. More...
 
template<class D , typename = std::enable_if_t<internal::conjunction< internal::is_matrix<D>, internal::is_square<D>>::value>>
constexpr auto lin::diag (internal::Mapping< D > &mapping)
 Creates a diagonal mapping reference from the given mapping. More...
 
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref (internal::Stream< D > const &stream, size_t i, size_t j)
 Creates a mapping stream with default dimensions. More...
 
template<class C , class D , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::ref (internal::Stream< D > const &stream, size_t i, size_t j, size_t n)
 Creates a vector stream reference with the provided length. More...
 
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref (internal::Stream< D > const &stream, size_t i, size_t j, size_t r, size_t c)
 Creates a stream reference with the provided dimensions. More...
 
template<class D >
constexpr auto lin::col (internal::Stream< D > const &stream, size_t j)
 Creates a stream reference of a particular column of a given tensor. More...
 
template<class D >
constexpr auto lin::row (internal::Stream< D > const &stream, size_t i)
 Creates a stream reference of a particular row of a given tensor. More...
 
template<class D , typename = std::enable_if_t<internal::conjunction< internal::is_matrix<D>, internal::is_square<D>>::value>>
constexpr auto lin::diag (internal::Stream< D > const &stream)
 Creates a diagonal stream reference from the given stream. More...
 

Detailed Description

Allows interpretting portions of larger tensor as other tensor types.

This can be extremely helpful if, for example, you'd like to normalize all the columns of a matrix without copying elements in and out of the matrix itself. We'll use this an example demonstrating how to use the refernces module.

First, be sure to include the appropriate headers (that being the lin/core.hpp and lin/references.hpp headers). From there, we can implement the following function which will normalize the columns in a three by three matrix:

#include <lin/core.hpp>
template <typename T>
void normalize(lin::Matrix<T, 3, 3> &M) {
for (lin::size_t j = 0; j < M.cols(); j++) {
auto m = lin::ref<lin::Vector<T, 3>>(M, 0, j);
m = m / lin::norm(m);
}
}

where line of interest here is clearly the call to lin::ref<lin::Vector<T, 3>> which essentially asks for a reference to be created that acts like a lin::Vector<T, 3> and whose first element matches up with M(0, j).

There are a couple things to note here:

Lastly, there are also convenience functions lin::col, lin::row, and lin::diag to more easily reference the entire column, row, or diagonal of a tensor. In fact, if you don't mind using the lin::internal namespace a little, a simple function normalizing the columns of any matrix can be implemented as shown below:

#include <lin/core.hpp>
#include <type_traits>
template <class D, typename = std::enable_if_t<lin::internal::disjunction<
void normalize(lin::internal::Mapping<D> &M) {
for (lin::size_t j = 0; j < M.cols(); j++) {
auto m = lin::col(M, j);
m = m / lin::norm(m);
}
}

Function Documentation

template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref ( internal::Mapping< D > &  mapping,
size_t  i,
size_t  j 
)

Creates a mapping reference with default dimensions.

Template Parameters
CTensor type whose traits are replicated.
DUnderlying referenced type.
Parameters
mappingUnderlying mapping.
iAnchor point row index.
jAnchor point column index.
Returns
Instace of an internal::MatrixMappingReference, internal::RowVectorMappingReference, or internal::VectorMappingReference

This serves essentially as a wrapper around the reference constructors using default dimensions.

The anchor points specifies where the top left corner of the reference maps to in the underlying mapping.

template<class C , class D , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::ref ( internal::Mapping< D > &  mapping,
size_t  i,
size_t  j,
size_t  n 
)

Creates a vector mapping reference with the provided length.

Template Parameters
CVector type whose traits are replicated.
DUnderlying referenced type.
Parameters
mappingUnderlying mapping.
iAnchor point row index.
jAnchor point column index.
nProvided length.
Returns
Instance of an internal::RowVectorMappingReference or internal::VectorMappingReference

This serves essentially as a wrapper around the vector reference constructors requesting a length.

The anchor points specifies where the top left corner of the reference maps to in the underlying mapping.

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

See also
internal::traits
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref ( internal::Mapping< D > &  mapping,
size_t  i,
size_t  j,
size_t  r,
size_t  c 
)

Creates a mapping reference with the provided dimensions.

Template Parameters
CTensor type whose traits are replicated.
DUnderlying referenced type.
Parameters
mappingUnderlying mapping.
iAnchor point row index.
jAnchor point column index.
rProvided row dimension.
cProvided column dimension.
Returns
Instance of an internal::MatrixMappingReference, internal::RowVectorMappingReference, or internal::VectorMappingReference

This serves essentially as a wrapper around the reference constructors using default dimensions.

The anchor points specifies where the top left corner of the reference maps to in the underlying mapping.

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

See also
internal::traits
template<class D >
constexpr auto lin::col ( internal::Mapping< D > &  mapping,
size_t  j 
)

Creates a mapping reference of a particular column of a given tensor.

Template Parameters
DUnderlying referened type.
Parameters
mappingUnderlying mapping.
jIndex of the referenced column.
Returns
Instance of an internal::VectorMappingReference or internal::MatrixMappingReference

This is a convenience function and the same result can be obtained with a call to another reference function.

The dimensions of a variably sized column are set depending on the provided mapping's row dimension at run time.

If calling this function on a mapping representing a row vector, a one by one matrix reference is returned.

template<class D >
constexpr auto lin::row ( internal::Mapping< D > &  mapping,
size_t  i 
)

Creates a mapping reference of a particular row of a given tensor.

Template Parameters
DUnderlying referened type.
Parameters
mappingUnderlying mapping.
jIndex of the referenced row.
Returns
Instance of an internal::RowVectorMappingReference or internal::MatrixMappingReference.

This is a convenience function and the same result can be obtained with a call to another reference function.

The dimensions of a variably sized row are set depending on the provided mapping's column dimension at run time.

If calling this function on a mapping representing a column vector, a one by one matrix reference is returned.

template<class D , typename = std::enable_if_t<internal::conjunction< internal::is_matrix<D>, internal::is_square<D>>::value>>
constexpr auto lin::diag ( internal::Mapping< D > &  mapping)

Creates a diagonal mapping reference from the given mapping.

Template Parameters
DUnderlying referenced type.
Parameters
mappingUnderlying mapping.
Returns
Instance of an internal::DiagonalMappingReference.

The underlying mapping must have the traits of a square matrix and lin assertion errors will be thrown if the underlying mapping isn't square at runtime.

See also
internal::is_matrix
internal::is_square
internal::traits
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref ( internal::Stream< D > const &  stream,
size_t  i,
size_t  j 
)

Creates a mapping stream with default dimensions.

Template Parameters
CTensor type whose traits are replicated.
DUnderlying referenced type.
Parameters
streamUnderlying stream.
iAnchor point row index.
jAnchor point column index.
Returns
Instace of an internal::MatrixStreamReference, internal::RowVectorStreamReference, or internal::VectorStreamReference

This serves essentially as a wrapper around the reference constructors using default dimensions.

The anchor points specifies where the top left corner of the reference maps to in the underlying stream.

template<class C , class D , typename = std::enable_if_t<internal::conjunction< internal::has_traits<C>, internal::is_vector<C>>::value>>
constexpr auto lin::ref ( internal::Stream< D > const &  stream,
size_t  i,
size_t  j,
size_t  n 
)

Creates a vector stream reference with the provided length.

Template Parameters
CVector type whose traits are replicated.
DUnderlying referenced type.
Parameters
streamUnderlying stream.
iAnchor point row index.
jAnchor point column index.
nProvided length.
Returns
Instance of an internal::RowVectorStreamReference or internal::VectorStreamReference

This serves essentially as a wrapper around the vector reference constructors requesting a length.

The anchor points specifies where the top left corner of the reference maps to in the underlying stream.

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

See also
internal::traits
template<class C , class D , typename = std::enable_if_t<internal::has_traits<C>::value>>
constexpr auto lin::ref ( internal::Stream< D > const &  stream,
size_t  i,
size_t  j,
size_t  r,
size_t  c 
)

Creates a stream reference with the provided dimensions.

Template Parameters
CTensor type whose traits are replicated.
DUnderlying referenced type.
Parameters
streamUnderlying stream.
iAnchor point row index.
jAnchor point column index.
rProvided row dimension.
cProvided column dimension.
Returns
Instance of an internal::MatrixStreamReference, internal::RowVectorStreamReference, or internal::VectorStreamReference

This serves essentially as a wrapper around the reference constructors using default dimensions.

The anchor points specifies where the top left corner of the reference maps to in the underlying mapping.

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

See also
internal::traits
template<class D >
constexpr auto lin::col ( internal::Stream< D > const &  stream,
size_t  j 
)

Creates a stream reference of a particular column of a given tensor.

Template Parameters
DUnderlying referened type.
Parameters
streamUnderlying stream.
jIndex of the referenced column.
Returns
Instance of an internal::VectorStreamReference or internal::MatrixStreamReference.

This is a convenience function and the same result can be obtained with a call to another reference function.

The dimensions of a variably sized column are set depending on the provided mapping's row dimension at run time.

If calling this function on a stream representing a row vector, a one by one matrix reference is returned.

template<class D >
constexpr auto lin::row ( internal::Stream< D > const &  stream,
size_t  i 
)

Creates a stream reference of a particular row of a given tensor.

Template Parameters
DUnderlying referened type.
Parameters
streamUnderlying stream.
jIndex of the referenced row.
Returns
Instance of an internal::RowVectorStreamReference or internal::MatrixStreamReference.

This is a convenience function and the same result can be obtained with a call to another reference function.

The dimensions of a variably sized row are set depending on the provided mapping's column dimension at run time.

If calling this function on a stream representing a column vector, a one by one matrix reference is returned.

template<class D , typename = std::enable_if_t<internal::conjunction< internal::is_matrix<D>, internal::is_square<D>>::value>>
constexpr auto lin::diag ( internal::Stream< D > const &  stream)

Creates a diagonal stream reference from the given stream.

Creates a diagonal stream from a vector stream.

Template Parameters
DUnderlying referenced type.
Parameters
streamUnderlying stream.
Returns
Instance of an internal::DiagonalMappingReference.

The underlying mapping must have the traits of a square matrix and lin assertion errors will be thrown if the underlying mapping isn't square at runtime.

See also
internal::is_matrix
internal::is_square
internal::traits
Template Parameters
DUnderlying type.
Parameters
streamUnderlying vector stream.
Returns
Instance of an internal::StreamDiagonal
See also
internal::is_vector