提交 891236a8 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3176 from mjwillson/CudaNdarray_reshape_zero_dims

Remove the restriction on zero target dimensions when reshaping a CudaNdarray
...@@ -857,8 +857,8 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape) ...@@ -857,8 +857,8 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape)
free(rval_dims); free(rval_dims);
return NULL; return NULL;
} }
if(rval_dims[i]<=0){ if(rval_dims[i]<0){
PyErr_Format(PyExc_ValueError, "Reshape has invalid dimension %i (must be >0)",rval_dims[i]); PyErr_Format(PyExc_ValueError, "Reshape has invalid dimension %i (must be >=0)",rval_dims[i]);
free(rval_dims); free(rval_dims);
return NULL; return NULL;
} }
......
...@@ -374,6 +374,11 @@ def test_reshape(): ...@@ -374,6 +374,11 @@ def test_reshape():
except ValueError: except ValueError:
pass pass
# Test zero dimensions are allowed
x = T.vector('x')
f_reshp = theano.function([x], x.reshape((0,100)), mode=mode_with_gpu)
assert f_reshp(numpy.ndarray((0,), dtype='float32')).shape == (0,100)
def test_alloc_empty(): def test_alloc_empty():
# Test that we allocated correctly # Test that we allocated correctly
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论