Rate this Page

torch.linalg.matrix_exp#

torch.linalg.matrix_exp(A)Tensor#

Computes the matrix exponential of a square matrix.

LettingK\mathbb{K} beR\mathbb{R} orC\mathbb{C},this function computes thematrix exponential ofAKn×nA \in \mathbb{K}^{n \times n}, which is defined as

matrix_exp(A)=k=01k!AkKn×n.\mathrm{matrix\_exp}(A) = \sum_{k=0}^\infty \frac{1}{k!}A^k \in \mathbb{K}^{n \times n}.

If the matrixAA has eigenvaluesλiC\lambda_i \in \mathbb{C},the matrixmatrix_exp(A)\mathrm{matrix\_exp}(A) has eigenvalueseλiCe^{\lambda_i} \in \mathbb{C}.

Supports input of bfloat16, float, double, cfloat and cdouble dtypes.Also supports batches of matrices, and ifA is a batch of matrices thenthe output has the same batch dimensions.

Parameters

A (Tensor) – tensor of shape(*, n, n) where* is zero or more batch dimensions.

Example:

>>>A=torch.empty(2,2,2)>>>A[0,:,:]=torch.eye(2,2)>>>A[1,:,:]=2*torch.eye(2,2)>>>Atensor([[[1., 0.],         [0., 1.]],        [[2., 0.],         [0., 2.]]])>>>torch.linalg.matrix_exp(A)tensor([[[2.7183, 0.0000],         [0.0000, 2.7183]],         [[7.3891, 0.0000],          [0.0000, 7.3891]]])>>>importmath>>>A=torch.tensor([[0,math.pi/3],[-math.pi/3,0]])# A is skew-symmetric>>>torch.linalg.matrix_exp(A)# matrix_exp(A) = [[cos(pi/3), sin(pi/3)], [-sin(pi/3), cos(pi/3)]]tensor([[ 0.5000,  0.8660],        [-0.8660,  0.5000]])