提交 0def13ef authored 作者: James Bergstra's avatar James Bergstra

fixed a bug in the setting of output array flags in DimShuffle.c_code

上级 2a55ea5f
......@@ -224,15 +224,19 @@ class DimShuffle(Op):
for i in xrange(nd_out-2,-1, -1):
strides_statements.append("if (strides[%(i)s] == 0) strides[%(i)s] = strides[%(i)s+1] * dimensions[%(i)s+1]"%dict(i=str(i)))
#
# PyObject* PyArray_New(PyTypeObject* subtype, int nd, npy_intp* dims, int type_num,
# npy_intp* strides, void* data, int itemsize, int flags, PyObject* obj)
#
close_bracket = [
#create a new array,
('%(res)s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
'' + str(nd_out) + ', dimensions, '
'PyArray_TYPE(%(basename)s), strides, '
'%(basename)s->data, %(basename)s->descr->elsize, '
'%(basename)s->data, PyArray_ITEMSIZE(%(basename)s), '
#borrow only the writable flag from the base
# the NPY_OWNDATA flag will default to 0.
'PyArray_ISWRITEABLE(%(basename)s), NULL)'),
'(NPY_WRITEABLE*PyArray_ISWRITEABLE(%(basename)s)), 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
......
import sys
import numpy, theano
from theano import tensor
def test_bug_2009_06_02():
y = tensor.lvector()
f = theano.function([y], tensor.stack(y[0] / 2))
y = tensor.lvector('y')
#f = theano.function([y], tensor.stack(y[0] / 2))
#f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1)))
f = theano.function([y], tensor.int_div(tensor.DimShuffle(y[0].broadcastable, ['x'])(y[0]), 2))
sys.stdout.flush()
print f(numpy.ones(1) * 3)
#z = tensor.lscalar('z')
#f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2)
print f(numpy.ones(1) * 2)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论