GQCP
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
GQCP::Tensor< _Scalar, _Rank > Class Template Reference

#include <Tensor.hpp>

Inheritance diagram for GQCP::Tensor< _Scalar, _Rank >:
Inheritance graph
Collaboration diagram for GQCP::Tensor< _Scalar, _Rank >:
Collaboration graph

Public Types

using Scalar = _Scalar
 
using Self = Tensor< Scalar, Rank >
 
using Base = Eigen::Tensor< Scalar, Rank >
 

Public Member Functions

const BaseEigen () const
 
BaseEigen ()
 
template<size_t r, size_t s, int Z = Rank>
enable_if_t< Z==4, Self & > addBlock (const MatrixX< Scalar > &M, const size_t i, const size_t j, const size_t k, const size_t l)
 
template<int Z = Rank>
enable_if_t< Z==4, Self & > addBlock (const Self &T, const size_t i, const size_t j, const size_t k, const size_t l)
 
template<int Z = Rank>
enable_if_t< Z==4, Matrix< Scalar > > pairWiseReduced (const size_t start_i=0, const size_t start_j=0, const size_t start_k=0, const size_t start_l=0) const
 
template<int N, int LHSRank = Rank, int RHSRank>
Tensor< Scalar, LHSRank+RHSRank - 2 *N > einsum (const Tensor< Scalar, RHSRank > &rhs, const std::string &lhs_labels, const std::string &rhs_labels, const std::string &output_labels) const
 
template<int N, int LHSRank = Rank, int RHSRank>
Tensor< Scalar, LHSRank+RHSRank - 2 *N > einsum (std::string contraction_string, const Tensor< Scalar, RHSRank > &rhs) const
 
template<int N, int LHSRank = Rank>
Tensor< Scalar, LHSRank+2 - 2 *N > einsum (std::string contraction_string, const Matrix< Scalar > rhs) const
 
template<int Z = Rank>
const enable_if_t< Z==2, GQCP::Matrix< Scalar > > asMatrix () const
 
GQCP::Matrix< Scalarreshape (const size_t rows, const size_t cols) const
 
bool hasEqualDimensionsAs (const Self &other) const
 
template<int Z = Rank>
enable_if_t< Z==4, bool > isApprox (const Self &other, const double tolerance=1.0e-12) const
 
size_t numberOfElements () const
 
template<int Z = Rank>
enable_if_t< Z==4 > print (std::ostream &output_stream=std::cout) const
 

Static Public Member Functions

template<int Z = Rank>
static enable_if_t< Z==4, SelfFromBlock (const Self &T, const size_t i, const size_t j, const size_t k, const size_t l, const size_t cutoff=0)
 

Static Public Attributes

static constexpr auto Rank = _Rank
 

Detailed Description

template<typename _Scalar, int _Rank>
class GQCP::Tensor< _Scalar, _Rank >

An extension of the Eigen::Tensor class, with extra operations.

Template Parameters
_ScalarThe scalar type of one of the elements of the tensor.
_RankThe rank of the tensor, i.e. the number of axes.

We have decided to inherit from Eigen::Tensor, because we will use different hierarchies: see also: https://eigen.tuxfamily.org/dox-devel/TopicCustomizing_InheritingMatrix.html.

Member Typedef Documentation

◆ Base

template<typename _Scalar , int _Rank>
using GQCP::Tensor< _Scalar, _Rank >::Base = Eigen::Tensor<Scalar, Rank>

◆ Scalar

template<typename _Scalar , int _Rank>
using GQCP::Tensor< _Scalar, _Rank >::Scalar = _Scalar

◆ Self

template<typename _Scalar , int _Rank>
using GQCP::Tensor< _Scalar, _Rank >::Self = Tensor<Scalar, Rank>

Member Function Documentation

◆ addBlock() [1/2]

template<typename _Scalar , int _Rank>
template<size_t r, size_t s, int Z = Rank>
enable_if_t< Z==4, Self & > GQCP::Tensor< _Scalar, _Rank >::addBlock ( const MatrixX< Scalar > &  M,
const size_t  i,
const size_t  j,
const size_t  k,
const size_t  l 
)
inline

Add a matrix to a this tensor starting from given indices

Template Parameters
rindicates with which tensor index axis (0,1,2,3) the row index axis of the matrix should align
sindicates with which tensor index axis (0,1,2,3) the column index axis of the matrix should align
Parameters
Ma matrix
istarting index for the 1st index axis of the tensor
jstarting index for the 2nd index axis of the tensor
kstarting index for the 3rd index axis of the tensor
lstarting index for the 4th index axis of the tensor
Returns
a reference to updated this

Example: Given a rank-4 tensor of dimensions (10,10,10,10), and a matrix M of dimensions (3,3) Input : <2,0> (M, 0, 2, 1, 3): <2,0> dictates that the row index axis of the matrix aligns with the 3rd index axis of the tensor (2nd starting from 0) and that the column index axis of the matrix aligns with the 1st index axis tensor (0th starting from 0) (0, 2, 1, 3) dictates the starting indexes to which the matrix is added, given the input <2,0> this means the indices of the 2nd (indicated by the "2") and the 4th (indicated by the "3") axes are held fixed because they do not correspond to the entries <2,0>.

◆ addBlock() [2/2]

template<typename _Scalar , int _Rank>
template<int Z = Rank>
enable_if_t< Z==4, Self & > GQCP::Tensor< _Scalar, _Rank >::addBlock ( const Self T,
const size_t  i,
const size_t  j,
const size_t  k,
const size_t  l 
)
inline

Add a rank-4 tensor into this, starting from given indices

Parameters
Ta rank-4 tensor
istarting index for the 1st index axis of the tensor
jstarting index for the 2nd index axis of the tensor
kstarting index for the 3rd index axis of the tensor
lstarting index for the 4th index axis of the tensor
Returns
a reference to updated this

◆ asMatrix()

template<typename _Scalar , int _Rank>
template<int Z = Rank>
const enable_if_t< Z==2, GQCP::Matrix< Scalar > > GQCP::Tensor< _Scalar, _Rank >::asMatrix ( ) const
inline
Returns
This rank-two tensor as a matrix.

◆ Eigen() [1/2]

template<typename _Scalar , int _Rank>
Base & GQCP::Tensor< _Scalar, _Rank >::Eigen ( )
inline
Returns
This as a non-const Eigen base.

◆ Eigen() [2/2]

template<typename _Scalar , int _Rank>
const Base & GQCP::Tensor< _Scalar, _Rank >::Eigen ( ) const
inline
Returns
This as a const Eigen base.

◆ einsum() [1/3]

template<typename _Scalar , int _Rank>
template<int N, int LHSRank = Rank, int RHSRank>
Tensor< Scalar, LHSRank+RHSRank - 2 *N > GQCP::Tensor< _Scalar, _Rank >::einsum ( const Tensor< Scalar, RHSRank > &  rhs,
const std::string &  lhs_labels,
const std::string &  rhs_labels,
const std::string &  output_labels 
) const
inline

◆ einsum() [2/3]

template<typename _Scalar , int _Rank>
template<int N, int LHSRank = Rank>
Tensor< Scalar, LHSRank+2 - 2 *N > GQCP::Tensor< _Scalar, _Rank >::einsum ( std::string  contraction_string,
const Matrix< Scalar rhs 
) const
inline

◆ einsum() [3/3]

template<typename _Scalar , int _Rank>
template<int N, int LHSRank = Rank, int RHSRank>
Tensor< Scalar, LHSRank+RHSRank - 2 *N > GQCP::Tensor< _Scalar, _Rank >::einsum ( std::string  contraction_string,
const Tensor< Scalar, RHSRank > &  rhs 
) const
inline

◆ FromBlock()

template<typename _Scalar , int _Rank>
template<int Z = Rank>
static enable_if_t< Z==4, Self > GQCP::Tensor< _Scalar, _Rank >::FromBlock ( const Self T,
const size_t  i,
const size_t  j,
const size_t  k,
const size_t  l,
const size_t  cutoff = 0 
)
inlinestatic
Parameters
Ta rank-4 tensor
i1st starting index
j2nd starting index
k3rd starting index
l4th starting index
cutoffearly cut-off of index iteration
Returns
a rank-4 tensor from an other rank-4 tensor, starting from given indices

◆ hasEqualDimensionsAs()

template<typename _Scalar , int _Rank>
bool GQCP::Tensor< _Scalar, _Rank >::hasEqualDimensionsAs ( const Self other) const
inline
Parameters
otherthe other tensor
Returns
if this tensor has the same dimensions as the other tensor

◆ isApprox()

template<typename _Scalar , int _Rank>
template<int Z = Rank>
enable_if_t< Z==4, bool > GQCP::Tensor< _Scalar, _Rank >::isApprox ( const Self other,
const double  tolerance = 1.0e-12 
) const
inline
Parameters
otherthe other tensor
tolerancethe tolerance for element-wise comparison
Returns
if this is approximately equal to the other

◆ numberOfElements()

template<typename _Scalar , int _Rank>
size_t GQCP::Tensor< _Scalar, _Rank >::numberOfElements ( ) const
inline
Returns
The total number of elements in this tensor.

◆ pairWiseReduced()

template<typename _Scalar , int _Rank>
template<int Z = Rank>
enable_if_t< Z==4, Matrix< Scalar > > GQCP::Tensor< _Scalar, _Rank >::pairWiseReduced ( const size_t  start_i = 0,
const size_t  start_j = 0,
const size_t  start_k = 0,
const size_t  start_l = 0 
) const
inline
Parameters
start_ithe index at which the first rank should start
start_jthe index at which the second rank should start
start_kthe index at which the third rank should start
start_lthe index at which the fourth rank should start
Returns
a pair-wise reduced form of this rank-4 tensor. The elements of the tensor are put into the matrix such that M(m,n) = T(i,j,k,l)

in which m is calculated from i and j in a column-major way n is calculated from k and l in a column-major way

◆ print()

template<typename _Scalar , int _Rank>
template<int Z = Rank>
enable_if_t< Z==4 > GQCP::Tensor< _Scalar, _Rank >::print ( std::ostream &  output_stream = std::cout) const
inline

Print the contents of this to an output stream

Parameters
output_streamthe stream used for outputting

◆ reshape()

template<typename _Scalar , int _Rank>
GQCP::Matrix< Scalar > GQCP::Tensor< _Scalar, _Rank >::reshape ( const size_t  rows,
const size_t  cols 
) const
inline

A numpy-like reshape function that turns a tensor into a matrix using C-like ordering (See numpy documentation: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html).

Parameters
rowsThe dimension of the matrix rows.
colsThe dimension of the matrix columns.
Returns
This tensor as a matrix of the specified dimensions, ordered using C-like ordering.

Member Data Documentation

◆ Rank

template<typename _Scalar , int _Rank>
constexpr auto GQCP::Tensor< _Scalar, _Rank >::Rank = _Rank
staticconstexpr

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