提交 703d535a authored 作者: lamblin's avatar lamblin

Merge pull request #1173 from nouiz/fix_crash_roll

Fix crash tensor.roll(Var, iscalar) reported by Jeremiah Lowin.
......@@ -105,6 +105,8 @@ Brian Vandenberg emailed `installation instructions on Gentoo
<http://groups.google.com/d/msg/theano-dev/-8WCMn2FMR0/bJPasoZXaqoJ>`_,
focusing on how to install the appropriate dependencies.
Nicolas Pinto provide `ebuild scripts <https://github.com/npinto/sekyfsr-gentoo-overlay/tree/master/sci-libs/Theano>`_.
Alternative installation on Mandriva 2010.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -89,6 +89,7 @@ class HostFromGpu(GpuOp):
out = outputs[0]
fail = sub['fail']
return """
Py_XDECREF(%(out)s);
%(out)s = (PyArrayObject *) CudaNdarray_CreateArrayObj(%(inp)s);
if(!%(out)s){
%(fail)s;
......@@ -96,7 +97,7 @@ class HostFromGpu(GpuOp):
""" % locals()
def c_code_cache_version(self):
return (1,)
return (2,)
host_from_gpu = HostFromGpu()
......
......@@ -5632,8 +5632,8 @@ def roll(x, shift, axis=None):
end_list = ([allslice] * axis + [end_slice] +
[allslice] * (x.ndim - axis - 1))
return join(axis,
Subtensor(front_list)(x),
Subtensor(end_list)(x))
x.__getitem__(tuple(front_list)),
x.__getitem__(tuple(end_list)))
@constructor
......
......@@ -3625,43 +3625,44 @@ class T_Join_and_Split(unittest.TestCase):
def test_roll(self):
# Test simple 1D example
a = self.shared(numpy.array([1, 2, 3, 4, 5, 6], dtype=self.floatX))
b = roll(a, 2)
want = numpy.array([5, 6, 1, 2, 3, 4])
out = theano.function([], b)()
for get_shift in [lambda a:a, lambda x:theano.shared(x)]:
# Test simple 1D example
a = self.shared(numpy.array([1, 2, 3, 4, 5, 6], dtype=self.floatX))
b = roll(a, get_shift(2))
want = numpy.array([5, 6, 1, 2, 3, 4])
out = theano.function([], b)()
assert (out == want).all()
assert (out == want).all()
# Test simple 1D example with explicit 0 axis
b = roll(a, -1, 0)
want = numpy.array([2, 3, 4, 5, 6, 1])
out = theano.function([], b)()
# Test simple 1D example with explicit 0 axis
b = roll(a, get_shift(-1), 0)
want = numpy.array([2, 3, 4, 5, 6, 1])
out = theano.function([], b)()
assert (out == want).all()
assert (out == want).all()
# Test 2D example - ensure that behavior matches numpy.roll behavior
a = self.shared(numpy.arange(21).reshape((3, 7)).astype(self.floatX))
b = roll(a, -2, 1)
# Test 2D example - ensure that behavior matches numpy.roll behavior
a = self.shared(numpy.arange(21).reshape((3, 7)).astype(self.floatX))
b = roll(a, get_shift(-2), 1)
want = numpy.roll(a.get_value(borrow=True), -2, 1)
out = theano.function([], b)()
want = numpy.roll(a.get_value(borrow=True), -2, 1)
out = theano.function([], b)()
assert (out == want).all()
assert (out == want).all()
# Test rolling on axis 0
want = numpy.roll(a.get_value(borrow=True), -2, 0)
b = roll(a, -2, 0)
out = theano.function([], b)()
# Test rolling on axis 0
want = numpy.roll(a.get_value(borrow=True), -2, 0)
b = roll(a, get_shift(-2), 0)
out = theano.function([], b)()
assert (out == want).all()
assert (out == want).all()
# Test rolling on default axis with ndim > 1
want = numpy.roll(a.get_value(borrow=True), 2)
b = roll(a, 2)
out = theano.function([], b)()
# Test rolling on default axis with ndim > 1
want = numpy.roll(a.get_value(borrow=True), 2)
b = roll(a, get_shift(2))
out = theano.function([], b)()
assert (out == want).all()
assert (out == want).all()
def test_stack_vector(self):
a = self.shared(numpy.array([1, 2, 3], dtype=self.floatX))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论