Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
d23d1352
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d23d1352
编写于
12月 21, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(imperative/python): add the default warning for args descending
GitOrigin-RevId: cb5f065e6ca7e3d18f39e95966316d0a2110d499
上级
5e80f021
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
9 deletion
+37
-9
imperative/python/megengine/functional/math.py
imperative/python/megengine/functional/math.py
+3
-1
imperative/python/megengine/utils/deprecation.py
imperative/python/megengine/utils/deprecation.py
+34
-8
未找到文件。
imperative/python/megengine/functional/math.py
浏览文件 @
d23d1352
...
...
@@ -22,6 +22,7 @@ from ..core.tensor import amp
from
..core.tensor.utils
import
_normalize_axis
,
cast_tensors
,
setscalar
,
subgraph
from
..jit
import
exclude_from_trace
from
..tensor
import
Tensor
from
..utils.deprecation
import
deprecated_kwargs_default
from
.debug_param
import
get_execution_strategy
from
.elemwise
import
clip
,
minimum
from
.tensor
import
broadcast_to
,
concat
,
expand_dims
,
squeeze
...
...
@@ -684,6 +685,7 @@ def sort(inp: Tensor, descending: bool = False) -> Tuple[Tensor, Tensor]:
return
tns
,
ind
@
deprecated_kwargs_default
(
"1.12"
,
"descending"
,
3
)
def
topk
(
inp
:
Tensor
,
k
:
int
,
...
...
@@ -712,7 +714,7 @@ def topk(
import megengine.functional as F
x = tensor(np.array([2, 4, 6, 8, 7, 5, 3, 1], dtype=np.float32))
top, indices = F.topk(x, 5)
top, indices = F.topk(x, 5
, descending=False
)
print(top.numpy(), indices.numpy())
Outputs:
...
...
imperative/python/megengine/utils/deprecation.py
浏览文件 @
d23d1352
...
...
@@ -7,9 +7,12 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
importlib
import
warnings
from
functools
import
wraps
from
deprecated.sphinx
import
deprecated
warnings
.
filterwarnings
(
action
=
"default"
,
module
=
"megengine"
)
def
deprecated_func
(
version
,
origin
,
name
,
tbd
):
r
"""
...
...
@@ -27,16 +30,39 @@ def deprecated_func(version, origin, name, tbd):
module
=
importlib
.
import_module
(
origin
)
func
=
module
.
__getattribute__
(
name
)
if
should_warning
:
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
action
=
"always"
)
warnings
.
warn
(
"Call to deprecated function {}. (use {}.{} instead) -- Deprecated since version {}."
.
format
(
name
,
origin
,
name
,
version
),
category
=
DeprecationWarning
,
stacklevel
=
2
,
)
return
func
(
*
args
,
**
kwargs
)
return
wrapper
def
deprecated_kwargs_default
(
version
,
kwargs_name
,
kwargs_pos
):
r
"""
Args:
version: version to deprecate this default
kwargs_name: kwargs name
kwargs_pos: kwargs position
"""
def
deprecated
(
func
):
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
if
len
(
args
)
<
kwargs_pos
and
kwargs_name
not
in
kwargs
:
warnings
.
warn
(
"
Call to deprecated function {}. (use {}.{} instead) -- Deprecated since version {}.
"
.
format
(
name
,
origin
,
name
,
version
"
the default behavior for {} will be changed in version {}, please use it in keyword parameter way
"
.
format
(
kwargs_
name
,
version
),
category
=
DeprecationWarning
,
category
=
Pending
DeprecationWarning
,
stacklevel
=
2
,
)
should_warning
=
False
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
wrapper
return
wrapper
return
deprecated
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录