Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ff542349
提交
ff542349
authored
7月 17, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify checking for constant zeros in optimization, test it.
More cases are detected now.
上级
8b7aeb6e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
35 行删除
+45
-35
opt.py
theano/tensor/opt.py
+27
-35
test_opt.py
theano/tensor/tests/test_opt.py
+18
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
ff542349
...
@@ -262,21 +262,19 @@ def local_0_dot_x(node):
...
@@ -262,21 +262,19 @@ def local_0_dot_x(node):
x
=
node
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
y
=
node
.
inputs
[
1
]
y
=
node
.
inputs
[
1
]
replace
=
False
replace
=
False
if
x
.
owner
and
isinstance
(
x
.
owner
.
op
,
T
.
Alloc
):
try
:
try
:
if
get_constant_value
(
x
)
==
0
:
val
=
get_constant_value
(
x
.
owner
.
inputs
[
0
])
replace
=
True
if
numpy
.
all
(
val
==
0
):
except
TypeError
:
replace
=
True
pass
except
TypeError
:
pass
if
y
.
owner
and
isinstance
(
y
.
owner
.
op
,
T
.
Alloc
)
:
try
:
try
:
if
get_constant_value
(
y
)
==
0
:
val
=
get_constant_value
(
y
.
owner
.
inputs
[
0
])
replace
=
True
if
numpy
.
all
(
val
==
0
)
:
except
TypeError
:
replace
=
True
pass
except
TypeError
:
pass
# TODO: Integrate that into get_constant_value somehow
if
isinstance
(
x
,
T
.
TensorConstant
)
and
(
x
.
tag
.
unique_value
==
0
):
if
isinstance
(
x
,
T
.
TensorConstant
)
and
(
x
.
tag
.
unique_value
==
0
):
replace
=
True
replace
=
True
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
==
0
):
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
==
0
):
...
@@ -1630,13 +1628,12 @@ def local_incsubtensor_of_allocs(node):
...
@@ -1630,13 +1628,12 @@ def local_incsubtensor_of_allocs(node):
x
=
node
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
y
=
node
.
inputs
[
1
]
y
=
node
.
inputs
[
1
]
replace
=
False
replace
=
False
if
y
.
owner
and
isinstance
(
y
.
owner
.
op
,
T
.
Alloc
):
try
:
try
:
if
get_constant_value
(
y
)
==
0
:
val
=
get_constant_value
(
y
.
owner
.
inputs
[
0
])
replace
=
True
if
numpy
.
all
(
val
==
0
):
except
TypeError
:
replace
=
True
pass
except
TypeError
:
# TODO: Integrate that into get_constant_value
pass
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
==
0
):
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
==
0
):
replace
=
True
replace
=
True
...
@@ -1655,25 +1652,20 @@ def local_setsubtensor_of_allocs(node):
...
@@ -1655,25 +1652,20 @@ def local_setsubtensor_of_allocs(node):
y
=
node
.
inputs
[
1
]
y
=
node
.
inputs
[
1
]
replace_x
=
None
replace_x
=
None
replace_y
=
None
replace_y
=
None
if
x
.
owner
and
isinstance
(
x
.
owner
.
op
,
T
.
Alloc
):
try
:
try
:
val
=
get_constant_value
(
x
.
owner
.
inputs
[
0
])
replace_x
=
get_constant_value
(
x
)
assert
val
.
size
==
1
except
TypeError
:
replace_x
=
val
pass
except
(
TypeError
,
AssertionError
):
replace_x
=
x
.
owner
.
inputs
[
0
]
if
isinstance
(
x
,
T
.
TensorConstant
)
and
(
x
.
tag
.
unique_value
is
not
if
isinstance
(
x
,
T
.
TensorConstant
)
and
(
x
.
tag
.
unique_value
is
not
None
):
None
):
replace_x
=
x
.
tag
.
unique_value
replace_x
=
x
.
tag
.
unique_value
if
y
.
owner
and
isinstance
(
y
.
owner
.
op
,
T
.
Alloc
):
try
:
try
:
replace_y
=
get_constant_value
(
y
)
val
=
get_constant_value
(
y
.
owner
.
inputs
[
0
])
except
TypeError
:
assert
val
.
size
==
1
pass
replace_y
=
val
except
(
TypeError
,
AssertionError
):
replace_y
=
y
.
owner
.
inputs
[
0
]
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
is
not
if
isinstance
(
y
,
T
.
TensorConstant
)
and
(
y
.
tag
.
unique_value
is
not
None
):
None
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
ff542349
...
@@ -1602,6 +1602,15 @@ class Test_alloc_zero(unittest.TestCase):
...
@@ -1602,6 +1602,15 @@ class Test_alloc_zero(unittest.TestCase):
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
f
.
maker
.
env
.
toposort
()
])
f
.
maker
.
env
.
toposort
()
])
def
test_setsubtensor_allocs1t
(
self
):
y
=
tensor
.
matrix
()
x0
=
tensor
.
constant
(
numpy
.
asarray
(
numpy
.
zeros_like
((
4
,
4
)),
dtype
=
config
.
floatX
))
y0
=
tensor
.
zeros_like
(
y
)
z
=
tensor
.
set_subtensor
(
x0
[:
4
],
y0
.
T
)
f
=
theano
.
function
([
y
],
z
)
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
f
.
maker
.
env
.
toposort
()
])
def
test_setsubtensor_allocs2
(
self
):
def
test_setsubtensor_allocs2
(
self
):
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
y0
=
tensor
.
constant
(
numpy
.
asarray
(
numpy
.
zeros_like
((
4
,
4
)),
dtype
=
config
.
floatX
))
y0
=
tensor
.
constant
(
numpy
.
asarray
(
numpy
.
zeros_like
((
4
,
4
)),
dtype
=
config
.
floatX
))
...
@@ -1620,6 +1629,15 @@ class Test_alloc_zero(unittest.TestCase):
...
@@ -1620,6 +1629,15 @@ class Test_alloc_zero(unittest.TestCase):
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
f
.
maker
.
env
.
toposort
()
])
f
.
maker
.
env
.
toposort
()
])
def
test_incsubtensor_allocs0t
(
self
):
x
=
tensor
.
matrix
()
y
=
tensor
.
matrix
()
y0
=
tensor
.
zeros_like
(
y
)
z
=
tensor
.
inc_subtensor
(
x
[:
4
],
y0
.
T
)
f
=
theano
.
function
([
x
,
y
],
z
)
assert
numpy
.
all
(
[
not
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
f
.
maker
.
env
.
toposort
()
])
def
test_incsubtensor_allocs1
(
self
):
def
test_incsubtensor_allocs1
(
self
):
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
y0
=
tensor
.
constant
(
numpy
.
asarray
(
numpy
.
zeros_like
((
4
,
4
)),
dtype
=
config
.
floatX
))
y0
=
tensor
.
constant
(
numpy
.
asarray
(
numpy
.
zeros_like
((
4
,
4
)),
dtype
=
config
.
floatX
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论