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

small update

上级 dd018d55
......@@ -770,7 +770,7 @@ Creating Tensor
if mode=wrap, values in a (and thus Ba) may be any (signed) integer; modular arithmetic is used to map integers outside the range [0, n-1] back into that range; and then the new array is constructed as above;
if mode=clip, values in a (and thus Ba) may be any (signed) integer; negative integers are mapped to 0; values greater than n-1 are mapped to n-1; and then the new array is constructed as above.
Parameters :
Parameters :
a : int array
This array must contain integers in [0, n-1], where n is the number of choices, unless mode=wrap or mode=clip, in which cases any integers are permissible.
choices : sequence of arrays
......@@ -782,10 +782,10 @@ Creating Tensor
‘raise’ : an exception is raised
‘wrap’ : value becomes value mod n
‘clip’ : values < 0 are mapped to 0, values > n-1 are mapped to n-1
Returns :
Returns :
merged_array : array
The merged result.
Raises :
Raises :
ValueError: shape mismatch
If a and each choice array are not all broadcastable to the same shape.
......
......@@ -5095,19 +5095,13 @@ def swapaxes(y, axis1, axis2):
def choose(a, choices, out=None, mode='raise'):
# This is done to keep the same function signature then NumPy.
assert out is None
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):
return (type(self) == type(other) and self.props() == other.props())
class Choose(Op):
__props__ = ('mode',)
def infer_shape(self, node, shapes):
if isinstance(node.inputs[1], tuple):
......@@ -5118,9 +5112,6 @@ class Choose(Op):
else:
return[(shapes[0])]
def props(self):
return self.mode
def make_node(self, a, choices):
from theano import typed_list
a = as_tensor_variable(a)
......@@ -5133,26 +5124,4 @@ class Choose(Op):
def perform(self, node, inputs, (z, )):
a = inputs[0]
choice = inputs[1]
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))
"""
z[0] = numpy.choose(a, choice, mode=self.mode)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论