Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
677e7a2e
提交
677e7a2e
authored
11月 29, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change the default of theano.{max,min,argmax,argmin,max_and_argmax} to the same as numpy.
上级
f40a8a25
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
60 行删除
+5
-60
basic.py
theano/tensor/basic.py
+5
-60
没有找到文件。
theano/tensor/basic.py
浏览文件 @
677e7a2e
...
...
@@ -1862,13 +1862,6 @@ specify_shape = SpecifyShape()
class
MaxAndArgmax
(
Op
):
"""Calculate the max and argmax over a given axis.
.. note::
If axis is None it means to calculate the max over the last dimension which is
DIFFERENT FROM NUMPY!!
To have the behavior of numpy do a flatten of the input before passing the data to this op.
If the input to flatten is not ccontiguous, this will make a copy to a contiguous version.
"""
nin
=
2
# tensor, axis
nout
=
2
# max val, max idx
...
...
@@ -1879,7 +1872,7 @@ class MaxAndArgmax(Op):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
axis
=
'DEFAULT'
):
def
make_node
(
self
,
x
,
axis
=
None
):
x
=
_as_tensor_variable
(
x
)
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
...
...
@@ -1894,16 +1887,6 @@ class MaxAndArgmax(Op):
"MaxAndArgmax currently support axis over only 1 dimensions, so "
"you must flatten the tensor to have the futur behavior."
),
stacklevel
=
3
)
elif
axis
is
None
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The behavior of MaxAndArgmax when axis==None will "
"change! Now we return the max and argmax over the last "
"dimensions. It will change to the max and argmax over all "
"dimensions as numpy. To hide this warning and be compatible with "
"the future behavior, set axis to -1 to have the current behavior. "
"MaxAndArgmax currently support axis over only 1 dimensions, so "
"you must flatten the tensor to have the futur behavior."
),
stacklevel
=
3
)
if
isinstance
(
axis
,
int
):
axis
=
[
axis
]
elif
isinstance
(
axis
,(
tuple
,
list
)):
...
...
@@ -1995,7 +1978,7 @@ def max_and_argmax(a):
@constructor
def
max
(
x
,
axis
=
'DEFAULT'
):
def
max
(
x
,
axis
=
None
):
"""
Return maximum elements obtained by iterating over given axis
...
...
@@ -2017,16 +2000,6 @@ def max(x, axis='DEFAULT'):
"this don't support the grad. To have the grad, you must flatten the "
"tensor before calling max()."
),
stacklevel
=
2
)
elif
axis
is
None
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The behavior of max when axis==None will change! Now "
"we return the max over the last dimensions. It will change to the max "
"over all dimensions as numpy. To hide this warning and be compatible "
"with the future behavior, set axis to -1 to have the current "
"behavior. To have the futur behavior set axis to range(nb dim), but "
"this don't support the grad. To have the grad, you must flatten the "
"tensor before calling max()."
),
stacklevel
=
2
)
if
isinstance
(
axis
,(
list
,
tuple
))
and
len
(
axis
)
>
1
:
return
CAReduce
(
scal
.
maximum
,
axis
)(
x
)
try
:
...
...
@@ -2036,7 +2009,7 @@ def max(x, axis='DEFAULT'):
return
max_and_argmax
(
x
,
axis
)[
0
]
@constructor
def
argmax
(
x
,
axis
=
'DEFAULT'
):
def
argmax
(
x
,
axis
=
None
):
"""
Return indexes of maximum elements obtained by iterating over given axis
...
...
@@ -2054,22 +2027,13 @@ def argmax(x, axis='DEFAULT'):
"current behavior. To have the futur behavior, you must flatten the "
"tensor before calling max()."
),
stacklevel
=
2
)
elif
axis
is
None
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The behavior of argmax when axis==None will change! "
"Now we return the argmax over the last dimensions. It will change to "
"the argmax over all dimensions as numpy. To hide this warning and be "
"compatible with the future behavior, set axis to -1 to have the "
"current behavior. To have the futur behavior, you must flatten the "
"tensor before calling argmax()."
),
stacklevel
=
2
)
# In python (using MaxAndArgmax.perform()) this leads to an wasteful
# implementation that goes through the data twice instead of once
# but when Argmax.c_impl() is in place, it should be fine.
return
max_and_argmax
(
x
,
axis
)[
1
]
@constructor
def
min
(
x
,
axis
=
'DEFAULT'
):
def
min
(
x
,
axis
=
None
):
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
axis
=
0
...
...
@@ -2083,16 +2047,6 @@ def min(x, axis='DEFAULT'):
"this does not support the grad. To be able to get the grad, you must "
"flatten the tensor before calling min()."
),
stacklevel
=
2
)
elif
axis
is
None
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The behavior of min when axis is None will change! Now "
"we return the min over the last dimensions. It will change to the min "
"over all dimensions as numpy. To hide this warning and be compatible "
"with the future behavior, set axis to -1 to have the current "
"behavior. To have the future behavior, set axis to range(x.ndim), but "
"this does not support the grad. To be able to get the grad, you must "
"flatten the tensor before calling min()."
),
stacklevel
=
2
)
str_x_type
=
str
(
x
.
dtype
)
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
return
-
max
(
-
x
,
axis
=
axis
)
...
...
@@ -2101,7 +2055,7 @@ def min(x, axis='DEFAULT'):
raise
NotImplementedError
()
@constructor
def
argmin
(
x
,
axis
=
'DEFAULT'
):
def
argmin
(
x
,
axis
=
None
):
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
axis
=
0
...
...
@@ -2114,15 +2068,6 @@ def argmin(x, axis='DEFAULT'):
"current behavior. To have the futur behavior, you must flatten the "
"axis before calling argmin."
),
stacklevel
=
2
)
elif
axis
is
None
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The behavior of argmin when axis==None will change! "
"Now we return the argmin over the last dimensions. It will change to "
"the argmin over all dimensions as numpy. To hide this warning and be "
"compatible with the future behavior, set axis to -1 to have the "
"current behavior. To have the futur behavior, you must flatten the "
"axis before calling argmin."
),
stacklevel
=
2
)
str_x_type
=
str
(
x
.
dtype
)
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
return
argmax
(
-
x
,
axis
=
axis
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论