提交 33bd7278 authored 作者: Frederic Bastien's avatar Frederic Bastien

fix the last commit in DEBUG_MODE.

Make the copy to the cpu from the gpu work for empty cuda array. Make the perform of Sum work in python when their is more then 1 dimenssions
上级 de9cde80
...@@ -203,6 +203,18 @@ static PyMemberDef CudaNdarray_members[] = ...@@ -203,6 +203,18 @@ static PyMemberDef CudaNdarray_members[] =
PyObject * CudaNdarray_CreateArrayObj(CudaNdarray * self) PyObject * CudaNdarray_CreateArrayObj(CudaNdarray * self)
{ {
int verbose = 0; int verbose = 0;
if(self->nd>=0 && CudaNdarray_SIZE(self)==0){
npy_intp * npydims = (npy_intp*)malloc(self->nd * sizeof(npy_intp));
assert (npydims);
for (int i = 0; i < self->nd; ++i) npydims[i] = (npy_intp)(CudaNdarray_HOST_DIMS(self)[i]);
PyObject * rval = PyArray_SimpleNew(self->nd, npydims, REAL_TYPENUM);
free(npydims);
if (!rval){
return NULL;
}
assert (PyArray_ITEMSIZE(rval) == sizeof(real));
return rval;
}
if ((self->nd < 0) || (self->devdata == 0)) if ((self->nd < 0) || (self->devdata == 0))
{ {
PyErr_SetString(PyExc_ValueError, "can't copy from un-initialized CudaNdarray"); PyErr_SetString(PyExc_ValueError, "can't copy from un-initialized CudaNdarray");
......
...@@ -35,8 +35,9 @@ def test_sum(): ...@@ -35,8 +35,9 @@ def test_sum():
TODO: test with broadcast TODO: test with broadcast
""" """
for shape, pattern in [((0,),[0]),((5,),[0]), for shape, pattern in [((0,),[0]),((5,),[0]),
((5,4),[0,1]),((33,31),[0,1]),((5,4),[1]),((5,4),[0]),#need something bigger then 32 for some opt test. ((0,0),[0,1]),((1,0),[0,1]),((5,4),[0,1]),((33,31),[0,1]),((5,4),[1]),((5,4),[0]),#need something bigger then 32 for some opt test.
((5,4,3),[0]),((5,4,3),[0,1]),((5,4,3),[2]),((5,4,3),[1,2]),((5,4,3),[0,1,2]), ((5,4,3),[0]),((5,4,3),[0,1]),((5,4,3),[2]),((5,4,3),[1,2]),((5,4,3),[0,1,2]),
((0,0,0,0),[0,1,2,3]),
((5,4,3,20),[2,3]), ((5,4,3,2),[0,1,2,3]), ((5,4,3,2),[0,2,3]),((5,4,3,2),[1,2,3])]: ((5,4,3,20),[2,3]), ((5,4,3,2),[0,1,2,3]), ((5,4,3,2),[0,2,3]),((5,4,3,2),[1,2,3])]:
a = tensor.TensorType('float32',(False,)*len(shape))() a = tensor.TensorType('float32',(False,)*len(shape))()
b = T.Sum(pattern)(a) b = T.Sum(pattern)(a)
......
...@@ -873,6 +873,7 @@ class CAReduce(Op): ...@@ -873,6 +873,7 @@ class CAReduce(Op):
if variable.shape[dimension] == 0: if variable.shape[dimension] == 0:
if hasattr(self.scalar_op, 'identity'): if hasattr(self.scalar_op, 'identity'):
variable = self.scalar_op.identity variable = self.scalar_op.identity
break
else: else:
raise ValueError("Input (%s) has zero-size on axis %s, but self.scalar_op (%s) has no attribute 'identity'" % (variable, dimension, self.scalar_op)) raise ValueError("Input (%s) has zero-size on axis %s, but self.scalar_op (%s) has no attribute 'identity'" % (variable, dimension, self.scalar_op))
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论