GitOrigin-RevId: 75c48ce327
tags/v1.3.0
@@ -29,6 +29,7 @@ __all__ = [ | |||||
"dot", | "dot", | ||||
"isinf", | "isinf", | ||||
"isnan", | "isnan", | ||||
"matinv", | |||||
"matmul", | "matmul", | ||||
"max", | "max", | ||||
"mean", | "mean", | ||||
@@ -729,6 +730,38 @@ def topk( | |||||
return tns, ind | return tns, ind | ||||
def matinv(inp: Tensor) -> Tensor: | |||||
""" | |||||
Computes the inverse of a batch of matrices; input must has shape [..., n, n]. | |||||
:param inp: input tensor. | |||||
:return: output tensor. | |||||
Examples: | |||||
.. testcode:: | |||||
import numpy as np | |||||
from megengine import tensor | |||||
import megengine.functional as F | |||||
data = tensor([[1.0, 0.0], [1.0, 1.0]]) | |||||
out = F.matinv(data) | |||||
print(out.numpy()) | |||||
Outputs: | |||||
.. testoutput:: | |||||
[[ 1. 0.] | |||||
[-1. 1.]] | |||||
""" | |||||
(result,) = apply(builtin.MatrixInverse(), inp) | |||||
return result | |||||
def matmul( | def matmul( | ||||
inp1: Tensor, | inp1: Tensor, | ||||
inp2: Tensor, | inp2: Tensor, | ||||
@@ -53,7 +53,6 @@ __all__ = [ | |||||
"logsigmoid", | "logsigmoid", | ||||
"logsumexp", | "logsumexp", | ||||
"logsoftmax", | "logsoftmax", | ||||
"matinv", | |||||
"max_pool2d", | "max_pool2d", | ||||
"one_hot", | "one_hot", | ||||
"prelu", | "prelu", | ||||
@@ -1183,38 +1182,6 @@ def remap( | |||||
return result | return result | ||||
def matinv(inp: Tensor) -> Tensor: | |||||
""" | |||||
Computes the inverse of a batch of matrices; input must has shape [..., n, n]. | |||||
:param inp: input tensor. | |||||
:return: output tensor. | |||||
Examples: | |||||
.. testcode:: | |||||
import numpy as np | |||||
from megengine import tensor | |||||
import megengine.functional as F | |||||
data = tensor([[1.0, 0.0], [1.0, 1.0]]) | |||||
out = F.matinv(data) | |||||
print(out.numpy()) | |||||
Outputs: | |||||
.. testoutput:: | |||||
[[ 1. 0.] | |||||
[-1. 1.]] | |||||
""" | |||||
(result,) = apply(builtin.MatrixInverse(), inp) | |||||
return result | |||||
def interpolate( | def interpolate( | ||||
inp: Tensor, | inp: Tensor, | ||||
size: Optional[Union[int, Tuple[int, int]]] = None, | size: Optional[Union[int, Tuple[int, int]]] = None, | ||||