Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
82b6c836
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看板
提交
82b6c836
编写于
6月 03, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1765 Pynative support list input
Merge pull request !1765 from JoyLvliang/pynative-support-list-input
上级
6e1dfe5f
e046e6dd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
10 deletion
+31
-10
mindspore/ccsrc/pynative/pynative_execute.cc
mindspore/ccsrc/pynative/pynative_execute.cc
+31
-10
未找到文件。
mindspore/ccsrc/pynative/pynative_execute.cc
浏览文件 @
82b6c836
...
...
@@ -319,6 +319,27 @@ void ConvertValueTupleToTensor(const py::object &input_object, std::vector<tenso
input_tensors
->
push_back
(
tensor_ptr
);
}
void
ConvertMultiPyObjectToTensor
(
const
py
::
object
&
input_object
,
const
PrimitivePtr
&
op_prim
,
std
::
vector
<
tensor
::
TensorPtr
>
*
input_tensors
,
int
*
tensor_mask
)
{
MS_EXCEPTION_IF_NULL
(
op_prim
);
MS_EXCEPTION_IF_NULL
(
input_tensors
);
MS_EXCEPTION_IF_NULL
(
tensor_mask
);
if
(
!
py
::
isinstance
<
py
::
tuple
>
(
input_object
))
{
MS_LOG
(
EXCEPTION
)
<<
"The input should be a tuple!"
;
}
auto
tuple_inputs
=
py
::
cast
<
py
::
tuple
>
(
input_object
);
if
(
tuple_inputs
.
size
()
==
0
)
{
MS_LOG
(
EXCEPTION
)
<<
"The size of input list or tuple is 0!"
;
}
if
(
py
::
isinstance
<
tensor
::
Tensor
>
(
tuple_inputs
[
0
]))
{
PlantTensorTupleToVector
(
tuple_inputs
,
op_prim
,
input_tensors
);
}
else
{
ConvertValueTupleToTensor
(
input_object
,
input_tensors
);
*
tensor_mask
=
kValueNodeTensorMask
;
}
}
void
ConvertPyObjectToTensor
(
const
py
::
object
&
input_object
,
const
PrimitivePtr
&
op_prim
,
std
::
vector
<
tensor
::
TensorPtr
>
*
input_tensors
,
int
*
tensor_mask
)
{
MS_EXCEPTION_IF_NULL
(
op_prim
);
...
...
@@ -333,20 +354,20 @@ void ConvertPyObjectToTensor(const py::object &input_object, const PrimitivePtr
}
else
if
(
py
::
isinstance
<
py
::
int_
>
(
input_object
))
{
tensor_ptr
=
std
::
make_shared
<
tensor
::
Tensor
>
(
py
::
cast
<
py
::
int_
>
(
input_object
),
kInt32
);
*
tensor_mask
=
kValueNodeTensorMask
;
}
else
if
(
py
::
isinstance
<
py
::
list
>
(
input_object
))
{
tensor_ptr
=
std
::
make_shared
<
tensor
::
Tensor
>
(
py
::
cast
<
py
::
list
>
(
input_object
),
nullptr
);
}
else
if
(
py
::
isinstance
<
py
::
array
>
(
input_object
))
{
tensor_ptr
=
std
::
make_shared
<
tensor
::
Tensor
>
(
py
::
cast
<
py
::
array
>
(
input_object
),
nullptr
);
}
else
if
(
py
::
isinstance
<
py
::
none
>
(
input_object
))
{
}
else
if
(
py
::
isinstance
<
py
::
list
>
(
input_object
))
{
auto
list_inputs
=
py
::
cast
<
py
::
list
>
(
input_object
);
py
::
tuple
tuple_inputs
(
list_inputs
.
size
());
for
(
size_t
i
=
0
;
i
<
tuple_inputs
.
size
();
++
i
)
{
tuple_inputs
[
i
]
=
list_inputs
[
i
];
}
ConvertMultiPyObjectToTensor
(
tuple_inputs
,
op_prim
,
input_tensors
,
tensor_mask
);
return
;
}
else
if
(
py
::
isinstance
<
py
::
tuple
>
(
input_object
))
{
auto
tuple_inputs
=
py
::
cast
<
py
::
tuple
>
(
input_object
);
if
(
py
::
isinstance
<
tensor
::
Tensor
>
(
tuple_inputs
[
0
]))
{
PlantTensorTupleToVector
(
tuple_inputs
,
op_prim
,
input_tensors
);
}
else
{
ConvertValueTupleToTensor
(
input_object
,
input_tensors
);
*
tensor_mask
=
kValueNodeTensorMask
;
}
ConvertMultiPyObjectToTensor
(
input_object
,
op_prim
,
input_tensors
,
tensor_mask
);
return
;
}
else
if
(
py
::
isinstance
<
py
::
none
>
(
input_object
))
{
return
;
}
else
{
MS_LOG
(
EXCEPTION
)
<<
"Run op inputs type is invalid!"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录