|
| | Tensor (std::vector< std::size_t > dims) |
| | Construct a new Tensor object.
|
| |
| | Tensor (const T &value, std::vector< std::size_t > dims) |
| | Construct a new Tensor object.
|
| |
| | Tensor (std::vector< T > data, std::vector< std::size_t > dims={}) |
| | Construct a new Tensor object.
|
| |
| Tensor & | reshape (std::vector< std::size_t > dims) |
| | Reshape the tensor to the new dimensions.
|
| |
| template<IsAnyOf< int, float, double, std::complex< double > > TT = T> |
| Tensor< TT > | permute (const std::vector< std::size_t > &permutation) const |
| | Permute the axes of the tensor.
|
| |
| template<IsAnyOf< int, float, double, std::complex< double > > TT = T, std::convertible_to< const std::size_t > I, class... Is> |
| Tensor< TT > | permute (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, class 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::vector< T > & | data () const |
| | Get read-only access to the data of the tensor.
|
| |
| const TensorView< T > & | view () const |
| | Get read-only access to the view of the tensor.
|
| |
| TensorView< T > & | m_view () |
| | Get read-write access to the view of the tensor.
|
| |
| std::vector< T > & | m_data () |
| | Get read-write 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.
|
| |
| Tensor< T > | pad (const std::vector< std::pair< Index, Index > > &padding, const T &value={}) const |
| | Pad the tensor with a value.
|
| |
| Tensor< T > | pad (const std::vector< Index > &padding, const std::vector< Index > &start_padding={}, const T &value={}) const |
| | Pad the tensor with a value.
|
| |
| Tensor< std::complex< double > > | fft (double coeff=std::numeric_limits< double >::quiet_NaN()) const |
| | Apply the Fast Fourier Transform to the tensor.
|
| |
| Tensor< double > | ifft (double coeff=std::numeric_limits< double >::quiet_NaN()) const |
| | Apply the Inverse Fast Fourier Transform to the tensor.
|
| |
| Tensor< double > | fft_upsample (const std::vector< std::size_t > &new_dims) const |
| | Use the Fast Fourier Transform to upsample the tensor.
|
| |
template<IsAnyOf< int, float, double, std::complex< double > > T>
class lucid::Tensor< T >
Lightweight tensor class.
It uses a strided vector to support any number of dimensions.
- Note
- Most methods in this class are implemented by the TensorView class. Its direct use is discouraged unless you can ensure proper memory management.
- Template Parameters
-
| T | type of the elements in the tensor |
template<IsAnyOf< int, float, double, std::complex< double > > T>
template<IsAnyOf< int, float, double, std::complex< double > > TT = T>
| Tensor< TT > lucid::Tensor< T >::permute |
( |
const std::vector< std::size_t > & | permutation | ) |
const |
|
inlinenodiscard |
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.
Tensor<int> t{std::vector<int>{1, 2, 3, 4, 5, 6}, std::vector<std::size_t>{2, 3}};
t.permute(std::vector<std::size_t>{0, 1});
- Precondition
- All values in
permutation must be in the range [0, rank() - 1]
- Parameters
-
| permutation | permutation of the axes |
- Returns
- reference to this object
template<IsAnyOf< int, float, double, std::complex< double > > T>
template<IsAnyOf< int, float, double, std::complex< double > > TT = T, std::convertible_to< const std::size_t > I, class... Is>
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.
Tensor<int> t{std::vector<int>{1, 2, 3, 4, 5, 6}, std::vector<std::size_t>{2, 3}};
t.permute(0, 1);
- Precondition
- All values in
permutation must be in the range [0, rank() - 1]
- Template Parameters
-
| I | axis to put in the first dimension type |
| Is | varadic remaining permuted axis types |
- Parameters
-
| i | axis to put in the first dimension |
| is | remaining permuted axes |
- Returns
- reference to this object