Browse Source

refactor(mge/functional): move matinv from nn to math

GitOrigin-RevId: 75c48ce327
tags/v1.3.0
Megvii Engine Team 4 years ago
parent
commit
98d6ba7e2f
2 changed files with 33 additions and 33 deletions
  1. +33
    -0
      imperative/python/megengine/functional/math.py
  2. +0
    -33
      imperative/python/megengine/functional/nn.py

+ 33
- 0
imperative/python/megengine/functional/math.py View File

@@ -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,


+ 0
- 33
imperative/python/megengine/functional/nn.py View File

@@ -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,


Loading…
Cancel
Save