提交 649c1be7 authored 作者: James Bergstra's avatar James Bergstra

merge

...@@ -1412,7 +1412,7 @@ CudaNdarray_setitem(PyObject *o, PyObject *key, PyObject *v) ...@@ -1412,7 +1412,7 @@ CudaNdarray_setitem(PyObject *o, PyObject *key, PyObject *v)
{ {
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_setitem: syncing structure to device failed"); PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_setitem: syncing structure to device failed");
Py_DECREF(rval); Py_DECREF(rval);
return NULL; return -1;
} }
CudaNdarray *viewCopyForComparison = CudaNdarray *viewCopyForComparison =
......
...@@ -226,7 +226,12 @@ def local_gpu_sum(node): ...@@ -226,7 +226,12 @@ def local_gpu_sum(node):
gsum=GpuSum(reduce_mask) gsum=GpuSum(reduce_mask)
pattern=(''.join(str(i) for i in reduce_mask)) pattern=(''.join(str(i) for i in reduce_mask))
if hasattr(gsum, 'c_code_reduce_%s'%pattern): if hasattr(gsum, 'c_code_reduce_%s'%pattern):
return [host_from_gpu(gsum(gpu_from_host(x)))] rval = host_from_gpu(gsum(gpu_from_host(x)))
if rval.type == node.outputs[0].type:
return [rval]
else:
print >> sys.stderr, "WARNING: local_gpu_sum got type wrong"
return None
else: else:
# Try to make a simpler pattern based on reshaping # Try to make a simpler pattern based on reshaping
...@@ -253,7 +258,11 @@ def local_gpu_sum(node): ...@@ -253,7 +258,11 @@ def local_gpu_sum(node):
reshaped_x = x.reshape(tensor.stack(*new_in_shp)) reshaped_x = x.reshape(tensor.stack(*new_in_shp))
sum_reshaped_x = host_from_gpu(new_gsum(gpu_from_host(reshaped_x))) sum_reshaped_x = host_from_gpu(new_gsum(gpu_from_host(reshaped_x)))
unreshaped_sum = sum_reshaped_x.reshape(tensor.stack(*shape_of[node.outputs[0]])) unreshaped_sum = sum_reshaped_x.reshape(tensor.stack(*shape_of[node.outputs[0]]))
if unreshaped_sum.type == node.outputs[0].type:
return [unreshaped_sum] return [unreshaped_sum]
else:
print >> sys.stderr, "WARNING: local_gpu_sum got type wrong"
return None
raise Exception("GpuSum don't have implemented the pattern",pattern) raise Exception("GpuSum don't have implemented the pattern",pattern)
return False return False
......
...@@ -484,12 +484,12 @@ class TensorType(Type): ...@@ -484,12 +484,12 @@ class TensorType(Type):
return False return False
if 'int' in str(a.dtype): if 'int' in str(a.dtype):
return numpy.all(a==b) return numpy.all(a==b)
elif a.shape == (): #for comparing scalars, use broadcasting. #elif a.shape == (): #for comparing scalars, use broadcasting.
# Note: according to James B, there was a reason for the ## Note: according to James B, there was a reason for the
# following two lines, that may seem weird at first glance. ## following two lines, that may seem weird at first glance.
# If someone can figure out what it is, please say it here! ## If someone can figure out what it is, please say it here!
ones = numpy.ones(2) #ones = numpy.ones(2)
return _allclose(ones * a, ones*b) #return _allclose(ones * a, ones*b) ### dtype handling is wrong here
else: else:
cmp = _allclose(a, b) cmp = _allclose(a, b)
if cmp: if cmp:
......
...@@ -63,3 +63,15 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs): ...@@ -63,3 +63,15 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
rng = numpy.random rng = numpy.random
T.verify_grad(op, pt, n_tests, rng, *args, **kwargs) T.verify_grad(op, pt, n_tests, rng, *args, **kwargs)
#
# This supports the following syntax:
#
# try:
# verify_grad(...)
# except verify_grad.E_grad, e:
# print e.num_grad.gf
# print e.analytic_grad
# ...
#
#
verify_grad.E_grad = T.verify_grad.E_grad
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论