lin
|
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... | |
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:
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:
M
) goes out of scope.const
or read only.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:
constexpr auto lin::ref | ( | internal::Mapping< D > & | mapping, |
size_t | i, | ||
size_t | j | ||
) |
Creates a mapping reference with default dimensions.
C | Tensor type whose traits are replicated. |
D | Underlying referenced type. |
mapping | Underlying mapping. |
i | Anchor point row index. |
j | Anchor point column index. |
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.
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.
C | Vector type whose traits are replicated. |
D | Underlying referenced type. |
mapping | Underlying mapping. |
i | Anchor point row index. |
j | Anchor point column index. |
n | Provided length. |
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.
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.
C | Tensor type whose traits are replicated. |
D | Underlying referenced type. |
mapping | Underlying mapping. |
i | Anchor point row index. |
j | Anchor point column index. |
r | Provided row dimension. |
c | Provided column dimension. |
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.
constexpr auto lin::col | ( | internal::Mapping< D > & | mapping, |
size_t | j | ||
) |
Creates a mapping reference of a particular column of a given tensor.
D | Underlying referened type. |
mapping | Underlying mapping. |
j | Index of the referenced column. |
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.
constexpr auto lin::row | ( | internal::Mapping< D > & | mapping, |
size_t | i | ||
) |
Creates a mapping reference of a particular row of a given tensor.
D | Underlying referened type. |
mapping | Underlying mapping. |
j | Index of the referenced row. |
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.
constexpr auto lin::diag | ( | internal::Mapping< D > & | mapping | ) |
Creates a diagonal mapping reference from the given mapping.
D | Underlying referenced type. |
mapping | Underlying mapping. |
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.
constexpr auto lin::ref | ( | internal::Stream< D > const & | stream, |
size_t | i, | ||
size_t | j | ||
) |
Creates a mapping stream with default dimensions.
C | Tensor type whose traits are replicated. |
D | Underlying referenced type. |
stream | Underlying stream. |
i | Anchor point row index. |
j | Anchor point column index. |
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.
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.
C | Vector type whose traits are replicated. |
D | Underlying referenced type. |
stream | Underlying stream. |
i | Anchor point row index. |
j | Anchor point column index. |
n | Provided length. |
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.
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.
C | Tensor type whose traits are replicated. |
D | Underlying referenced type. |
stream | Underlying stream. |
i | Anchor point row index. |
j | Anchor point column index. |
r | Provided row dimension. |
c | Provided column dimension. |
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.
constexpr auto lin::col | ( | internal::Stream< D > const & | stream, |
size_t | j | ||
) |
Creates a stream reference of a particular column of a given tensor.
D | Underlying referened type. |
stream | Underlying stream. |
j | Index of the referenced column. |
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.
constexpr auto lin::row | ( | internal::Stream< D > const & | stream, |
size_t | i | ||
) |
Creates a stream reference of a particular row of a given tensor.
D | Underlying referened type. |
stream | Underlying stream. |
j | Index of the referenced row. |
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.
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.
D | Underlying referenced type. |
stream | Underlying stream. |
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.
D | Underlying type. |
stream | Underlying vector stream. |