mptensor v0.6.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches

Operations that change the shape of a tensor. More...

Collaboration diagram for Shape change:
template<typename MatrixType >
Tensor< MatrixType > mptensor::transpose (Tensor< MatrixType > T, const Axes &axes)
 Transposition of tensor with lazy evaluation.
 
template<typename MatrixType >
Tensor< MatrixType > mptensor::transpose (const Tensor< MatrixType > &T, const Axes &axes, size_t urank_new)
 Transposition of tensor without lazy evaluation.
 
template<typename MatrixType >
Tensor< MatrixType > mptensor::reshape (const Tensor< MatrixType > &T, const Shape &shape_new)
 Change the shape of tensor.
 
template<typename MatrixType >
Tensor< MatrixType > mptensor::slice (const Tensor< MatrixType > &T, std::ptrdiff_t n_axes, std::ptrdiff_t i_begin, std::ptrdiff_t i_end)
 Slice a tensor.
 
template<typename MatrixType >
Tensor< MatrixType > mptensor::slice (const Tensor< MatrixType > &T, const Index &index_begin, const Index &index_end)
 Slice a tensor.
 
template<typename MatrixType >
Tensor< MatrixType > mptensor::extend (const Tensor< MatrixType > &T, const Shape &shape_new)
 Extend the size of a tensor.
 

Detailed Description

Operations that change the shape of a tensor.

Function Documentation

◆ extend()

template<typename MatrixType >
Tensor< MatrixType > mptensor::extend ( const Tensor< MatrixType > &  T,
const Shape &  shape_new 
)

Extend the size of a tensor.

Parameters
[in]TTensor to be extended.
[in]shape_newNew shape.
Returns
Extended tensor.
Note
New shape should be larger than the original shape.

◆ reshape()

template<typename MatrixType >
Tensor< MatrixType > mptensor::reshape ( const Tensor< MatrixType > &  T,
const Shape &  shape_new 
)

Change the shape of tensor.

Parameters
[in]TTensor to be reshaped.
[in]shape_newNew shape.
Returns
Reshaped tensor.
Note
The new shape should be compatible with the original shape. The total size of tensor does not change.
Warning
mptensor uses the column major, unlike NumPy.

◆ slice() [1/2]

template<typename MatrixType >
Tensor< MatrixType > mptensor::slice ( const Tensor< MatrixType > &  T,
const Index &  index_begin,
const Index &  index_end 
)

Slice a tensor.

This function mimics slicing in python such as [start:end]. If index_begin[r]==index_end[r], this rank is not sliced. For example,

slice(T, Index(1,0,3), Index(4,0,6));
std::complex< double > complex
Definition complex.hpp:38
BasicIndex< std::ptrdiff_t > Index
Definition index.hpp:209
Tensor< MatrixType > slice(const Tensor< MatrixType > &a, std::ptrdiff_t n_axes, std::ptrdiff_t i_begin, std::ptrdiff_t i_end)
Slice a tensor.
Definition tensor_impl.hpp:1265

will return T[1:4, :, 3:6].

Parameters
[in]TTensor to be sliced.
[in]index_beginStart of indices.
[in]index_endEnd of indices.
Returns
Sliced tensor.

◆ slice() [2/2]

template<typename MatrixType >
Tensor< MatrixType > mptensor::slice ( const Tensor< MatrixType > &  T,
std::ptrdiff_t  n_axes,
std::ptrdiff_t  i_begin,
std::ptrdiff_t  i_end 
)

Slice a tensor.

This function mimics slicing in python such as [start:end].

Parameters
[in]TTensor to be sliced.
[in]n_axesAxes to be sliced.
[in]i_beginStart of index.
[in]i_endEnd of index.
Returns
Sliced tensor.

◆ transpose() [1/2]

template<typename MatrixType >
Tensor< MatrixType > mptensor::transpose ( const Tensor< MatrixType > &  T,
const Axes &  axes,
size_t  urank_new 
)

Transposition of tensor without lazy evaluation.

When axes=[1,2,0], \( T_{ijk} \) is transformed into \( T_{jki} \).

Parameters
[in]TTensor to be transposed.
[in]axesOrder of axes.
[in]urank_newUpper rank of new tensor.
Returns
Transposed tensor
Note
This function may cause communications.

◆ transpose() [2/2]

template<typename MatrixType >
Tensor< MatrixType > mptensor::transpose ( Tensor< MatrixType >  T,
const Axes &  axes 
)
inline

Transposition of tensor with lazy evaluation.

When axes=[1,2,0], \( T_{ijk} \) is transformed into \( T_{jki} \).

Parameters
[in]TTensor to be transposed.
[in]axesOrder of axes
Returns
Transposed tensor