Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6d7be386
提交
6d7be386
authored
11月 30, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't accept the DEFAULT value for axis and update the docstring for…
don't accept the DEFAULT value for axis and update the docstring for theano.{max,min,argmax,argmin,max_and_argmax}
上级
23d425f1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
2 行增加
和
66 行删除
+2
-66
basic.py
theano/tensor/basic.py
+2
-66
没有找到文件。
theano/tensor/basic.py
浏览文件 @
6d7be386
...
@@ -1874,19 +1874,6 @@ class MaxAndArgmax(Op):
...
@@ -1874,19 +1874,6 @@ class MaxAndArgmax(Op):
def
make_node
(
self
,
x
,
axis
=
None
):
def
make_node
(
self
,
x
,
axis
=
None
):
x
=
_as_tensor_variable
(
x
)
x
=
_as_tensor_variable
(
x
)
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
axis
=
0
if
axis
==
'DEFAULT'
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The default axis of MaxAndArgmax will change! "
"Now we return the max and the armax over the last dimensions. "
"It will change to be the same as numpy: the max and argmax over "
"all dimensions. 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
):
if
isinstance
(
axis
,
int
):
axis
=
[
axis
]
axis
=
[
axis
]
elif
isinstance
(
axis
,(
tuple
,
list
)):
elif
isinstance
(
axis
,(
tuple
,
list
)):
...
@@ -1982,24 +1969,10 @@ def max(x, axis=None):
...
@@ -1982,24 +1969,10 @@ def max(x, axis=None):
"""
"""
Return maximum elements obtained by iterating over given axis
Return maximum elements obtained by iterating over given axis
Default axis is
the last one. This will change
.
Default axis is
None: sum over all dimensions
.
:note: we return an error as numpy when we reduce a dim with a shape of 0
:note: we return an error as numpy when we reduce a dim with a shape of 0
:note2: see MaxAndArgmax note for a difference between numpy and theano when axis==None
"""
"""
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
axis
=
0
elif
axis
==
'DEFAULT'
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The default axis of max will change! Now we return the "
"max over the last dimensions. It will change to be the same as numpy: "
"the max over all dimensions. 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
:
if
isinstance
(
axis
,(
list
,
tuple
))
and
len
(
axis
)
>
1
:
return
CAReduce
(
scal
.
maximum
,
axis
)(
x
)
return
CAReduce
(
scal
.
maximum
,
axis
)(
x
)
try
:
try
:
...
@@ -2013,20 +1986,8 @@ def argmax(x, axis=None):
...
@@ -2013,20 +1986,8 @@ def argmax(x, axis=None):
"""
"""
Return indexes of maximum elements obtained by iterating over given axis
Return indexes of maximum elements obtained by iterating over given axis
Default axis is
the last one. This will change
.
Default axis is
None: sum over all dimensions
.
"""
"""
if
x
.
type
.
ndim
<=
1
and
axis
in
(
'DEFAULT'
,
None
):
# The old and new behavior are not different.
axis
=
0
elif
axis
==
'DEFAULT'
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The default axis of argmax will change! Now we return "
"the argmax over the last dimensions. It will change to be the same as "
"numpy: the argmax over all dimensions. 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 max()."
),
stacklevel
=
2
)
# In python (using MaxAndArgmax.perform()) this leads to an wasteful
# In python (using MaxAndArgmax.perform()) this leads to an wasteful
# implementation that goes through the data twice instead of once
# implementation that goes through the data twice instead of once
# but when Argmax.c_impl() is in place, it should be fine.
# but when Argmax.c_impl() is in place, it should be fine.
...
@@ -2034,19 +1995,6 @@ def argmax(x, axis=None):
...
@@ -2034,19 +1995,6 @@ def argmax(x, axis=None):
@constructor
@constructor
def
min
(
x
,
axis
=
None
):
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
elif
axis
==
'DEFAULT'
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The default axis of min will change! Now we return the "
"min over the last dimensions. It will change to be the same as numpy: "
"the min over all dimensions. 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
)
str_x_type
=
str
(
x
.
dtype
)
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
return
-
max
(
-
x
,
axis
=
axis
)
return
-
max
(
-
x
,
axis
=
axis
)
...
@@ -2056,18 +2004,6 @@ def min(x, axis=None):
...
@@ -2056,18 +2004,6 @@ def min(x, axis=None):
@constructor
@constructor
def
argmin
(
x
,
axis
=
None
):
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
elif
axis
==
'DEFAULT'
:
axis
=
x
.
type
.
ndim
-
1
warnings
.
warn
((
"The default axis of argmin will change! Now we return "
"the argmin over the last dimensions. It will change to be the same as "
"numpy: the argmin over all dimensions. 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
)
str_x_type
=
str
(
x
.
dtype
)
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
if
str_x_type
.
startswith
(
'float'
)
or
str_x_type
in
int_dtypes
:
return
argmax
(
-
x
,
axis
=
axis
)
return
argmax
(
-
x
,
axis
=
axis
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论