Skip to contents

Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A is a batch of matrices then the output has the same batch dimensions.

Usage

linalg_matrix_power(A, n)

Arguments

A

(Tensor): tensor of shape (*, m, m) where * is zero or more batch dimensions.

n

(int): the exponent.

Details

If n=0, it returns the identity matrix (or batch) of the same shape as A. If n is negative, it returns the inverse of each matrix (if invertible) raised to the power of abs(n).

Examples

if (torch_is_installed()) {
A <- torch_randn(3, 3)
linalg_matrix_power(A, 0)
}
#> torch_tensor
#>  1  0  0
#>  0  1  0
#>  0  0  1
#> [ CPUFloatType{3,3} ]