提交 a9ea825f authored 作者: Frederic Bastien's avatar Frederic Bastien

Add a_tensor.squeeze() interface as numpy

上级 71dd2984
...@@ -286,6 +286,20 @@ class SqueezeTester(utt.InferShapeTester): ...@@ -286,6 +286,20 @@ class SqueezeTester(utt.InferShapeTester):
utt.verify_grad(self.op, [data]) utt.verify_grad(self.op, [data])
def test_var_interface(self):
# same as test_op, but use a_theano_var.squeeze.
for shape, broadcast in zip(self.shape_list, self.broadcast_list):
data = numpy.random.random(size=shape).astype(theano.config.floatX)
variable = tensor.TensorType(theano.config.floatX, broadcast)()
f = theano.function([variable], variable.squeeze())
expected = numpy.squeeze(data)
tested = f(data)
assert tested.shape == expected.shape
assert numpy.allclose(tested, expected)
class TestRepeatOp(utt.InferShapeTester): class TestRepeatOp(utt.InferShapeTester):
def _possible_axis(self, ndim): def _possible_axis(self, ndim):
......
...@@ -585,7 +585,19 @@ class _tensor_py_operators: ...@@ -585,7 +585,19 @@ class _tensor_py_operators:
def choose(self, a, choices, out=None, mode='raise'): def choose(self, a, choices, out=None, mode='raise'):
"""Construct an array from an index array and a set of arrays to choose from.""" """Construct an array from an index array and a set of arrays to choose from."""
return theano.tensor.basic.choose(self, a, choices, out=None, mode='raise') return theano.tensor.basic.choose(self, a, choices, out=None,
mode='raise')
def squeeze(self):
"""Remove broadcastable dimensions from
the shape of an array.
It returns the input array, but with the
broadcastable dimensions removed. This is
always `x` itself or a view into `x`.
"""
return theano.tensor.extra_ops.squeeze(self)
class TensorVariable(_tensor_py_operators, Variable): class TensorVariable(_tensor_py_operators, Variable):
"""Subclass to add the tensor operators to the basic `Variable` class.""" """Subclass to add the tensor operators to the basic `Variable` class."""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论