提交 13bc71b3 authored 作者: notoraptor's avatar notoraptor

Update transposition param and remove useless exceptions.

上级 00297272
...@@ -27,21 +27,16 @@ int gpu_dimshuffle(PyGpuArrayObject* input, PyGpuArrayObject** out, PARAMS_TYPE* ...@@ -27,21 +27,16 @@ int gpu_dimshuffle(PyGpuArrayObject* input, PyGpuArrayObject** out, PARAMS_TYPE*
/** Do shuffle. **/ /** Do shuffle. **/
new_order = (npy_int64*) PyArray_DATA(params->_new_order); new_order = (npy_int64*) PyArray_DATA(params->_new_order);
transposition = (unsigned int*) malloc(nd_in * sizeof(unsigned int)); /* Type of params->transposition (npy_uint32) should be an alias of unsigned int
* on platforms supported by Theano. */
transposition = (unsigned int*) PyArray_DATA(params->transposition);
sh = (size_t*) malloc(nd_out * sizeof(size_t)); sh = (size_t*) malloc(nd_out * sizeof(size_t));
if (transposition == NULL || sh == NULL) { if (sh == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
free(transposition);
free(sh);
return 1; return 1;
} }
for (npy_intp i = 0; i < nd_in; ++i) {
transposition[i] = ((npy_int64*) PyArray_DATA(params->transposition))[i];
}
tmp = pygpu_transpose(input, transposition); tmp = pygpu_transpose(input, transposition);
if (!tmp) { if (!tmp) {
PyErr_SetString(PyExc_RuntimeError, "GpuDimShuffle: unable to transpose input.");
free(transposition);
free(sh); free(sh);
return 1; return 1;
} }
...@@ -56,21 +51,18 @@ int gpu_dimshuffle(PyGpuArrayObject* input, PyGpuArrayObject** out, PARAMS_TYPE* ...@@ -56,21 +51,18 @@ int gpu_dimshuffle(PyGpuArrayObject* input, PyGpuArrayObject** out, PARAMS_TYPE*
} }
*out = pygpu_reshape(tmp, nd_out, sh, GA_ANY_ORDER, 1, -1); *out = pygpu_reshape(tmp, nd_out, sh, GA_ANY_ORDER, 1, -1);
Py_DECREF(tmp); Py_DECREF(tmp);
free(transposition);
free(sh); free(sh);
/** End shuffle. **/
if (*out == NULL) { if (*out == NULL) {
PyErr_SetString(PyExc_RuntimeError, "GpuDimShuffle: unable to reshape output.");
return 1; return 1;
} }
/** End shuffle. **/
if (!params->inplace) { if (!params->inplace) {
tmp = pygpu_copy(*out, GA_ANY_ORDER); tmp = pygpu_copy(*out, GA_ANY_ORDER);
Py_DECREF(*out); Py_DECREF(*out);
if (!tmp) { if (!tmp) {
PyErr_SetString(PyExc_RuntimeError, "GpuDimShuffle: unable to copy output.");
*out = NULL; *out = NULL;
return 1; return 1;
} }
......
...@@ -99,5 +99,6 @@ int cpu_dimshuffle(PyArrayObject* input, PyArrayObject** res, PARAMS_TYPE* param ...@@ -99,5 +99,6 @@ int cpu_dimshuffle(PyArrayObject* input, PyArrayObject** res, PARAMS_TYPE* param
free(strides); free(strides);
free(dimensions); free(dimensions);
return 0; return 0;
} }
...@@ -139,7 +139,7 @@ class DimShuffle(COp): ...@@ -139,7 +139,7 @@ class DimShuffle(COp):
# because of importation issues related to TensorType. # because of importation issues related to TensorType.
return ParamsType(input_broadcastable=TensorType(dtype='bool', broadcastable=(False,)), return ParamsType(input_broadcastable=TensorType(dtype='bool', broadcastable=(False,)),
_new_order=theano.tensor.lvector, _new_order=theano.tensor.lvector,
transposition=theano.tensor.lvector, transposition=TensorType(dtype='uint32', broadcastable=(False,)),
inplace=theano.scalar.bool) inplace=theano.scalar.bool)
@property @property
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论