Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
872ead68
提交
872ead68
authored
10月 25, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1025 from nouiz/err_msg_unalign
Err msg unalign
上级
1bb10871
7363cbca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
13 行删除
+48
-13
basic.py
theano/tensor/basic.py
+26
-3
test_basic.py
theano/tensor/tests/test_basic.py
+22
-10
没有找到文件。
theano/tensor/basic.py
浏览文件 @
872ead68
...
@@ -707,6 +707,17 @@ class TensorType(Type):
...
@@ -707,6 +707,17 @@ class TensorType(Type):
raise
TypeError
(
"Wrong number of dimensions: expected
%
s,"
raise
TypeError
(
"Wrong number of dimensions: expected
%
s,"
" got
%
s with shape
%
s."
%
(
self
.
ndim
,
data
.
ndim
,
" got
%
s with shape
%
s."
%
(
self
.
ndim
,
data
.
ndim
,
data
.
shape
),
data
)
data
.
shape
),
data
)
if
not
data
.
flags
.
aligned
:
try
:
msg
=
"object buffer"
+
str
(
data
.
data
)
except
AttributeError
:
msg
=
""
raise
TypeError
(
"The numpy.ndarray object is not aligned."
" Theano c code do not support that."
,
msg
,
"object shape"
,
data
.
shape
,
"object strides"
,
data
.
strides
)
i
=
0
i
=
0
for
b
in
self
.
broadcastable
:
for
b
in
self
.
broadcastable
:
if
b
and
data
.
shape
[
i
]
!=
1
:
if
b
and
data
.
shape
[
i
]
!=
1
:
...
@@ -988,8 +999,20 @@ class TensorType(Type):
...
@@ -988,8 +999,20 @@ class TensorType(Type):
if (!PyArray_ISALIGNED(py_
%(name)
s)) {
if (!PyArray_ISALIGNED(py_
%(name)
s)) {
PyErr_Format(PyExc_NotImplementedError,
PyErr_Format(PyExc_NotImplementedError,
"expected an aligned array of type
%%
d "
"expected an aligned array of type
%%
d "
"(
%(type_num)
s), got non-aligned array of type
%%
d",
"(
%(type_num)
s), got non-aligned array of type
%%
d"
%(type_num)
s, type_num_
%(name)
s);
" with
%%
d dimensions, with 2 last dims
%%
d,
%%
d"
" and 2 last strides
%%
d,
%%
d.",
%(type_num)
s, type_num_
%(name)
s,
PyArray_NDIM(py_
%(name)
s),
PyArray_NDIM(py_
%(name)
s) >= 2 ?
PyArray_DIMS(py_
%(name)
s)[PyArray_NDIM(py_
%(name)
s)-2] : -1,
PyArray_NDIM(py_
%(name)
s) >= 1 ?
PyArray_DIMS(py_
%(name)
s)[PyArray_NDIM(py_
%(name)
s)-1] : -1,
PyArray_NDIM(py_
%(name)
s) >= 2 ?
PyArray_STRIDES(py_
%(name)
s)[PyArray_NDIM(py_
%(name)
s)-2] : -1,
PyArray_NDIM(py_
%(name)
s) >= 1 ?
PyArray_STRIDES(py_
%(name)
s)[PyArray_NDIM(py_
%(name)
s)-1] : -1
);
%(fail)
s
%(fail)
s
}
}
// This is a TypeError to be consistent with DEBUG_MODE
// This is a TypeError to be consistent with DEBUG_MODE
...
@@ -1043,7 +1066,7 @@ class TensorType(Type):
...
@@ -1043,7 +1066,7 @@ class TensorType(Type):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
scalar_version
=
scal
.
Scalar
(
self
.
dtype
)
.
c_code_cache_version
()
scalar_version
=
scal
.
Scalar
(
self
.
dtype
)
.
c_code_cache_version
()
if
scalar_version
:
if
scalar_version
:
return
(
5
,)
+
scalar_version
return
(
6
,)
+
scalar_version
else
:
else
:
return
()
return
()
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
872ead68
...
@@ -6062,21 +6062,33 @@ def test_unalign():
...
@@ -6062,21 +6062,33 @@ def test_unalign():
av
,
bv
=
tensor
.
vectors
(
'ab'
)
av
,
bv
=
tensor
.
vectors
(
'ab'
)
f
=
theano
.
function
([
av
,
bv
],
2
*
av
+
3
*
bv
)
f
=
theano
.
function
([
av
,
bv
],
2
*
av
+
3
*
bv
)
f
.
maker
.
fgraph
.
toposort
()
f
.
maker
.
fgraph
.
toposort
()
# FAST_COMPILE use the python code that support unaligned data
# The DebugMode make a copy of the inputs, so they will be aligned.
should_raise
=
(
theano
.
config
.
mode
not
in
[
"FAST_COMPILE"
,
"DebugMode"
,
"DEBUG_MODE"
]
and
theano
.
config
.
linker
!=
'py'
)
try
:
try
:
out_theano
=
f
(
a
,
b
)
out_theano
=
f
(
a
,
b
)
assert
not
a
.
flags
.
aligned
assert
not
a
.
flags
.
aligned
assert
not
b
.
flags
.
aligned
assert
not
b
.
flags
.
aligned
assert
numpy
.
allclose
(
out_numpy
,
out_theano
)
assert
numpy
.
allclose
(
out_numpy
,
out_theano
)
if
should_raise
:
assert
False
raise
Exception
(
"Expected an error from Theano!"
)
except
TypeError
,
e
:
except
NotImplementedError
,
e
:
pass
if
not
should_raise
:
raise
Exception
(
"Theano raised an unexpected exception"
)
a
=
numpy
.
empty
((),
dtype
=
dtype
)[
'f1'
]
b
=
numpy
.
empty
((),
dtype
=
dtype
)[
'f1'
]
assert
not
a
.
flags
.
aligned
assert
not
b
.
flags
.
aligned
out_numpy
=
2
*
a
+
3
*
b
av
,
bv
=
tensor
.
scalars
(
'ab'
)
f
=
theano
.
function
([
av
,
bv
],
2
*
av
+
3
*
bv
)
f
.
maker
.
fgraph
.
toposort
()
try
:
out_theano
=
f
(
a
,
b
)
assert
not
a
.
flags
.
aligned
assert
not
b
.
flags
.
aligned
assert
numpy
.
allclose
(
out_numpy
,
out_theano
)
assert
False
except
TypeError
,
e
:
pass
def
test_dimshuffle_duplicate
():
def
test_dimshuffle_duplicate
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论