oneflow.linalg.inv¶
-
oneflow.linalg.
inv
(A) → Tensor¶ Computes the inverse of a square matrix if it exists. Throws a RuntimeError if the matrix is not invertible.
Letting \(\mathbb{K}\) be \(\mathbb{R}\) or \(\mathbb{C}\), for a matrix \(A \in \mathbb{K}^{n imes n}\), its inverse matrix \(A^{-1} \in \mathbb{K}^{n imes n}\) (if it exists) is defined as
\[A^{-1}A = AA^{-1} = \mathrm{I}_n\]where \(\mathrm{I}_n\) is the n-dimensional identity matrix.
The inverse matrix exists if and only if \(A\) is invertible. In this case, the inverse is unique.
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.- Parameters
A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of invertible matrices.
- Raises
RuntimeError – if the matrix
A
or any matrix in the batch of matricesA
is not invertible.
Examples:
>>> import oneflow as flow >>> A = flow.tensor([[ 1.3408, -0.7788, 1.0551, -0.5866], ... [ 0.8480, 0.8350, 0.9781, -0.1297], ... [-0.0881, -0.6142, -0.3833, 0.3232], ... [ 1.2841, 0.7517, -0.3849, 0.2515]]) >>> flow.linalg.inv(A) tensor([[ 0.3105, -0.0811, 0.1288, 0.5169], ... [-0.3457, 0.1716, -0.7133, 0.1987], ... [-0.0593, 1.1706, 0.8694, -0.6516], ... [-0.6427, 1.6923, 2.8049, -0.2541]], dtype=oneflow.float32) >>> A = flow.tensor([[[ 0.6144, 0.1027, -0.1353], ... [-1.4415, -0.6731, 0.3723], ... [ 0.4069, -0.8940, 1.4056]], ... [[-1.1891, -0.3897, -1.5015], ... [ 0.3028, 1.1040, 0.2600], ... [-1.6970, 0.4238, 0.9146]]]) >>> flow.linalg.inv(A) tensor([[[ 1.6830, 0.0644, 0.1449], ... [-5.9755, -2.5206, 0.0925], ... [-4.2879, -1.6219, 0.7283]], ... ... [[-0.2370, 0.0737, -0.4100], ... [ 0.1892, 0.9579, 0.0384], ... [-0.5274, -0.3070, 0.3148]]], dtype=oneflow.float32)