Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
68e959df
提交
68e959df
authored
12月 20, 2016
作者:
Iulian Vlad Serban
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implemented comments from Pascal. Implemented some tests for local_useless_elemwise_comparison.
上级
bde718ca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
11 行删除
+30
-11
opt.py
theano/tensor/opt.py
+13
-8
test_opt.py
theano/tensor/tests/test_opt.py
+17
-3
没有找到文件。
theano/tensor/opt.py
浏览文件 @
68e959df
...
@@ -4226,7 +4226,7 @@ def local_flatten_lift(node):
...
@@ -4226,7 +4226,7 @@ def local_flatten_lift(node):
# Copy over stacktrace from previous output node and from unary
# Copy over stacktrace from previous output node and from unary
# elementwise output node since if there was an error, it would
# elementwise output node since if there was an error, it would
# probably have come from that operation.
# probably have come from that operation.
copy_stack_trace
(
node
.
outputs
+
node
.
inputs
[
0
],
e
)
copy_stack_trace
(
node
.
outputs
+
[
node
.
inputs
[
0
]
],
e
)
return
[
e
]
return
[
e
]
...
@@ -4498,9 +4498,9 @@ def local_reshape_lift(node):
...
@@ -4498,9 +4498,9 @@ def local_reshape_lift(node):
if
e
.
type
!=
node
.
outputs
[
0
]
.
type
:
if
e
.
type
!=
node
.
outputs
[
0
]
.
type
:
re
=
T
.
patternbroadcast
(
e
,
node
.
outputs
[
0
]
.
broadcastable
)
re
=
T
.
patternbroadcast
(
e
,
node
.
outputs
[
0
]
.
broadcastable
)
#
We assume that the broadcast op cannot fail. Thus, if the
#
Copy over stack trace.
#
graph fails it must be due to previous UnaryElemwise op, and
#
If the graph fails it is usually due to the fact that a dimension
# th
erefore we must copy its stacktrace over.
# th
at should be broadcastable does not actually have length 1,
copy_stack_trace
(
e
,
re
)
copy_stack_trace
(
e
,
re
)
else
:
else
:
re
=
e
re
=
e
...
@@ -5200,7 +5200,7 @@ def local_sum_prod_mul_by_scalar(node):
...
@@ -5200,7 +5200,7 @@ def local_sum_prod_mul_by_scalar(node):
# There are never errors in the negative op, thus
# There are never errors in the negative op, thus
# we need only to copy over stacktrace from previous output node to
# we need only to copy over stacktrace from previous output node to
# the two new ops.
# the two new ops.
copy_stack_trace
(
node
.
outputs
,
s
+
ret
)
copy_stack_trace
(
node
.
outputs
,
[
s
,
ret
]
)
return
[
ret
]
return
[
ret
]
...
@@ -5217,7 +5217,7 @@ def local_elemwise_sub_zeros(node):
...
@@ -5217,7 +5217,7 @@ def local_elemwise_sub_zeros(node):
node
.
inputs
[
0
]
==
node
.
inputs
[
1
]):
node
.
inputs
[
0
]
==
node
.
inputs
[
1
]):
res
=
T
.
zeros_like
(
node
.
inputs
[
0
])
res
=
T
.
zeros_like
(
node
.
inputs
[
0
])
# Copy over stacktrace from previous output.
# Copy over stacktrace from previous output.
#
Julian: Pascal, is this really necessary? Is there anyway zeros_like can ever fail?
#
This could help for failures due to out-of-memory.
copy_stack_trace
(
node
.
outputs
,
res
)
copy_stack_trace
(
node
.
outputs
,
res
)
return
[
res
]
return
[
res
]
...
@@ -5394,9 +5394,14 @@ def local_useless_elemwise_comparison(node):
...
@@ -5394,9 +5394,14 @@ def local_useless_elemwise_comparison(node):
try
:
try
:
cst
=
get_scalar_constant_value
(
node
.
inputs
[
1
],
cst
=
get_scalar_constant_value
(
node
.
inputs
[
1
],
only_process_constants
=
True
)
only_process_constants
=
True
)
# Copy over stacktrace from previous output.
res
=
T
.
zeros_like
(
node
.
inputs
[
0
],
dtype
=
dtype
,
opt
=
True
)
copy_stack_trace
(
node
.
outputs
,
res
)
if
cst
<
0
:
if
cst
<
0
:
return
[
T
.
zeros_like
(
node
.
inputs
[
0
],
return
[
res
]
dtype
=
dtype
,
opt
=
True
)]
except
NotScalarConstantError
:
except
NotScalarConstantError
:
pass
pass
return
return
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
68e959df
...
@@ -3566,7 +3566,6 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3566,7 +3566,6 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
assert
isinstance
(
elem
.
inputs
[
0
],
T
.
TensorConstant
),
elem
assert
isinstance
(
elem
.
inputs
[
0
],
T
.
TensorConstant
),
elem
assert
T
.
extract_constant
(
elem
.
inputs
[
0
])
==
val
,
val
assert
T
.
extract_constant
(
elem
.
inputs
[
0
])
==
val
,
val
def
assert_identity
(
self
,
f
):
def
assert_identity
(
self
,
f
):
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
...
@@ -3662,7 +3661,6 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3662,7 +3661,6 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
0
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
0
))
assert
f
([
3
,
3
])
==
0
assert
f
([
3
,
3
])
==
0
assert
f
([])
==
1
assert
f
([])
==
1
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
-
1
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
-
1
))
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
...
@@ -3674,12 +3672,12 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3674,12 +3672,12 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
0
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
0
))
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
assert
(
f
([])
==
1
)
.
all
()
assert
(
f
([])
==
1
)
.
all
()
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
-
1
))
f
=
theano
.
function
([
x
],
T
.
eq
(
g
,
-
1
))
self
.
assert_eqs_const
(
f
,
0
,
op
=
T
.
alloc
)
self
.
assert_eqs_const
(
f
,
0
,
op
=
T
.
alloc
)
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
def
test_and
(
self
):
def
test_and
(
self
):
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
...
@@ -3727,6 +3725,22 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3727,6 +3725,22 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
def
test_stacktrace
(
self
):
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'local_useless_elemwise_comparison'
)
x
=
T
.
vector
(
'x'
,
dtype
=
config
.
floatX
)
f
=
theano
.
function
([
x
],
T
.
gt
(
x
,
x
),
mode
=
mode
)
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
f
=
theano
.
function
([
x
],
T
.
le
(
x
,
x
),
mode
=
mode
)
self
.
assertTrue
(
check_stack_trace
(
f
,
ops_to_check
=
'last'
))
# Julian: I tried testing the stack trace for a bunch of different
# functions, including maximum and shapes, but other opts remove
# the stack traces in this case.
class
Test_local_canonicalize_alloc
(
unittest
.
TestCase
):
class
Test_local_canonicalize_alloc
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论