Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
18108182
提交
18108182
authored
11月 16, 2010
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added some extra tests to the aliasing issue.
上级
ede0a42b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
114 行增加
和
5 行删除
+114
-5
test_pfunc.py
theano/compile/tests/test_pfunc.py
+114
-5
没有找到文件。
theano/compile/tests/test_pfunc.py
浏览文件 @
18108182
...
...
@@ -517,7 +517,57 @@ class Test_aliasing_rules(unittest.TestCase):
assert
not
numpy
.
may_share_memory
(
A
.
get_value
(
borrow
=
False
),
data_of
(
A
))
def
test_potential_input_aliasing_affecting_inplace_operations
(
self
):
def
test_sparse_input_aliasing_affecting_inplace_operations
(
self
):
##
## Note this test will never fail because I am not aware of any
## inplace op on sparse variables
try
:
import
scipy.sparse
as
sp
except
ImportError
:
pass
#the variable enable_sparse will be used to disable the test file.
from
theano.sparse
import
enable_sparse
if
enable_sparse
==
False
:
raise
SkipTest
(
'Optional package sparse disabled'
)
from
theano
import
sparse
## Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
# you need to make in inputs mutable ( so that inplace
# operations are used) and to break the elemwise composition
# with some non-elemwise op ( here dot )
x
=
sparse
.
SparseType
(
'csc'
,
dtype
=
'float64'
)()
y
=
sparse
.
SparseType
(
'csc'
,
dtype
=
'float64'
)()
f
=
theano
.
function
(
[
theano
.
In
(
x
,
mutable
=
True
),
theano
.
In
(
y
,
mutable
=
True
)],
(
x
+
y
)
+
(
x
+
y
))
## Test 1. If the same variable is given twice
# Compute bogus values
m
=
sp
.
csc_matrix
(
numpy
.
asarray
([[
1
,
0
,
0
,
0
,
0
],
[
0
,
1
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
0
],
[
0
,
0
,
0
,
0
,
1
]],
dtype
=
'float64'
))
bogus_vals
=
f
(
m
,
m
)
# Since we used inplace operation v and m may be corrupted
# so we need to recreate them
m
=
sp
.
csc_matrix
(
numpy
.
asarray
([[
1
,
0
,
0
,
0
,
0
],
[
0
,
1
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
0
],
[
0
,
0
,
0
,
0
,
1
]],
dtype
=
'float64'
))
m_copy
=
m
.
copy
()
vals
=
f
(
m
,
m_copy
)
assert
numpy
.
allclose
(
vals
.
todense
(),
bogus_vals
.
todense
())
def
test_input_aliasing_affecting_inplace_operations
(
self
):
## Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
# you need to make in inputs mutable ( so that inplace
...
...
@@ -532,20 +582,79 @@ class Test_aliasing_rules(unittest.TestCase):
theano
.
In
(
m1
,
mutable
=
True
),
theano
.
In
(
m2
,
mutable
=
True
)],
theano
.
dot
(
x
*
2
,
m1
)
+
theano
.
dot
(
y
*
3
,
m2
))
## Test 1. If the same variable is given twice
# Compute bogus values
v
=
numpy
.
asarray
([
1
,
2
],
dtype
=
'float64'
)
m
=
numpy
.
asarray
([[
1
,
0
],[
0
,
1
]],
dtype
=
'float64'
)
v
=
numpy
.
asarray
(
[
1
,
2
,
3
,
4
,
5
],
dtype
=
'float64'
)
m
=
numpy
.
asarray
([[
1
,
0
,
0
,
0
,
0
],
[
0
,
1
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
0
],
[
0
,
0
,
0
,
0
,
1
]],
dtype
=
'float64'
)
bogus_vals
=
f
(
v
,
v
,
m
,
m
)
# Since we used inplace operation v and m may be corrupted
# so we need to recreate them
m
=
numpy
.
asarray
([[
1
,
0
],[
0
,
1
]],
dtype
=
'float64'
)
v
=
numpy
.
asarray
([
1
,
2
],
dtype
=
'float64'
)
v
=
numpy
.
asarray
(
[
1
,
2
,
3
,
4
,
5
],
dtype
=
'float64'
)
m
=
numpy
.
asarray
([[
1
,
0
,
0
,
0
,
0
],
[
0
,
1
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
0
,
1
,
0
],
[
0
,
0
,
0
,
0
,
1
]],
dtype
=
'float64'
)
m_copy
=
m
.
copy
()
v_copy
=
v
.
copy
()
vals
=
f
(
v
,
v_copy
,
m
,
m_copy
)
assert
numpy
.
allclose
(
vals
,
bogus_vals
)
def
test_partial_input_aliasing_affecting_inplace_operations
(
self
):
## Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
# you need to make in inputs mutable ( so that inplace
# operations are used) and to break the elemwise composition
# with some non-elemwise op ( here dot )
x
=
theano
.
tensor
.
dvector
()
y
=
theano
.
tensor
.
dvector
()
z
=
theano
.
tensor
.
dvector
()
m1
=
theano
.
tensor
.
dmatrix
()
m2
=
theano
.
tensor
.
dmatrix
()
m3
=
theano
.
tensor
.
dmatrix
()
## Test 2. If variables only partial overlap
# more exactly we care about the case when we have a,b,c
# and a shares memory with b, b shares memory with c, but
# c does not share memory with a
f
=
theano
.
function
(
[
theano
.
In
(
x
,
mutable
=
True
),
theano
.
In
(
y
,
mutable
=
True
),
theano
.
In
(
z
,
mutable
=
True
),
theano
.
In
(
m1
,
mutable
=
True
),
theano
.
In
(
m2
,
mutable
=
True
),
theano
.
In
(
m3
,
mutable
=
True
)],
theano
.
dot
(
x
*
2
,
m1
)
+
theano
.
dot
(
y
*
3
,
m2
)
+
theano
.
dot
(
z
*
4
,
m3
))
# Compute bogus values
v
=
numpy
.
asarray
(
[
1
,
2
,
3
,
4
,
5
],
dtype
=
'float64'
)
m
=
numpy
.
asarray
([[
1
,
0
],
[
0
,
1
]],
dtype
=
'float64'
)
bogus_vals
=
f
(
v
[:
2
],
v
[
1
:
3
],
v
[
2
:
4
],
m
,
m
,
m
)
# Since we used inplace operation v and m may be corrupted
# so we need to recreate them
v
=
numpy
.
asarray
(
[
1
,
2
,
3
,
4
,
5
],
dtype
=
'float64'
)
m
=
numpy
.
asarray
([[
1
,
0
],
[
0
,
1
]],
dtype
=
'float64'
)
m_copy1
=
m
.
copy
()
v_copy1
=
v
.
copy
()
m_copy2
=
m
.
copy
()
v_copy2
=
v
.
copy
()
vals
=
f
(
v
[:
2
],
v_copy1
[
1
:
3
],
v_copy2
[
2
:
4
],
m
,
m_copy1
,
m_copy2
)
assert
numpy
.
allclose
(
vals
,
bogus_vals
)
def
test_potential_output_aliasing_induced_by_updates
(
self
):
A
=
self
.
shared
(
numpy
.
zeros
((
2
,
2
)))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论