提交 fc0fb2f6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Get rid of InversePermutation Op, obsoleted by new functionalities of

PermuteRowElements and ARange.
上级 a0400630
......@@ -2765,29 +2765,6 @@ def arange(start, stop=None, step=1, dtype=None):
return _arange[dtype](start, stop, step)
class InversePermutation(Op):
"""Computes the inverse of permutations.
Each row of input should contain a permutation of the first integers.
"""
def make_node(self, x):
x = as_tensor_variable(x)
return Apply(self, [x], [x.type()])
def perform(self, node, (x,), (outs,)):
if outs[0] is None or outs[0].shape != x.shape:
outs[0] = numpy.empty_like(x)
for i in numpy.ndindex(x.shape[:-1]):
outs[0][i][x[i]] = numpy.arange(x.shape[-1], dtype=x.dtype)
def grad(self, (x,), (gz,)):
return [None]
#inverse_permutation = InversePermutation()
def inverse_permutation(perm):
return permute_row_elements(arange(perm.shape[-1]), perm, inverse=True)
class PermuteRowElements(Op):
"""Permute the elements of each row (inner-most dim) of a tensor.
......@@ -2935,6 +2912,12 @@ _permute_row_elements = PermuteRowElements()
def permute_row_elements(x, y, inverse=0):
return _permute_row_elements(x, y, inverse)
def inverse_permutation(perm):
"""Computes the inverse of permutations.
Each row of input should contain a permutation of the first integers.
"""
return permute_row_elements(arange(perm.shape[-1]), perm, inverse=True)
#########################
# Linalg : Dot
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论