|
|
lucid
0.0.1
Lifting-based Uncertain Control Invariant Dynamics
|
Lightweight wrapper that provides a view of a tensor. More...
#include <TensorView.h>
Public Member Functions | |
| TensorView (std::span< const T > data, std::vector< std::size_t > dims) | |
| Construct a new Tensor object. | |
| TensorView & | reshape (std::vector< std::size_t > dims) |
| Reshape the tensor to the new dimensions. | |
| template<IsAnyOf< int, float, double, std::complex< double > > TT> | |
| void | permute (TensorView< TT > &out, const std::vector< std::size_t > &permutation) const |
| Permute the axes of the tensor. | |
| template<IsAnyOf< int, float, double, std::complex< double > > TT, std::convertible_to< const std::size_t > I, class... Is> | |
| void | permute (TensorView< TT > &out, I i, Is... is) const |
| Permute the axes of the tensor. | |
| template<std::convertible_to< const std::size_t > I, class... Is> | |
| const T & | operator() (I i, Is... is) const |
| Get the element in the tensor using the indices in each dimension. | |
| template<std::convertible_to< const std::size_t > I, class... Is> | |
| T & | operator() (I i, Is... is) |
| Get the element in the tensor using the indices in each dimension. | |
| template<template< class... > class Container, std::convertible_to< const std::size_t > I> | |
| const T & | operator() (const Container< I > &indices) const |
| Get the element in the tensor using the indices in each dimension. | |
| template<template< class... > class Container, std::convertible_to< const std::size_t > I> | |
| T & | operator() (const Container< I > &indices) |
| Get the element in the tensor using the indices in each dimension. | |
| template<std::convertible_to< const std::size_t > I> | |
| const T & | operator[] (I i) const |
| Get the element in the underlying data vector using its index. | |
| std::size_t | size () const |
| Get read-only access to the size of the tensor. | |
| std::size_t | rank () const |
| Get read-only access to the rank of the tensor. | |
| const std::vector< std::size_t > & | axes () const |
| Get read-only access to the axes of the tensor. | |
| const std::vector< std::size_t > & | dimensions () const |
| Get read-only access to the dimensions of the tensor. | |
| const std::span< const T > & | data () const |
| Get read-only access to the data of the tensor. | |
| std::span< T > | m_data () |
| Get read-only access to the data of the tensor. | |
| TensorIterator< T > | begin () const |
| Get read-only access to the iterator pointing at the beginning of the tensor. | |
| TensorIterator< T > | end () const |
| Get read-only access to the iterator pointing at the end of the tensor. | |
| void | fft (TensorView< std::complex< double > > &out, double coeff=std::numeric_limits< double >::quiet_NaN()) const |
| Apply the Fast Fourier Transform to the tensor. | |
| void | ifft (TensorView< double > &out, double coeff=std::numeric_limits< double >::quiet_NaN()) const |
| Apply the Inverse Fast Fourier Transform to the tensor. | |
| void | ifft (TensorView< std::complex< double > > &out, double coeff=std::numeric_limits< double >::quiet_NaN()) const |
| Apply the Inverse Fast Fourier Transform to the tensor. | |
| void | pad (TensorView< T > &out, const std::vector< std::pair< Index, Index > > &padding) const |
| Pad the tensor with a value. | |
| void | pad (TensorView< T > &out, const std::vector< Index > &padding, const std::vector< Index > &start_padding) const |
| Pad the tensor with a value. | |
| void | fft_upsample (TensorView< double > &out) const |
| Use the Fast Fourier Transform to upsample the tensor. | |
| template<IsAnyOf< int, float, double, std::complex< double > > TT> | |
| void | copy (TensorView< TT > &out) const |
| Copy the tensor to another tensor. | |
Private Member Functions | |
| template<int Dim, std::convertible_to< const std::size_t > I, class... Is> | |
| Index | index (I i, Is... is) const |
| Get the linear index of an element in the data vector using the indices in each dimension. | |
| template<std::convertible_to< const std::size_t > I> | |
| std::size_t | index (std::span< const I > indices) const |
| Get the linear index of an element in the data vector using the indices in each dimension. | |
Lightweight wrapper that provides a view of a tensor.
It uses a strided vector to support any number of dimensions.
| T | type of the elements in the tensor |
| lucid::TensorView< T >::TensorView | ( | std::span< const T > | data, |
| std::vector< std::size_t > | dims ) |
Construct a new Tensor object.
The rank of the tensor is determined by the size of the dimensions vector.
| data | data of the tensor |
| dims | shape of the tensor. Each element is the size of the corresponding dimension |
|
inlinenodiscard |
Get read-only access to the axes of the tensor.
|
nodiscard |
Get read-only access to the iterator pointing at the beginning of the tensor.
| template void lucid::TensorView< T >::copy | ( | TensorView< TT > & | out | ) | const |
Copy the tensor to another tensor.
This method also allows to cast the tensor to another type.
out tensor must have enough space to accommodate the data | out | permuted output tensor |
|
inlinenodiscard |
Get read-only access to the data of the tensor.
|
inlinenodiscard |
Get read-only access to the dimensions of the tensor.
|
nodiscard |
Get read-only access to the iterator pointing at the end of the tensor.
| void lucid::TensorView< T >::fft | ( | TensorView< std::complex< double > > & | out, |
| double | coeff = std::numeric_limits<double>::quiet_NaN() ) const |
Apply the Fast Fourier Transform to the tensor.
It is just the application of the FFT to each dimension of the tensor.
| [out] | out | tensor with the FFT applied to each dimension |
| coeff | coefficient applied to the FFT. If NaN, the default coefficient, 1.0, is used |
| void lucid::TensorView< T >::fft_upsample | ( | TensorView< double > & | out | ) | const |
Use the Fast Fourier Transform to upsample the tensor.
This procedure will interpolate the signal in the frequency domain and then apply the inverse FFT.
out tensor must have the same shape as the input tensor plus a non-negative padding | [out[ | out upsampled tensor |
| void lucid::TensorView< T >::ifft | ( | TensorView< double > & | out, |
| double | coeff = std::numeric_limits<double>::quiet_NaN() ) const |
Apply the Inverse Fast Fourier Transform to the tensor.
It is just the application of the IFFT to each dimension of the tensor.
| [out] | out | tensor with the IFFT applied to each dimension |
| coeff | coefficient applied to the FFT. If NaN, the default coefficient, 1.0 / size(), is used |
| void lucid::TensorView< T >::ifft | ( | TensorView< std::complex< double > > & | out, |
| double | coeff = std::numeric_limits<double>::quiet_NaN() ) const |
Apply the Inverse Fast Fourier Transform to the tensor.
It is just the application of the IFFT to each dimension of the tensor.
| [out] | out | tensor with the IFFT applied to each dimension |
| coeff | coefficient applied to the FFT. If NaN, the default coefficient, 1.0 / size(), is used |
|
inlinenodiscardprivate |
Get the linear index of an element in the data vector using the indices in each dimension.
| Dim | index of the current dimension |
| I | index type |
| Is | variadic index types |
| i | index in the current dimension |
| is | indices in the remaining dimensions |
|
inlinenodiscardprivate |
Get the linear index of an element in the data vector using the indices in each dimension.
| I | index type |
| indices | indices in each dimension |
|
inlinenodiscard |
Get read-only access to the data of the tensor.
|
inline |
Get the element in the tensor using the indices in each dimension.
| I | index type |
| indices | indices in each dimension |
|
inline |
Get the element in the tensor using the indices in each dimension.
| I | index type |
| indices | indices in each dimension |
|
inline |
Get the element in the tensor using the indices in each dimension.
| I | index type |
| Is | variadic index types |
| i | index in the first dimension |
| is | indices in the remaining dimensions |
|
inline |
Get the element in the tensor using the indices in each dimension.
| I | index type |
| Is | variadic index types |
| i | index in the first dimension |
| is | indices in the remaining dimensions |
|
inline |
Get the element in the underlying data vector using its index.
| I | index type |
| i | index in the data vector |
| void lucid::TensorView< T >::pad | ( | TensorView< T > & | out, |
| const std::vector< Index > & | padding, | ||
| const std::vector< Index > & | start_padding ) const |
Pad the tensor with a value.
The padding is applied to each dimension starting at the respective start_padding index. This allows the padding to be placed in the middle of the tensor.
start_padding to 0 (the size of that dimension) will place all the padding at the start (the end) of the dimension. out tensor must have the same shape as the input tensor plus padding | [out] | out | padded output tensor |
| padding | padding for each dimension | |
| start_padding | the index where the padding starts for each dimension |
| void lucid::TensorView< T >::pad | ( | TensorView< T > & | out, |
| const std::vector< std::pair< Index, Index > > & | padding ) const |
Pad the tensor with a value.
The padding is applied to each dimension, and it is specified by a pair of indices, one for the beginning and one for the end of the dimension.
out tensor must have the same shape as the input tensor plus padding | [out] | out | padded output tensor |
| padding | padding for each dimension |
| void lucid::TensorView< T >::permute | ( | TensorView< TT > & | out, |
| const std::vector< std::size_t > & | permutation ) const |
Permute the axes of the tensor.
Namely, the axes are rearranged according to the permutation vector. If an axis is not specified, it will be left unchanged.
permutation must be in the range [0, rank() - 1] | out | permuted output tensor |
| permutation | permutation of the axes |
|
inline |
Permute the axes of the tensor.
Namely, the axes are rearranged according to the permutation vector. If an axis is not specified, it will be left unchanged.
permutation must be in the range [0, rank() - 1] | out | permuted output tensor |
| I | axis to put in the first dimension type |
| Is | varadic remaining permuted axis types |
| i | axis to put in the first dimension |
| is | remaining permuted axes |
|
inlinenodiscard |
Get read-only access to the rank of the tensor.
| TensorView< T > & lucid::TensorView< T >::reshape | ( | std::vector< std::size_t > | dims | ) |
Reshape the tensor to the new dimensions.
| dims | new dimensions of the tensor |
|
inlinenodiscard |
Get read-only access to the size of the tensor.