Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
cf0507e1
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
cf0507e1
编写于
4年前
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge): remove F.identity
GitOrigin-RevId: 858be627acf028a46c57bde55161a85ff47d157f
上级
09241a1f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
10 addition
and
20 deletion
+10
-20
imperative/python/megengine/functional/tensor.py
imperative/python/megengine/functional/tensor.py
+0
-13
imperative/python/megengine/functional/utils.py
imperative/python/megengine/functional/utils.py
+7
-4
imperative/python/megengine/module/identity.py
imperative/python/megengine/module/identity.py
+2
-2
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+1
-1
未找到文件。
imperative/python/megengine/functional/tensor.py
浏览文件 @
cf0507e1
...
...
@@ -42,7 +42,6 @@ __all__ = [
"full"
,
"full_like"
,
"gather"
,
"identity"
,
"linspace"
,
"ones"
,
"ones_like"
,
...
...
@@ -178,18 +177,6 @@ def full_like(inp: Tensor, value: Union[int, float]) -> Tensor:
return
full
(
inp
.
shape
,
value
,
dtype
=
inp
.
dtype
,
device
=
inp
.
device
)
def
identity
(
inp
:
Tensor
)
->
Tensor
:
"""Applies an identity transformation to input tensor.
:param inp: input tensor.
:return: output tensor.
"""
op
=
builtin
.
Identity
()
(
data
,)
=
convert_inputs
(
inp
)
(
output
,)
=
apply
(
op
,
data
)
return
output
def
broadcast_to
(
inp
:
Tensor
,
shape
:
Union
[
int
,
Iterable
[
int
]])
->
Tensor
:
"""
Broadcasts a tensor to given shape.
...
...
This diff is collapsed.
Click to expand it.
imperative/python/megengine/functional/utils.py
浏览文件 @
cf0507e1
...
...
@@ -11,7 +11,8 @@ from typing import Iterable, Union
import
numpy
as
np
from
..core.ops.builtin
import
Copy
from
..core._wrap
import
device
as
as_device
from
..core.ops.builtin
import
Copy
,
Identity
from
..core.tensor
import
Tensor
from
..core.tensor.core
import
apply
from
.math
import
topk
as
_topk
...
...
@@ -63,12 +64,12 @@ def accuracy(
return
accs
def
copy
(
inp
,
cn
):
def
copy
(
inp
,
device
=
None
):
r
"""
Copies tensor to another device.
:param inp: input tensor.
:param
cn
: destination device.
:param
device
: destination device.
Examples:
...
...
@@ -88,4 +89,6 @@ def copy(inp, cn):
[1 2 3]
"""
return
apply
(
Copy
(
comp_node
=
cn
),
inp
)[
0
]
if
device
is
None
:
return
apply
(
Identity
(),
inp
)[
0
]
return
apply
(
Copy
(
comp_node
=
as_device
(
device
).
to_c
()),
inp
)[
0
]
This diff is collapsed.
Click to expand it.
imperative/python/megengine/module/identity.py
浏览文件 @
cf0507e1
...
...
@@ -6,7 +6,7 @@
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
from
..functional
import
identit
y
from
..functional
import
cop
y
from
.module
import
Module
...
...
@@ -14,4 +14,4 @@ class Identity(Module):
r
"""A placeholder identity operator that will ignore any argument."""
def
forward
(
self
,
x
):
return
identit
y
(
x
)
return
cop
y
(
x
)
This diff is collapsed.
Click to expand it.
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
cf0507e1
...
...
@@ -314,7 +314,7 @@ def test_device():
def
test_identity
():
x
=
tensor
(
np
.
random
.
random
((
5
,
10
)).
astype
(
np
.
float32
))
y
=
F
.
identit
y
(
x
)
y
=
F
.
cop
y
(
x
)
np
.
testing
.
assert_equal
(
y
.
numpy
(),
x
)
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部