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

merge

......@@ -1412,7 +1412,7 @@ CudaNdarray_setitem(PyObject *o, PyObject *key, PyObject *v)
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_setitem: syncing structure to device failed");
Py_DECREF(rval);
return NULL;
return -1;
}
CudaNdarray *viewCopyForComparison =
......
......@@ -226,7 +226,12 @@ def local_gpu_sum(node):
gsum=GpuSum(reduce_mask)
pattern=(''.join(str(i) for i in reduce_mask))
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:
# Try to make a simpler pattern based on reshaping
......@@ -253,9 +258,13 @@ def local_gpu_sum(node):
reshaped_x = x.reshape(tensor.stack(*new_in_shp))
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]]))
return [unreshaped_sum]
if unreshaped_sum.type == node.outputs[0].type:
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
@register_opt()
......
......@@ -484,12 +484,12 @@ class TensorType(Type):
return False
if 'int' in str(a.dtype):
return numpy.all(a==b)
elif a.shape == (): #for comparing scalars, use broadcasting.
# Note: according to James B, there was a reason for the
# following two lines, that may seem weird at first glance.
# If someone can figure out what it is, please say it here!
ones = numpy.ones(2)
return _allclose(ones * a, ones*b)
#elif a.shape == (): #for comparing scalars, use broadcasting.
## Note: according to James B, there was a reason for the
## following two lines, that may seem weird at first glance.
## If someone can figure out what it is, please say it here!
#ones = numpy.ones(2)
#return _allclose(ones * a, ones*b) ### dtype handling is wrong here
else:
cmp = _allclose(a, b)
if cmp:
......
......@@ -63,3 +63,15 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
rng = numpy.random
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论