fixed flag update in DimShuffles c implementation

上级 f1d27e59
...@@ -207,25 +207,33 @@ class DimShuffle(Op): ...@@ -207,25 +207,33 @@ class DimShuffle(Op):
if self.inplace: if self.inplace:
get_base = ['{ PyArrayObject * base = %(input)s', 'Py_INCREF((PyObject*)base)'] get_output = ['{ PyArrayObject * base = %(input)s', 'Py_INCREF((PyObject*)base)']
else: else:
get_base = [('{ PyArrayObject * base = (PyArrayObject*)PyArray_FromAny((PyObject*)%(input)s, NULL,' get_output = [('{ PyArrayObject * base = (PyArrayObject*)PyArray_FromAny((PyObject*)%(input)s, NULL,'
'0, 0, NPY_ALIGNED|NPY_ENSURECOPY, NULL)')] '0, 0, NPY_ALIGNED|NPY_ENSURECOPY, NULL)')]
alloc_output = [('%(res)s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
'' + str(nd_out) + ', dimensions, ' close_bracket = [
'PyArray_TYPE(base), strides, ' #create a new array,
'base->data, base->descr->elsize, ' ('%(res)s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
'PyArray_FLAGS(base), NULL)'), '' + str(nd_out) + ', dimensions, '
'%(res)s->base = (PyObject*)base', 'PyArray_TYPE(base), strides, '
'base->data, base->descr->elsize, '
#borrow only the writable flag from the base
# the NPY_OWNDATA flag will default to 0.
'PyArray_ISWRITEABLE(base), NULL)'),
#recalculate flags: CONTIGUOUS, FORTRAN, ALIGNED
'PyArray_UpdateFlags(%(res)s, NPY_UPDATE_ALL)',
#we are making a view in both inplace and non-inplace cases
'%(res)s->base = (PyObject*)base',
'}'] '}']
full_code = statements(check_input_nd full_code = statements(check_input_nd
+ clear_output + clear_output
+ shape_statements + shape_statements
+ strides_statements + strides_statements
+ get_base + get_output
+ alloc_output) + close_bracket)
if 0: if 0:
print 'C_CODE' print 'C_CODE'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论