提交 d084cecf authored 作者: Frederic's avatar Frederic

small update

上级 dd018d55
...@@ -5095,19 +5095,13 @@ def swapaxes(y, axis1, axis2): ...@@ -5095,19 +5095,13 @@ def swapaxes(y, axis1, axis2):
def choose(a, choices, out=None, mode='raise'): def choose(a, choices, out=None, mode='raise'):
# This is done to keep the same function signature then NumPy.
assert out is None assert out is None
return Choose(mode)(a, choices) return Choose(mode)(a, choices)
class Choose(Op):
def __init__(self, mode):
self.mode = mode
def __hash__(self):
return hash((type(self), self.props()))
def __eq__(self, other): class Choose(Op):
return (type(self) == type(other) and self.props() == other.props()) __props__ = ('mode',)
def infer_shape(self, node, shapes): def infer_shape(self, node, shapes):
if isinstance(node.inputs[1], tuple): if isinstance(node.inputs[1], tuple):
...@@ -5118,9 +5112,6 @@ class Choose(Op): ...@@ -5118,9 +5112,6 @@ class Choose(Op):
else: else:
return[(shapes[0])] return[(shapes[0])]
def props(self):
return self.mode
def make_node(self, a, choices): def make_node(self, a, choices):
from theano import typed_list from theano import typed_list
a = as_tensor_variable(a) a = as_tensor_variable(a)
...@@ -5134,25 +5125,3 @@ class Choose(Op): ...@@ -5134,25 +5125,3 @@ class Choose(Op):
a = inputs[0] a = inputs[0]
choice = inputs[1] choice = inputs[1]
z[0] = numpy.choose(a, choice, mode=self.mode) z[0] = numpy.choose(a, choice, mode=self.mode)
"""
import theano
from theano import tensor as T
from theano import function
from theano.tensor.basic import choose
import numpy as np
x = T.tensor4(dtype='int64')
y = T.tensor4(dtype='int64')
z = T.tensor4(dtype='int64')
p = T.tensor4(dtype='int64')
w = choose(x,(y,z,p))
f = function([x,y,z,p], w)
a = np.array([0, 1, 2]).reshape((3,1,1,1))
c1 = np.array([1, 2, 3]).reshape((1,3,1,1))
c2 = np.array([-1, -2, -3, -4, -5]).reshape((1,1,5,1))
c3 = np.array([1, 2, 4]).reshape((1,1,1,3))
"""
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论