Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
15584c1d
提交
15584c1d
authored
11月 05, 2016
作者:
Jakub Sygnowski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimizer for substituting max_and_argmax with just argmax
上级
88160c11
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
7 行增加
和
24 行删除
+7
-24
basic.py
theano/tensor/basic.py
+1
-21
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+3
-3
opt_uncanonicalize.py
theano/tensor/opt_uncanonicalize.py
+3
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
15584c1d
...
...
@@ -1732,26 +1732,6 @@ class Argmax(Op):
node
.
inputs
[
0
]
.
type
.
broadcastable
)
if
i
not
in
axis
.
data
])
return
[
rval
]
def
R_op
(
self
,
inputs
,
eval_points
):
if
eval_points
[
0
]
is
None
:
return
[
None
]
if
not
isinstance
(
inputs
[
1
],
theano
.
Constant
):
raise
ValueError
((
'R_op supported for argmax only for '
'constant axis!'
))
if
inputs
[
1
]
.
data
>
1
:
raise
ValueError
((
'R_op supported for argmax only when '
' axis is 0 or 1'
))
if
inputs
[
0
]
.
ndim
!=
2
:
raise
ValueError
((
'R_op supported for argmax only when '
' input is a matrix'
))
max_pos
=
self
.
make_node
(
*
inputs
)
.
outputs
if
inputs
[
1
]
.
data
==
0
:
return
[
eval_points
[
0
][
max_pos
,
arange
(
eval_points
[
0
]
.
shape
[
1
])],
None
]
else
:
return
[
eval_points
[
0
][
arange
(
eval_points
[
0
]
.
shape
[
0
]),
max_pos
],
None
]
def
grad
(
self
,
inp
,
grads
):
x
,
axis
=
inp
...
...
@@ -1887,7 +1867,7 @@ def argmax(x, axis=None, keepdims=False):
will broadcast correctly against the original tensor.
"""
argout
=
_argmax
(
x
,
axis
)
argout
=
max_and_argmax
(
x
,
axis
)[
1
]
if
keepdims
:
argout
=
makeKeepDims
(
x
,
argout
,
axis
)
...
...
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
15584c1d
...
...
@@ -1314,10 +1314,10 @@ def test_argmax_pushdown():
# for node in fgraph.toposort():
# print node.op
assert
len
(
fgraph
.
toposort
())
==
2
# an output_guard is second
assert
fgraph
.
toposort
()[
0
]
.
op
==
tensor
.
basic
.
_
max_and_
argmax
assert
fgraph
.
toposort
()[
0
]
.
op
==
tensor
.
basic
.
_argmax
assert
str
(
fgraph
.
toposort
()[
1
]
.
op
)
==
'OutputGuard'
assert
check_stack_trace
(
fgraph
,
ops_to_check
=
tensor
.
basic
.
_
max_and_
argmax
)
fgraph
,
ops_to_check
=
tensor
.
basic
.
_argmax
)
x
=
tensor
.
matrix
()
# test that the max_and_argmax is not pushed down if the max is used
out
=
tensor
.
max_and_argmax
(
...
...
@@ -1362,7 +1362,7 @@ def test_argmax_pushdown_bias():
# print 'AFTER'
# for node in fgraph.toposort():
# print node.op
types_to_check
=
(
tensor
.
DimShuffle
,
tensor
.
Elemwise
,
tensor
.
MaxAnd
Argmax
)
types_to_check
=
(
tensor
.
DimShuffle
,
tensor
.
Elemwise
,
tensor
.
Argmax
)
assert
len
(
fgraph
.
toposort
())
==
4
for
i
,
type
in
enumerate
(
types_to_check
):
assert
isinstance
(
fgraph
.
toposort
()[
i
]
.
op
,
type
)
...
...
theano/tensor/opt_uncanonicalize.py
浏览文件 @
15584c1d
...
...
@@ -73,6 +73,9 @@ def local_max_and_argmax(node):
new
=
CAReduce
(
scal
.
maximum
,
axis
)(
node
.
inputs
[
0
])
return
[
new
,
None
]
if
len
(
node
.
outputs
[
0
]
.
clients
)
==
0
:
return
[
None
,
T
.
_argmax
(
node
.
inputs
[
0
],
node
.
inputs
[
1
])]
@register_uncanonicalize
@gof.local_optimizer
([
T
.
neg
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论