Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
823acacc
提交
823acacc
authored
6月 02, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactorized Opt. Improved opt tests.
上级
481ad92d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
35 行删除
+46
-35
opt.py
theano/typed_list/opt.py
+21
-35
test_opt.py
theano/typed_list/tests/test_opt.py
+25
-0
没有找到文件。
theano/typed_list/opt.py
浏览文件 @
823acacc
...
...
@@ -5,56 +5,42 @@ from theano.typed_list.basic import (Reverse,
Append
,
Extend
,
Insert
)
@gof.local_optimizer
([
Reverse
],
inplace
=
True
)
def
local_inplace_reverse
(
node
):
if
isinstance
(
node
.
op
,
Reverse
)
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
def
generic_opt_creator
(
op
):
@gof.local_optimizer
([
op
],
inplace
=
True
)
def
generic_inplace_opt
(
node
):
if
isinstance
(
node
.
op
,
op
)
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
return
generic_inplace_opt
local_inplace_reverse
=
generic_opt_creator
(
Reverse
)
compile
.
optdb
.
register
(
'local_inplace_reverse'
,
TopoOptimizer
(
local_inplace_reverse
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
)
# DEBUG
'fast_run'
,
'inplace'
)
@gof.local_optimizer
([
Append
],
inplace
=
True
)
def
local_inplace_append
(
node
):
if
isinstance
(
node
.
op
,
Append
)
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
local_inplace_append
=
generic_opt_creator
(
Append
)
compile
.
optdb
.
register
(
'local_inplace_append'
,
TopoOptimizer
(
local_inplace_append
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
)
# DEBUG
'fast_run'
,
'inplace'
)
@gof.local_optimizer
([
Extend
],
inplace
=
True
)
def
local_inplace_extend
(
node
):
if
isinstance
(
node
.
op
,
Extend
)
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
local_inplace_extend
=
generic_opt_creator
(
Extend
)
compile
.
optdb
.
register
(
'local_inplace_extend'
,
TopoOptimizer
(
local_inplace_extend
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
)
# DEBUG
'fast_run'
,
'inplace'
)
@gof.local_optimizer
([
Insert
],
inplace
=
True
)
def
local_inplace_insert
(
node
):
if
isinstance
(
node
.
op
,
Insert
)
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
local_inplace_insert
=
generic_opt_creator
(
Insert
)
compile
.
optdb
.
register
(
'local_inplace_insert'
,
TopoOptimizer
(
local_inplace_insert
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
...
...
theano/typed_list/tests/test_opt.py
浏览文件 @
823acacc
...
...
@@ -30,6 +30,12 @@ class test_inplace(unittest.TestCase):
f
=
theano
.
function
([
In
(
mySymbolicMatricesList
,
borrow
=
True
,
mutable
=
True
)],
z
,
accept_inplace
=
True
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
,
y
]),
[
y
,
x
]))
def
test_append_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
...
...
@@ -41,6 +47,12 @@ class test_inplace(unittest.TestCase):
mutable
=
True
),
In
(
mySymbolicMatrix
,
borrow
=
True
,
mutable
=
True
)],
z
,
accept_inplace
=
True
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
y
),
[
x
,
y
]))
def
test_extend_inplace
(
self
):
mySymbolicMatricesList1
=
TypedListType
(
T
.
TensorType
(
...
...
@@ -56,6 +68,12 @@ class test_inplace(unittest.TestCase):
z
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
[
y
]),
[
x
,
y
]))
def
test_insert_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
...
...
@@ -68,3 +86,10 @@ class test_inplace(unittest.TestCase):
mutable
=
True
),
mySymbolicIndex
,
mySymbolicMatrix
],
z
,
accept_inplace
=
True
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
theano
.
config
.
floatX
),
y
),
[
x
,
y
]))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论