提交 59a43850 authored 作者: Frederic Bastien's avatar Frederic Bastien

make theano raise an error if ndarray are not aligned and make a test for it.

上级 0998c9c4
......@@ -606,6 +606,10 @@ class TensorType(Type):
PyErr_SetString(PyExc_ValueError, "expected an ndarray");
%(fail)s
}
if (!PyArray_ISALIGNED(py_%(name)s)) {
PyErr_SetString(PyExc_ValueError, "expected an aligned array");
%(fail)s
}
type_num_%(name)s = ((PyArrayObject*)py_%(name)s)->descr->type_num; //we expect %(type_num)s
if (type_num_%(name)s != %(type_num)s) {
PyErr_SetString(PyExc_ValueError, "expected %(type_num)s");
......@@ -654,7 +658,7 @@ class TensorType(Type):
def c_code_cache_version(self):
scalar_version = scal.Scalar(self.dtype).c_code_cache_version()
if scalar_version:
return (2,) + scalar_version
return (3,) + scalar_version
else:
return ()
......
......@@ -2688,6 +2688,25 @@ def test_mod_compile():
f = theano.function([x,y],out)
def test_unalign():
a = numpy.empty(1e6, dtype="b1,f8")['f1']
b = numpy.empty(1e6, dtype="b1,f8")['f1']
assert not a.flags.aligned
assert not b.flags.aligned
a[:] = numpy.random.rand(len(a))
b[:] = numpy.random.rand(len(b))
out_numpy = 2*a + 3*b
av,bv = tensor.vectors('ab')
f = theano.function([av,bv],2*av+3*bv)
f.maker.env.toposort()
try:
out_theano = f(a,b)
except ValueError:
pass
else:
raise Exception("Expected an error from Theano!")
if __name__ == '__main__':
if 1:
unittest.main()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论