Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4ba6a10a
提交
4ba6a10a
authored
6月 11, 2010
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
dfc04612
655ecd92
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
74 行增加
和
0 行删除
+74
-0
function_module.py
theano/compile/function_module.py
+27
-0
test_pfunc.py
theano/compile/tests/test_pfunc.py
+47
-0
没有找到文件。
theano/compile/function_module.py
浏览文件 @
4ba6a10a
...
@@ -17,6 +17,7 @@ import theano.gof
...
@@ -17,6 +17,7 @@ import theano.gof
import
mode
as
mode_module
import
mode
as
mode_module
from
io
import
*
from
io
import
*
import
logging
import
logging
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
...
@@ -163,6 +164,18 @@ class AliasedMemoryError(Exception):
...
@@ -163,6 +164,18 @@ class AliasedMemoryError(Exception):
### Function
### Function
###
###
class
DeepCopyOp
(
theano
.
gof
.
Op
):
def
__init__
(
self
):
pass
def
make_node
(
self
,
x
):
return
theano
.
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
args
,
outs
):
outs
[
0
][
0
]
=
copy
.
deepcopy
(
args
[
0
])
deep_copy_op
=
DeepCopyOp
()
DUPLICATE
=
[
'DUPLICATE'
]
# unique id object used as a placeholder for duplicate entries
DUPLICATE
=
[
'DUPLICATE'
]
# unique id object used as a placeholder for duplicate entries
class
Function
(
object
):
class
Function
(
object
):
"""
"""
...
@@ -752,6 +765,20 @@ class FunctionMaker(object):
...
@@ -752,6 +765,20 @@ class FunctionMaker(object):
t0
=
time
.
time
()
t0
=
time
.
time
()
optimizer
(
env
)
optimizer
(
env
)
_logger
.
debug
(
'Optimizing took
%
f seconds'
%
(
time
.
time
()
-
t0
))
_logger
.
debug
(
'Optimizing took
%
f seconds'
%
(
time
.
time
()
-
t0
))
# This loop was inserted to remove aliasing between outputs when they all
# evaluete to the same value. Originally it was OK for outputs to be aliased,
# but some of the outputs can be shared variables, and is not good for shared
# variables to be aliased. It might be possible to optimize this by making sure
# there is no aliasing only between shared variables.
for
i
in
xrange
(
len
(
env
.
outputs
)):
views
=
set
()
view_tree_set
(
alias_root
(
env
.
outputs
[
i
]),
views
)
for
j
in
xrange
(
i
+
1
,
len
(
env
.
outputs
)):
if
env
.
outputs
[
j
]
in
views
:
env
.
change_input
(
'output'
,
j
,
deep_copy_op
(
env
.
outputs
[
j
]))
# initialize the linker
# initialize the linker
if
not
hasattr
(
linker
,
'accept'
):
if
not
hasattr
(
linker
,
'accept'
):
...
...
theano/compile/tests/test_pfunc.py
浏览文件 @
4ba6a10a
...
@@ -474,6 +474,53 @@ class Test_pfunc(unittest.TestCase):
...
@@ -474,6 +474,53 @@ class Test_pfunc(unittest.TestCase):
assert
f
()
==
21
assert
f
()
==
21
assert
f
()
==
34
assert
f
()
==
34
def
aliasing_test
(
self
):
A
=
shared
(
numpy
.
zeros
((
2
,
2
)))
B
=
shared
(
numpy
.
zeros
((
2
,
2
)))
C
=
numpy
.
zeros
((
2
,
2
))
D
=
tensor
.
dmatrix
()
DD
=
D
+
5
f
=
pfunc
([
D
],
[],
updates
=
[
(
A
,
D
),
(
B
,
D
)
])
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
f
=
pfunc
([
D
],
[],
updates
=
[
(
A
,
D
[:]),
(
B
,
D
)
])
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
f
=
pfunc
([
D
],
[],
updates
=
[
(
A
,
D
+
5
),
(
B
,
D
[:])
])
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
f
=
pfunc
([
D
],
[],
updates
=
[
(
A
,
D
+
5
),
(
B
,
D
)
])
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
f
=
pfunc
([
D
],
DD
,
updates
=
[
(
A
,
DD
[:
1
]),
(
B
,
DD
)
])
R
=
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
A
.
value
)
f
=
pfunc
([
D
],
DD
,
updates
=
[
(
A
,
DD
[:
1
]),
(
B
,
DD
[:
1
]
*
2
)
])
R
=
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
A
.
value
)
f
=
pfunc
([
D
],
DD
*
4
,
updates
=
[
(
A
,
DD
[:
1
]
*
3
),
(
B
,
DD
[:
1
]
*
2
)
])
R
=
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
A
.
value
)
f
=
pfunc
([
D
],
DD
*
4
,
updates
=
[
(
A
,
DD
[:
1
]
*
3
),
(
B
,
DD
[:
1
]
*
3
)
])
R
=
f
(
C
)
assert
not
numpy
.
may_share_memory
(
A
.
value
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
B
.
value
)
assert
not
numpy
.
may_share_memory
(
R
,
A
.
value
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
theano
.
config
.
mode
=
'FAST_COMPILE'
theano
.
config
.
mode
=
'FAST_COMPILE'
Test_pfunc
()
.
test_default_scalar_container
()
Test_pfunc
()
.
test_default_scalar_container
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论