LCS::Tensor< T, Dim > Class Template Reference

Class for tensors. More...

#include <basic.hpp>

Public Member Functions

 Tensor (unsigned nx, unsigned ny)
 
void operator= (const Tensor< T, Dim > &t)
 
T & operator() (unsigned i, unsigned j)
 
operator() (unsigned i, unsigned j) const
 
T & Get (unsigned i, unsigned j)
 
Get (unsigned i, unsigned j) const
 
GetValue (unsigned i, unsigned j) const
 
auto & GetAll () const
 
auto GetNearby (const unsigned i, const unsigned j) const
 
void SetValue (unsigned i, unsigned j, T value)
 
void SetAll (std::vector< T > &data)
 
auto Size () const
 

Detailed Description

template<typename T, unsigned Dim = 2>
class LCS::Tensor< T, Dim >

Class for tensors.

This class is used for representing tensors (matrices) in a 1D vector.

Template Parameters
TData type of each element in the tensor.
DimDimension of the tensor.

Constructor & Destructor Documentation

template<typename T, unsigned Dim = 2>
LCS::Tensor< T, Dim >::Tensor ( unsigned  nx,
unsigned  ny 
)
inline

Constructor for initializing the tensor.

Parameters
nxThe number of grid points in $x$-direction.
nyThe number of grid points in $y$-direction.

Member Function Documentation

template<typename T, unsigned Dim = 2>
T& LCS::Tensor< T, Dim >::Get ( unsigned  i,
unsigned  j 
)
inline

Get one element reference of the tensor.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
Returns
Reference of the element at the given location.
template<typename T, unsigned Dim = 2>
T LCS::Tensor< T, Dim >::Get ( unsigned  i,
unsigned  j 
) const
inline

Get one element of the tensor.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
Returns
The element at the given location.
template<typename T, unsigned Dim = 2>
auto& LCS::Tensor< T, Dim >::GetAll ( ) const
inline

Get all elements of the tensor in STL vector format

Returns
STL vector that contains raw data of the tensor
template<typename T, unsigned Dim = 2>
auto LCS::Tensor< T, Dim >::GetNearby ( const unsigned  i,
const unsigned  j 
) const
inline

Obtain nearby points of a given point

Parameters
iIndex of the given point in $x$-coordinate.
jIndex of the given point in $y$-coordinate.
Returns
Tuple that contains the $x$- and $y$-coordinates of the nearby points.
template<typename T, unsigned Dim = 2>
T LCS::Tensor< T, Dim >::GetValue ( unsigned  i,
unsigned  j 
) const
inline

An another implementation of getting one tensor element. The Get() function does not work well sometimes, perhaps due to the overloading.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
Returns
The element at the given location.
template<typename T, unsigned Dim = 2>
T& LCS::Tensor< T, Dim >::operator() ( unsigned  i,
unsigned  j 
)
inline

Get one element reference of the tensor using the () operator.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
Returns
Reference of the element at the given location.
template<typename T, unsigned Dim = 2>
T LCS::Tensor< T, Dim >::operator() ( unsigned  i,
unsigned  j 
) const
inline

Get one element of the tensor using the () operator.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
Returns
The element at the given location.
template<typename T, unsigned Dim = 2>
void LCS::Tensor< T, Dim >::operator= ( const Tensor< T, Dim > &  t)
inline

Class assignment.

Parameters
tA Tensor that needs to be assigned to this Tensor.
template<typename T, unsigned Dim = 2>
void LCS::Tensor< T, Dim >::SetAll ( std::vector< T > &  data)
inline

Set values of all tensor elements.

Parameters
dataA vector contains all element values of the tensor.
template<typename T, unsigned Dim = 2>
void LCS::Tensor< T, Dim >::SetValue ( unsigned  i,
unsigned  j,
value 
)
inline

Set value for one tensor element.

Parameters
iIndex in $x$-coordinate.
jIndex in $y$-coordinate.
valueThe value to be assigned.
template<typename T, unsigned Dim = 2>
auto LCS::Tensor< T, Dim >::Size ( ) const
inline

Get the shape of the tensor.

Returns
Tuple that contains the shape of the tensor.

The documentation for this class was generated from the following file: