提交 3a6e768b authored 作者: Iban Harlouchet's avatar Iban Harlouchet

Commit 3

上级 d42672be
...@@ -1031,14 +1031,11 @@ class Unique(theano.Op): ...@@ -1031,14 +1031,11 @@ class Unique(theano.Op):
outputs.append(output0) outputs.append(output0)
typ = basic.TensorType(broadcastable=[False], dtype='int64') typ = basic.TensorType(broadcastable=[False], dtype='int64')
if self.return_index : if self.return_index :
output1 = typ() outputs.append(typ())
outputs.append(output1)
if self.return_inverse : if self.return_inverse :
output2 = typ() outputs.append(typ())
outputs.append(output2)
if self.return_counts : if self.return_counts :
output3 = typ() outputs.append(typ())
outputs.append(output3)
return theano.Apply(self, [x], outputs) return theano.Apply(self, [x], outputs)
......
...@@ -667,8 +667,16 @@ class test_Unique(utt.InferShapeTester): ...@@ -667,8 +667,16 @@ class test_Unique(utt.InferShapeTester):
def setUp(self): def setUp(self):
super(test_Unique, self).setUp() super(test_Unique, self).setUp()
self.op_class = Unique self.op_class = Unique
self.ops = [Unique(), Unique(True), Unique(True, True), self.ops = [Unique(),
Unique(False, True)]#, Unique(True, True, True)] Unique(True),
Unique(False, True),
Unique(True, True)]
if np.__version__ >= "1.9.0" :
self.ops.extend([
Unique(False, False, True),
Unique(True, False, True),
Unique(False, True, True),
Unique(True, True, True)])
def test_basic_vector(self): def test_basic_vector(self):
""" """
...@@ -677,10 +685,16 @@ class test_Unique(utt.InferShapeTester): ...@@ -677,10 +685,16 @@ class test_Unique(utt.InferShapeTester):
""" """
x = theano.tensor.vector() x = theano.tensor.vector()
inp = np.asarray([2,1,3,2], dtype=config.floatX) inp = np.asarray([2,1,3,2], dtype=config.floatX)
list_outs_expected = [[[1., 2., 3.]], list_outs_expected = [[np.unique(inp)],
[[1., 2., 3.], [1, 0, 2]], np.unique(inp, True),
[[1., 2., 3.], [1, 0, 2], [1, 0, 2, 1]], np.unique(inp, False, True),
[[1., 2., 3.], [1, 0, 2, 1]]] np.unique(inp, True, True)]
if np.__version__ >= "1.9.0" :
list_outs_expected.extend([
np.unique(inp, False, False, True),
np.unique(inp, True, False, True),
np.unique(inp, False, True, True),
np.unique(inp, True, True, True)])
for op, outs_expected in zip(self.ops, list_outs_expected) : for op, outs_expected in zip(self.ops, list_outs_expected) :
f = theano.function(inputs=[x], outputs=op(x, return_list=True)) f = theano.function(inputs=[x], outputs=op(x, return_list=True))
outs = f(inp) outs = f(inp)
...@@ -697,10 +711,16 @@ class test_Unique(utt.InferShapeTester): ...@@ -697,10 +711,16 @@ class test_Unique(utt.InferShapeTester):
""" """
x = theano.tensor.matrix() x = theano.tensor.matrix()
inp = np.asarray([[2, 1], [3, 2], [2, 3]], dtype=config.floatX) inp = np.asarray([[2, 1], [3, 2], [2, 3]], dtype=config.floatX)
list_outs_expected = [[[1., 2., 3.]], list_outs_expected = [[np.unique(inp)],
[[1., 2., 3.], [1, 0, 2]], np.unique(inp, True),
[[1., 2., 3.], [1, 0, 2], [1, 0, 2, 1, 1, 2]], np.unique(inp, False, True),
[[1., 2., 3.], [1, 0, 2, 1, 1, 2]]] np.unique(inp, True, True)]
if np.__version__ >= "1.9.0" :
list_outs_expected.extend([
np.unique(inp, False, False, True),
np.unique(inp, True, False, True),
np.unique(inp, False, True, True),
np.unique(inp, True, True, True)])
for op, outs_expected in zip(self.ops, list_outs_expected): for op, outs_expected in zip(self.ops, list_outs_expected):
f = theano.function(inputs=[x], outputs=op(x, return_list=True)) f = theano.function(inputs=[x], outputs=op(x, return_list=True))
outs = f(inp) outs = f(inp)
...@@ -715,12 +735,22 @@ class test_Unique(utt.InferShapeTester): ...@@ -715,12 +735,22 @@ class test_Unique(utt.InferShapeTester):
""" """
Testing the infer_shape with a vector. Testing the infer_shape with a vector.
""" """
# TODO x = theano.tensor.vector()
pass for op in self.ops :
self._compile_and_check([x],
[op(x)],
[np.asarray(np.array([2,1,3,2]),
dtype=config.floatX)],
self.op_class)
def test_infer_shape_matrix(self): def test_infer_shape_matrix(self):
""" """
Testing the infer_shape with a vector. Testing the infer_shape with a vector.
""" """
# TODO x = theano.tensor.matrix()
pass self._compile_and_check([x],
[self.op(x)],
[np.asarray(np.array([[2, 1], [3, 2],[2, 3]]),
dtype=config.floatX)],
self.op_class)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论