Cytnx v0.9.5
Loading...
Searching...
No Matches
Functions
cytnx::algo Namespace Reference

Some basic algorithms API. More...

Functions

Tensor Sort (const Tensor &Tin)
 sort Tensor along last axis.
 
Tensor Concatenate (Tensor T1, Tensor T2)
 concatenate two 1d Tensor.
 
Tensor Vstack (const std::vector< Tensor > &In_tensors)
 vertical stack a list of Tensor.
 
Tensor Hstack (const std::vector< Tensor > &In_tensors)
 horizontal stack a list of Tensor.
 
void Vsplit_ (std::vector< Tensor > &out, const Tensor &Tin, const std::vector< cytnx_uint64 > &dims)
 split a Matrix (a 2d Tensor) into a list of Matrices along the vertical direction.
 
void Hsplit_ (std::vector< Tensor > &out, const Tensor &Tin, const std::vector< cytnx_uint64 > &dims)
 split a Matrix (a 2d Tensor) into a list of Matrices along the horizontal direction.
 
std::vector< TensorVsplit (const Tensor &Tin, const std::vector< cytnx_uint64 > &dims)
 split a Matrix (a 2d Tensor) into a list of Matrices along the vertical direction.
 
std::vector< TensorHsplit (const Tensor &Tin, const std::vector< cytnx_uint64 > &dims)
 split a Matrix (a 2d Tensor) into a list of Matrices along the horizontal direction.
 

Detailed Description

Some basic algorithms API.

Function Documentation

◆ Concatenate()

Tensor cytnx::algo::Concatenate ( Tensor  T1,
Tensor  T2 
)

concatenate two 1d Tensor.

Parameters
[in]T1the first Tensor.
[in]T2the second Tensor.
Returns
[Tensor] return a new Tensor that is the concatenation of T1 and T2.
Precondition
  1. T1 and T2 should be 1d Tensor.
  2. T1 and T2 should be on same device.
  3. The data type of T1 and T2 cannot be Type.Void.
Note
If the data type of T1 and T2 are different, the data type of the output Tensor will be the stronger one.

◆ Hsplit()

std::vector< Tensor > cytnx::algo::Hsplit ( const Tensor Tin,
const std::vector< cytnx_uint64 > &  dims 
)

split a Matrix (a 2d Tensor) into a list of Matrices along the horizontal direction.

This function will split a Matrix (a 2d Tensor) into a list of Matrices along the horizontal direction. That is, if the input Matrix Tin is:

\[ M = \begin{bmatrix} m_{11} & m_{12} & m_{13}\\ m_{21} & m_{22} & m_{23}\\ m_{31} & m_{32} & m_{33}\\ \end{bmatrix} \]

and the input dims is \( [2,1] \), the output will be \( [M_1, M_2] \), where:

\[ M_1 = \begin{bmatrix} m_{11} & m_{12}\\ m_{21} & m_{22}\\ m_{31} & m_{32}\\ \end{bmatrix} \]

and

\[ M_2 = \begin{bmatrix} m_{13}\\ m_{23}\\ m_{33}\\ \end{bmatrix} \]

Parameters
[in]Tinthe input Matrix (a 2d Tensor).
[in]dimsthe column number of each Matrix in the output list.
Returns
[std::vector<Tensor>] return a list of Matrices that is the split of Tin with respect to dims.
Precondition
  1. The input Tin need to be 2d Tensor (Matrix).
  2. The input dims cannot be empty.
  3. The input dims cannot be out of range. That is, the summation of dims need equal to the number of columns of Tin.
  4. The elements in dims cannot be zero.
See also
Vsplit, Hstack

◆ Hsplit_()

void cytnx::algo::Hsplit_ ( std::vector< Tensor > &  out,
const Tensor Tin,
const std::vector< cytnx_uint64 > &  dims 
)

split a Matrix (a 2d Tensor) into a list of Matrices along the horizontal direction.

This function is same as Hsplit, but the output is in the argument.

Parameters
[out]outa list of Tensor that will be the output.
[in]Tinthe input Tensor.
[in]dimsthe column number of each Matrix in the output list.
See also
Hsplit

◆ Hstack()

Tensor cytnx::algo::Hstack ( const std::vector< Tensor > &  In_tensors)

horizontal stack a list of Tensor.

This function will stack horizontally a list of Matrices (a 2d tensor) with same number of rows. That is, if the input Matrices are \( [M_1, M_2, M_3] \), the output will be:

\[ \begin{bmatrix} M_1, M_2, M_3 \end{bmatrix} \]

Note that the number of rows of \( M_1 \), \( M_2 \) and \( M_3 \) should be the same.

Parameters
[in]In_tensorsa list of 2d Tensor (Matrix).
Returns
[Tensor] return a new Tensor that is the horizontal stack of In_tensors.
Precondition
  1. The input In_tensors cannot be empty.
  2. The input In_tensors need to be 2d Tensor (Matrix).
  3. The input In_tensors should have same number of rows.
  4. The input In_tensors should be on same device.
  5. The data type of the input In_tensors cannot be Type.Bool or Type.Void. (see cytnx::Type)
Note
If the data type of the input In_tensors are different, the data type of the output Tensor will be the stronger one.

◆ Sort()

Tensor cytnx::algo::Sort ( const Tensor Tin)

sort Tensor along last axis.

Parameters
[in]Tinthe input Tensor.
Returns
[Tensor]

◆ Vsplit()

std::vector< Tensor > cytnx::algo::Vsplit ( const Tensor Tin,
const std::vector< cytnx_uint64 > &  dims 
)

split a Matrix (a 2d Tensor) into a list of Matrices along the vertical direction.

This function will split a Matrix (a 2d Tensor) into a list of Matrices along the vertical direction. That is, if the input Matrix Tin is:

\[ M = \begin{bmatrix} m_{11} & m_{12} & m_{13}\\ m_{21} & m_{22} & m_{23}\\ m_{31} & m_{32} & m_{33}\\ \end{bmatrix} \]

and the input dims is \( [1,2] \), the output will be \( [M_1, M_2] \), where:

\[ M_1 = \begin{bmatrix} m_{11} & m_{12} & m_{13}\\ \end{bmatrix} \]

and

\[ M_2 = \begin{bmatrix} m_{21} & m_{22} & m_{23}\\ m_{31} & m_{32} & m_{33}\\ \end{bmatrix} \]

Parameters
[in]Tinthe input Matrix (a 2d Tensor).
[in]dimsthe row number of each Matrix in the output list.
Returns
[std::vector<Tensor>] return a list of Matrices that is the split of Tin with respect to dims.
Precondition
  1. The input Tin need to be 2d Tensor (Matrix).
  2. The input dims cannot be empty.
  3. The input dims cannot be out of range. That is, the summation of dims need equal to the number of rows of Tin.
  4. The elements in dims cannot be zero.
See also
Hsplit, Vstack

◆ Vsplit_()

void cytnx::algo::Vsplit_ ( std::vector< Tensor > &  out,
const Tensor Tin,
const std::vector< cytnx_uint64 > &  dims 
)

split a Matrix (a 2d Tensor) into a list of Matrices along the vertical direction.

This function is same as Vsplit, but the output is in the argument.

Parameters
[out]outa list of Tensor that will be the output.
[in]Tinthe input Tensor.
[in]dimsthe row number of each Matrix in the output list.
See also
Vsplit

◆ Vstack()

Tensor cytnx::algo::Vstack ( const std::vector< Tensor > &  In_tensors)

vertical stack a list of Tensor.

This function will stack vertically a list of Matrices (a 2d tensor) with same number of columns. That is, if the input Matrices are \( [M_1, M_2, M_3] \), the output will be:

\[ \begin{bmatrix} M_1\\ M_2\\ M_3\\ \end{bmatrix} \]

Note that the number of columns of \( M_1 \), \( M_2 \) and \( M_3 \) should be the same.

Parameters
[in]In_tensorsa list of 2d Tensor (Matrix).
Returns
[Tensor] return a new Tensor that is the vertical stack of In_tensors.
Precondition
  1. The input In_tensors cannot be empty.
  2. The input In_tensors need to be 2d Tensor (Matrix).
  3. The input In_tensors should have same number of columns.
  4. The input In_tensors should be on same device.
  5. The data type of the input In_tensors cannot be Type.Bool or Type.Void. (see cytnx::Type)
Note
If the data type of the input In_tensors are different, the data type of the output Tensor will be the stronger one.