Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
cc23f1d8
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看板
提交
cc23f1d8
编写于
8月 18, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 18, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4630 Adding wrapper around CreateFromMemory
Merge pull request !4630 from EricZ/md_tensor_from_mem
上级
113ff6ca
26d968af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
0 deletion
+31
-0
mindspore/ccsrc/minddata/dataset/api/de_tensor.cc
mindspore/ccsrc/minddata/dataset/api/de_tensor.cc
+13
-0
mindspore/ccsrc/minddata/dataset/include/de_tensor.h
mindspore/ccsrc/minddata/dataset/include/de_tensor.h
+8
-0
mindspore/lite/test/ut/src/dataset/de_tensor_test.cc
mindspore/lite/test/ut/src/dataset/de_tensor_test.cc
+10
-0
未找到文件。
mindspore/ccsrc/minddata/dataset/api/de_tensor.cc
浏览文件 @
cc23f1d8
...
@@ -95,6 +95,19 @@ MSTensor *DETensor::CreateTensor(const std::string &path) {
...
@@ -95,6 +95,19 @@ MSTensor *DETensor::CreateTensor(const std::string &path) {
return
new
DETensor
(
std
::
move
(
t
));
return
new
DETensor
(
std
::
move
(
t
));
}
}
MSTensor
*
DETensor
::
CreateFromMemory
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
,
void
*
data
)
{
std
::
shared_ptr
<
dataset
::
Tensor
>
t
;
// prepare shape info
std
::
vector
<
dataset
::
dsize_t
>
t_shape
;
std
::
transform
(
shape
.
begin
(),
shape
.
end
(),
std
::
back_inserter
(
t_shape
),
[](
int
s
)
->
dataset
::
dsize_t
{
return
static_cast
<
dataset
::
dsize_t
>
(
s
);
});
(
void
)
dataset
::
Tensor
::
CreateFromMemory
(
dataset
::
TensorShape
(
t_shape
),
MSTypeToDEType
(
data_type
),
static_cast
<
uchar
*>
(
data
),
&
t
);
return
new
DETensor
(
std
::
move
(
t
));
}
DETensor
::
DETensor
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
)
{
DETensor
::
DETensor
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
)
{
std
::
vector
<
dataset
::
dsize_t
>
t_shape
;
std
::
vector
<
dataset
::
dsize_t
>
t_shape
;
t_shape
.
reserve
(
shape
.
size
());
t_shape
.
reserve
(
shape
.
size
());
...
...
mindspore/ccsrc/minddata/dataset/include/de_tensor.h
浏览文件 @
cc23f1d8
...
@@ -37,6 +37,14 @@ class DETensor : public MSTensor {
...
@@ -37,6 +37,14 @@ class DETensor : public MSTensor {
/// \return - MSTensor pointer.
/// \return - MSTensor pointer.
static
MSTensor
*
CreateTensor
(
const
std
::
string
&
path
);
static
MSTensor
*
CreateTensor
(
const
std
::
string
&
path
);
/// \brief Create a MSTensor pointer.
/// \note This function returns null_ptr if tensor creation fails.
/// \param[data_type] DataTypeId of tensor to be created.
/// \param[shape] Shape of tensor to be created.
/// \param[data] Data pointer.
/// \return - MSTensor pointer.
static
MSTensor
*
CreateFromMemory
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
,
void
*
data
);
DETensor
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
);
DETensor
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
);
explicit
DETensor
(
std
::
shared_ptr
<
dataset
::
Tensor
>
tensor_ptr
);
explicit
DETensor
(
std
::
shared_ptr
<
dataset
::
Tensor
>
tensor_ptr
);
...
...
mindspore/lite/test/ut/src/dataset/de_tensor_test.cc
浏览文件 @
cc23f1d8
...
@@ -96,3 +96,13 @@ TEST_F(MindDataTestTensorDE, MSTensorHash) {
...
@@ -96,3 +96,13 @@ TEST_F(MindDataTestTensorDE, MSTensorHash) {
auto
ms_tensor
=
std
::
shared_ptr
<
MSTensor
>
(
new
DETensor
(
t
));
auto
ms_tensor
=
std
::
shared_ptr
<
MSTensor
>
(
new
DETensor
(
t
));
ASSERT_EQ
(
ms_tensor
->
hash
()
==
11093771382437
,
true
);
ASSERT_EQ
(
ms_tensor
->
hash
()
==
11093771382437
,
true
);
}
}
TEST_F
(
MindDataTestTensorDE
,
MSTensorCreateFromMemory
)
{
std
::
vector
<
float
>
x
=
{
2.5
,
2.5
,
2.5
,
2.5
};
auto
mem_tensor
=
DETensor
::
CreateFromMemory
(
mindspore
::
TypeId
::
kNumberTypeFloat32
,
{
2
,
2
},
&
x
[
0
]);
std
::
shared_ptr
<
Tensor
>
t
;
Tensor
::
CreateFromVector
(
x
,
TensorShape
({
2
,
2
}),
&
t
);
auto
ms_tensor
=
std
::
shared_ptr
<
MSTensor
>
(
new
DETensor
(
t
));
ASSERT_EQ
(
ms_tensor
->
hash
()
==
mem_tensor
->
hash
(),
true
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录