提交 8a736df5 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #4033 from nouiz/py3_repr

Fix CudaNdarray repr in python 3 and a crash.
...@@ -2050,6 +2050,7 @@ class _Linker(gof.link.LocalLinker): ...@@ -2050,6 +2050,7 @@ class _Linker(gof.link.LocalLinker):
# shouldn't have put it into the list in # shouldn't have put it into the list in
# the first place # the first place
thunk_py = None thunk_py = None
thunks_py[i] = None
except Exception as e: except Exception as e:
# I think that only 1 optimization can # I think that only 1 optimization can
# insert a given apply node. If that is not True, # insert a given apply node. If that is not True,
......
...@@ -1143,6 +1143,8 @@ class GpuCorrMM_gradWeights(BaseGpuCorrMM): ...@@ -1143,6 +1143,8 @@ class GpuCorrMM_gradWeights(BaseGpuCorrMM):
raise ValueError('shape must be given if subsample != (1, 1)' raise ValueError('shape must be given if subsample != (1, 1)'
' or border_mode == "half"') ' or border_mode == "half"')
height_width = [shape[0], shape[1]] height_width = [shape[0], shape[1]]
assert shape[0].ndim == 0
assert shape[1].ndim == 0
else: else:
height_width = [] height_width = []
...@@ -1201,6 +1203,9 @@ class GpuCorrMM_gradInputs(BaseGpuCorrMM): ...@@ -1201,6 +1203,9 @@ class GpuCorrMM_gradInputs(BaseGpuCorrMM):
if self.subsample != (1, 1) and shape is None: if self.subsample != (1, 1) and shape is None:
raise ValueError('shape must be given if subsample != (1, 1)') raise ValueError('shape must be given if subsample != (1, 1)')
height_width = [shape[0], shape[1]] if self.subsample != (1, 1) else [] height_width = [shape[0], shape[1]] if self.subsample != (1, 1) else []
if height_width:
assert shape[0].ndim == 0
assert shape[1].ndim == 0
broadcastable = [topgrad.type.broadcastable[0], kern.type.broadcastable[1], broadcastable = [topgrad.type.broadcastable[0], kern.type.broadcastable[1],
False, False] False, False]
......
...@@ -3066,6 +3066,12 @@ PyObject *CudaNdarray_repr(PyObject *self) ...@@ -3066,6 +3066,12 @@ PyObject *CudaNdarray_repr(PyObject *self)
")"); ")");
Py_DECREF(str); Py_DECREF(str);
Py_DECREF(np_object); Py_DECREF(np_object);
#if PY_MAJOR_VERSION >= 3
// In Python 3 PyString_FromFormat return a Bytes object
PyObject* out2 = PyObject_Str(out);
Py_DECREF(out);
return out2;
#endif
return out; return out;
} }
......
...@@ -2767,10 +2767,11 @@ def local_abstractconv_gemm(node): ...@@ -2767,10 +2767,11 @@ def local_abstractconv_gemm(node):
# GpuConv does not always store information on the batchsize and # GpuConv does not always store information on the batchsize and
# channels, though, so we only use what information we have.) # channels, though, so we only use what information we have.)
if ((subsample == (1, 1)) and if ((subsample == (1, 1)) and
(node.op.imshp is not None) and (node.op.imshp is not None) and
(None not in node.op.imshp[-2:]) and (None not in node.op.imshp[-2:]) and
(node.op.kshp is not None) and (node.op.kshp is not None) and
(None not in node.op.kshp)): (None not in node.op.kshp) and
border_mode != "half"):
# we know the kernel and output size # we know the kernel and output size
prod1 = node.op.kshp[0] * node.op.kshp[1] prod1 = node.op.kshp[0] * node.op.kshp[1]
prod2 = ((node.op.imshp[-2] - node.op.kshp[0] + 1) * prod2 = ((node.op.imshp[-2] - node.op.kshp[0] + 1) *
......
...@@ -859,6 +859,20 @@ class Test_GpuReshape(test_opt.Test_Reshape): ...@@ -859,6 +859,20 @@ class Test_GpuReshape(test_opt.Test_Reshape):
self.op = basic_ops.GpuReshape self.op = basic_ops.GpuReshape
def test_local_abstractconv_gemm():
""" We test it here as this is the optimization only that we test.
This test gh-4036"""
image = tensor.ftensor4()
W = tensor.ftensor4()
conv = tensor.nnet.conv2d(image,
W,
input_shape=(1, 32, 32, 32),
filter_shape=(32, 32, 3, 3),
border_mode='half')
f = theano.function([image, W], [conv], mode=mode_with_gpu)
f(numpy.random.rand(1, 32, 32, 32).astype('float32'),
numpy.random.rand(32, 32, 3, 3).astype('float32'))
if __name__ == '__main__': if __name__ == '__main__':
test_gpualloc() test_gpualloc()
test_opt_gpujoin_onlyajoin() test_opt_gpujoin_onlyajoin()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论