Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
18bc81e8
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
18bc81e8
编写于
7月 01, 2020
作者:
Z
zhoufeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ascend control sink testcase
Signed-off-by:
N
zhoufeng
<
zhoufeng54@huawei.com
>
上级
ea475637
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
189 addition
and
0 deletion
+189
-0
tests/st/control/test_ascend_control_sink.py
tests/st/control/test_ascend_control_sink.py
+189
-0
未找到文件。
tests/st/control/test_ascend_control_sink.py
0 → 100644
浏览文件 @
18bc81e8
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test_ascend_control_sink """
import
pytest
import
numpy
as
np
import
mindspore.context
as
context
import
mindspore.nn
as
nn
from
mindspore.ops
import
operations
as
op
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common.tensor
import
Tensor
from
mindspore.common.parameter
import
Parameter
from
mindspore.common.initializer
import
initializer
class
ControlSimpleIf
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
self
.
addn
=
op
.
AddN
()
def
construct
(
self
,
x
,
y
,
z
,
input1
,
input2
):
addn1
=
self
.
addn
([
input1
,
input1
,
input1
])
addn2
=
self
.
addn
([
input2
,
input2
,
input2
])
addn11
=
self
.
addn
([
addn1
,
addn1
,
addn1
])
addn22
=
self
.
addn
([
addn2
,
addn2
,
addn2
])
cond1
=
x
>
y
cond2
=
y
>
z
# dodge pylint
if
cond1
and
cond2
:
out
=
self
.
addn
([
addn11
,
addn11
])
else
:
out
=
self
.
addn
([
addn22
,
addn22
])
out_me
=
self
.
addn
([
out
,
input1
])
return
out_me
class
ControlSimpleIfWithAssign
(
nn
.
Cell
):
def
__init__
(
self
,
input_shape
):
super
().
__init__
()
self
.
addn
=
op
.
AddN
()
self
.
assign
=
op
.
Assign
()
self
.
input_data
=
Parameter
(
initializer
(
1
,
input_shape
,
mstype
.
float32
),
name
=
"var"
)
def
construct
(
self
,
x
,
y
,
input_data
):
if
x
>
y
:
out
=
self
.
addn
([
input_data
,
input_data
,
input_data
])
else
:
out
=
self
.
assign
(
self
.
input_data
,
input_data
)
return
out
class
ControlIfinIf
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
def
construct
(
self
,
x
,
y
):
if
x
>
y
:
x
=
x
+
1
if
y
<
0
:
y
=
y
+
1
else
:
y
=
y
+
2
else
:
x
=
x
+
2
x
=
x
+
y
return
x
class
ControlIfbyIfbyIf
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
self
.
addn
=
op
.
AddN
()
def
construct
(
self
,
x
,
y
,
cond1
,
cond2
,
input_data
):
tri_in
=
self
.
addn
([
input_data
,
input_data
,
input_data
])
if
x
>
y
:
addn_1
=
self
.
addn
([
tri_in
,
tri_in
])
else
:
addn_1
=
self
.
addn
([
tri_in
,
tri_in
,
tri_in
])
if
cond1
:
addn_2
=
self
.
addn
([
addn_1
,
addn_1
])
else
:
addn_2
=
self
.
addn
([
addn_1
,
addn_1
,
addn_1
])
if
cond2
:
out
=
self
.
addn
([
addn_2
,
addn_2
,
addn_2
])
else
:
out
=
self
.
addn
([
addn_2
,
addn_2
])
return
out
class
ControlMixedWhileIf
(
nn
.
Cell
):
def
__init__
(
self
):
super
().
__init__
()
def
construct
(
self
,
x
,
y
):
y
=
y
+
4
while
x
<
y
:
if
2
*
x
<
y
:
x
=
x
+
1
else
:
x
=
x
+
2
x
=
x
+
3
return
x
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_simple_if
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
(
3
).
astype
(
np
.
float32
)
y
=
np
.
array
(
2
).
astype
(
np
.
float32
)
z
=
np
.
array
(
3
).
astype
(
np
.
float32
)
input_shape
=
(
127
,
7
,
53
,
31
)
input1
=
np
.
random
.
randn
(
*
input_shape
).
astype
(
np
.
float32
)
input2
=
np
.
random
.
randn
(
*
input_shape
).
astype
(
np
.
float32
)
net
=
ControlSimpleIf
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
),
Tensor
(
z
),
Tensor
(
input1
),
Tensor
(
input2
))
expect
=
input2
*
3
*
3
*
2
+
input1
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_simple_if_with_assign
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
(
0
).
astype
(
np
.
float32
)
y
=
np
.
array
(
1
).
astype
(
np
.
float32
)
input_shape
=
(
127
,
7
,
53
,
31
)
input_data
=
np
.
random
.
randn
(
*
input_shape
).
astype
(
np
.
float32
)
net
=
ControlSimpleIfWithAssign
(
input_shape
)
output
=
net
(
Tensor
(
x
),
Tensor
(
y
),
Tensor
(
input_data
))
expect
=
input_data
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_if_in_if
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
(
2.345678
).
astype
(
np
.
float32
)
y
=
np
.
array
(
1.234567
).
astype
(
np
.
float32
)
net
=
ControlIfinIf
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
))
expect
=
x
+
y
+
3
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_if_by_if_by_if
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
(
2.345678
).
astype
(
np
.
float32
)
y
=
np
.
array
(
1.234567
).
astype
(
np
.
float32
)
cond1
=
np
.
array
(
True
).
astype
(
np
.
bool
)
cond2
=
np
.
array
(
False
).
astype
(
np
.
bool
)
input_shape
=
(
127
,
7
,
53
,
31
)
input_data
=
np
.
random
.
randn
(
*
input_shape
).
astype
(
np
.
float32
)
net
=
ControlIfbyIfbyIf
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
),
Tensor
(
cond1
),
Tensor
(
cond2
),
Tensor
(
input_data
))
expect
=
input_data
*
3
*
2
*
2
*
2
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
platform_x86_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_mixed_while_if
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
x
=
np
.
array
(
2
).
astype
(
np
.
int32
)
y
=
np
.
array
(
14
).
astype
(
np
.
int32
)
net
=
ControlMixedWhileIf
()
output
=
net
(
Tensor
(
x
),
Tensor
(
y
))
expect
=
np
.
array
(
22
).
astype
(
np
.
int32
)
assert
np
.
allclose
(
expect
,
output
.
asnumpy
(),
0.0001
,
0.0001
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录