Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType > Class Template Reference

A class that represents a triangular or square matrix, with optional support for tensor-like multi-dimensional data. More...

#include <tensor.hpp>

Public Member Functions

template<typename T = void, typename = std::enable_if_t< !Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
 TriMatrix (IndexType tri_dim)
 Constructor for a non-tensor matrix.
 TriMatrix (const StorageType &data, IndexType tri_dim)
 Copy-constructor (almost).
template<typename T = void, typename = std::enable_if_t< Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
 TriMatrix (IndexType tri_dim, IndexType tensor_size)
 Constructor for a tensor-like matrix.
template<typename T = void, typename = std::enable_if_t<!Tensor, T>>
const DataType & operator() (IndexType i, IndexType j) const
 Accessor for non-tensor matrices (const version).
template<typename T = void, typename = std::enable_if_t<Tensor, T>>
const DataType & operator() (IndexType i, IndexType j, IndexType k) const
 Accessor for tensor matrices (const version).
template<typename T = void, typename = std::enable_if_t< !Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
DataType & operator() (IndexType i, IndexType j)
 Mutator for non-tensor matrices.
template<typename T = void, typename = std::enable_if_t<Tensor, T>>
DataType & operator() (IndexType i, IndexType j, IndexType k)
 Mutator for tensor matrices.
IndexType dim () const
 Dimension n of the \(n \times n\) matrix (or one slice of the tensor).
IndexType tdim () const
 Dimension along the tensor dimension.
IndexType numel () const
 Total number of elements.
auto begin ()
 Begin iterator.
auto end ()
 End iterator.
auto begin () const
 Const begin iterator.
auto end () const
 Const end iterator.

Protected Member Functions

IndexType ij (IndexType i, IndexType j) const
 Helper function to compute the flattened index for a 2D matrix.
IndexType ijk (IndexType i, IndexType j, IndexType k) const
 Helper function to compute the flattened index for a 3D tensor matrix.

Protected Attributes

IndexType m_tri_dim
 Dimension of the matrix.
IndexType m_tensor_size
 Size of the tensor dimension, if applicable.
IndexType m_tri_size
 Total number of elements in one slice.
IndexType m_numel
 Total number of elements stored in the matrix.
StorageType m_data
 Underlying data storage.

Detailed Description

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
class vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >

A class that represents a triangular or square matrix, with optional support for tensor-like multi-dimensional data.

The TriMatrix class is a templated matrix data structure that can store elements in either triangular or full (square) format. Namely it offers a coalescent representation for data when you know that the indexes of the tensor i, j satisfy i + j < tri_dim. It also supports third-order tensor data if enabled through template parameters.

Template Parameters
TriangularSpecifies whether the matrix is triangular. If true, only the upper triangular part is stored.
TensorSpecifies whether the matrix operates as a tensor with additional dimensions.
DataTypeThe data type of elements stored in the matrix (e.g., double, float).
IndexTypeThe data type for indexing the matrix (typically int or size_t).
StorageTypeThe container where to save the data. By default an std::vector, other used options are a const pointer, indicating that this is an not-owning view of some data

Constructor & Destructor Documentation

◆ TriMatrix() [1/3]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t< !Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::TriMatrix ( IndexType tri_dim)
inlineexplicit

Constructor for a non-tensor matrix.

This constructor initializes a triangular or square matrix, depending on the value of Triangular.

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
tri_dimThe dimension of the matrix (i.e., the number of rows/columns). If Triangular is true, only the upper triangular part is stored.
Note
This constructor can only be used when Tensor is false.

◆ TriMatrix() [2/3]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::TriMatrix ( const StorageType & data,
IndexType tri_dim )
inlineexplicit

Copy-constructor (almost).

This constructor initializes the tensor from the underlying data buffer. Especially useful for constructing data views (pass the pointer to the data)

◆ TriMatrix() [3/3]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t< Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::TriMatrix ( IndexType tri_dim,
IndexType tensor_size )
inlineexplicit

Constructor for a tensor-like matrix.

This constructor initializes a matrix with tensor support, adding an extra dimension for multi-dimensional data.

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
tri_dimThe dimension of the matrix.
tensor_sizeThe size of the additional tensor dimension.
Note
This constructor can only be used when Tensor is true.

Member Function Documentation

◆ begin() [1/2]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
auto vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::begin ( )
inline

Begin iterator.

◆ begin() [2/2]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
auto vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::begin ( ) const
inline

Const begin iterator.

◆ dim()

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::dim ( ) const
inline

Dimension n of the \(n \times n\) matrix (or one slice of the tensor).

◆ end() [1/2]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
auto vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::end ( )
inline

End iterator.

◆ end() [2/2]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
auto vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::end ( ) const
inline

Const end iterator.

◆ ij()

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::ij ( IndexType i,
IndexType j ) const
inlineprotected

Helper function to compute the flattened index for a 2D matrix.

If Triangular is true, it uses a mapping that only stores the upper triangular part of the matrix.

Parameters
iRow index.
jColumn index.
Returns
The flattened 1D index in the data array.

◆ ijk()

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::ijk ( IndexType i,
IndexType j,
IndexType k ) const
inlineprotected

Helper function to compute the flattened index for a 3D tensor matrix.

Parameters
iRow index.
jColumn index.
kTensor dimension index.
Returns
The flattened 1D index in the data array.

◆ numel()

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::numel ( ) const
inline

Total number of elements.

◆ operator()() [1/4]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t< !Tensor && std::is_same_v<StorageType, std::vector<DataType>>, T>>
DataType & vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::operator() ( IndexType i,
IndexType j )
inline

Mutator for non-tensor matrices.

This function allows modification of the matrix element at position (i, j).

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
iRow index.
jColumn index.
Returns
A reference to the element at position (i, j).
Note
This function can only be used when Tensor is false.

◆ operator()() [2/4]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t<!Tensor, T>>
const DataType & vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::operator() ( IndexType i,
IndexType j ) const
inline

Accessor for non-tensor matrices (const version).

This function returns the matrix element at position (i, j). If Triangular is true, the indices must be within the upper triangular part.

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
iRow index.
jColumn index.
Returns
The element at position (i, j).
Note
This function can only be used when Tensor is false.

◆ operator()() [3/4]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t<Tensor, T>>
DataType & vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::operator() ( IndexType i,
IndexType j,
IndexType k )
inline

Mutator for tensor matrices.

This function allows modification of the matrix element at position (i, j, k).

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
iRow index.
jColumn index.
kTensor dimension index.
Returns
A reference to the element at position (i, j, k).
Note
This function can only be used when Tensor is true.

◆ operator()() [4/4]

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
template<typename T = void, typename = std::enable_if_t<Tensor, T>>
const DataType & vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::operator() ( IndexType i,
IndexType j,
IndexType k ) const
inline

Accessor for tensor matrices (const version).

This function returns the matrix element at position (i, j, k), where k corresponds to the extra tensor dimension.

Template Parameters
TTemplate parameter for SFINAE control.
Parameters
iRow index.
jColumn index.
kTensor dimension index.
Returns
The element at position (i, j, k).
Note
This function can only be used when Tensor is true.

◆ tdim()

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::tdim ( ) const
inline

Dimension along the tensor dimension.

Member Data Documentation

◆ m_data

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
StorageType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::m_data
protected

Underlying data storage.

◆ m_numel

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::m_numel
protected

Total number of elements stored in the matrix.

◆ m_tensor_size

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::m_tensor_size
protected

Size of the tensor dimension, if applicable.

◆ m_tri_dim

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::m_tri_dim
protected

Dimension of the matrix.

◆ m_tri_size

template<bool Triangular, bool Tensor, typename DataType, typename IndexType, typename StorageType = std::vector<DataType>>
IndexType vulpes::datastructure::TriMatrix< Triangular, Tensor, DataType, IndexType, StorageType >::m_tri_size
protected

Total number of elements in one slice.


The documentation for this class was generated from the following file:
  • /__w/vulpes/vulpes/vulpes/datastructure/tensor.hpp