Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_44025039
mindspore
提交
f84b0552
M
mindspore
项目概览
weixin_44025039
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f84b0552
编写于
7月 22, 2020
作者:
B
buxue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add check for implicit conversion when scalar is not number and bool.
上级
9351739b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
5 deletion
+33
-5
mindspore/ccsrc/pipeline/jit/parse/function_block.cc
mindspore/ccsrc/pipeline/jit/parse/function_block.cc
+1
-1
mindspore/ccsrc/pipeline/jit/parse/function_block.h
mindspore/ccsrc/pipeline/jit/parse/function_block.h
+1
-1
mindspore/ccsrc/pipeline/pynative/pynative_execute.cc
mindspore/ccsrc/pipeline/pynative/pynative_execute.cc
+6
-0
tests/ut/python/pynative_mode/test_implicit_conversion.py
tests/ut/python/pynative_mode/test_implicit_conversion.py
+25
-3
未找到文件。
mindspore/ccsrc/pipeline/jit/parse/function_block.cc
浏览文件 @
f84b0552
...
...
@@ -99,7 +99,7 @@ AnfNodePtr FunctionBlock::MakeResolveAstOp(const py::object &op) {
}
// Resolve class member, two possible: method, member variable
AnfNodePtr
FunctionBlock
::
MakeResolveClassMember
(
std
::
string
attr
)
{
AnfNodePtr
FunctionBlock
::
MakeResolveClassMember
(
const
std
::
string
&
attr
)
{
py
::
object
namespace_var
=
parser_
.
ast
()
->
CallParseModFunction
(
PYTHON_MOD_GET_MEMBER_NAMESPACE_SYMBOL
,
parser_
.
ast
()
->
obj
());
NameSpacePtr
name_space
=
std
::
make_shared
<
NameSpace
>
(
RESOLVE_NAMESPACE_NAME_CLASS_MEMBER
,
namespace_var
);
...
...
mindspore/ccsrc/pipeline/jit/parse/function_block.h
浏览文件 @
f84b0552
...
...
@@ -68,7 +68,7 @@ class FunctionBlock : public std::enable_shared_from_this<FunctionBlock> {
void
AddGlobalVar
(
const
std
::
string
&
var_name
)
{
(
void
)
global_vars_
.
insert
(
var_name
);
}
bool
IsGlobalVar
(
const
std
::
string
&
var_name
)
{
return
global_vars_
.
find
(
var_name
)
!=
global_vars_
.
end
();
}
AnfNodePtr
MakeResolveAstOp
(
const
py
::
object
&
op
);
AnfNodePtr
MakeResolveClassMember
(
std
::
string
attr
);
AnfNodePtr
MakeResolveClassMember
(
const
std
::
string
&
attr
);
AnfNodePtr
MakeResolveSymbol
(
const
std
::
string
&
value
);
AnfNodePtr
MakeResolveOperation
(
const
std
::
string
&
value
);
AnfNodePtr
MakeResolve
(
const
std
::
shared_ptr
<
NameSpace
>
&
name_space
,
const
std
::
shared_ptr
<
Symbol
>
&
resolve_symbol
);
...
...
mindspore/ccsrc/pipeline/pynative/pynative_execute.cc
浏览文件 @
f84b0552
...
...
@@ -268,6 +268,12 @@ py::tuple ConvertInputs(const PrimitivePyPtr &prim, const py::list &args, py::tu
TypeIdToMsTypeStr
(
it
->
second
));
}
}
if
(
!
py
::
isinstance
<
tensor
::
Tensor
>
(
py_args
[
i
])
&&
!
py
::
isinstance
<
py
::
int_
>
(
py_args
[
i
])
&&
!
py
::
isinstance
<
py
::
float_
>
(
py_args
[
i
]))
{
MS_EXCEPTION
(
TypeError
)
<<
"For '"
<<
prim
->
name
()
<<
"', the "
<<
i
<<
"th input is a not support type: "
<<
py
::
cast
<
std
::
string
>
(
py_args
[
1
].
attr
(
"__class__"
).
attr
(
"__name__"
))
<<
", and the value is "
<<
py
::
cast
<
py
::
str
>
(
py_args
[
i
])
<<
"."
;
}
py
::
object
cast_output
=
DoAutoCast
(
py_args
[
i
],
it
->
second
);
(
*
out_args
)[
i
]
=
cast_output
;
(
*
out_args_list
)[
i
]
=
cast_output
;
...
...
tests/ut/python/pynative_mode/test_implicit_conversion.py
浏览文件 @
f84b0552
...
...
@@ -14,6 +14,7 @@
# ============================================================================
""" test implicit conversion """
import
numpy
as
np
import
pytest
from
mindspore
import
Tensor
,
nn
from
mindspore.ops
import
composite
as
C
...
...
@@ -90,6 +91,30 @@ def test_float_tensor_and_bool_tensors_add():
assert
(
ret_actual
.
asnumpy
()
==
ret_expect
.
asnumpy
()).
all
()
def
test_float_tensor_and_str_add
():
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
float32
))
y
=
"ok"
with
pytest
.
raises
(
TypeError
)
as
er
:
ret
=
x
+
y
assert
"For 'TensorAdd', the 1th input is a not support type: str"
in
str
(
er
.
value
)
def
test_float_tensor_and_tuple_add
():
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
float32
))
y
=
(
1
,
2
,
3
)
with
pytest
.
raises
(
TypeError
)
as
er
:
ret
=
x
+
y
assert
"For 'TensorAdd', the 1th input is a not support type: tuple"
in
str
(
er
.
value
)
def
test_float_tensor_and_list_add
():
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
float32
))
y
=
[
1
,
2
,
3
]
with
pytest
.
raises
(
TypeError
)
as
er
:
ret
=
x
+
y
assert
"For 'TensorAdd', the 1th input is a not support type: list"
in
str
(
er
.
value
)
def
test_float_tensor_and_bool_tensors_add_grad
():
class
Net
(
nn
.
Cell
):
def
__init__
(
self
):
...
...
@@ -104,7 +129,6 @@ def test_float_tensor_and_bool_tensors_add_grad():
self
.
net
=
net
def
construct
(
self
,
x
,
y
,
sens
):
return
C
.
grad_all_with_sens
(
self
.
net
)(
x
,
y
,
sens
)
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
float32
))
...
...
@@ -133,7 +157,6 @@ def test_float_tensor_and_int_tensors_sub_grad():
self
.
net
=
net
def
construct
(
self
,
x
,
y
,
sens
):
return
C
.
grad_all_with_sens
(
self
.
net
)(
x
,
y
,
sens
)
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
float32
))
...
...
@@ -163,7 +186,6 @@ def test_float16_tensor_and_float32_tensors_sub_grad():
self
.
net
=
net
def
construct
(
self
,
x
,
y
,
sens
):
return
C
.
grad_all_with_sens
(
self
.
net
)(
x
,
y
,
sens
)
x
=
Tensor
(
np
.
array
([[
0.1
,
0.2
,
0.3
],
[
0.4
,
0.5
,
0.6
]],
dtype
=
np
.
int32
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录