Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
79445012
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看板
提交
79445012
编写于
7月 03, 2020
作者:
E
Eric
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tensor ut works
new test case Name change for empty check
上级
915ddd25
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
0 deletion
+27
-0
mindspore/ccsrc/dataset/core/tensor.cc
mindspore/ccsrc/dataset/core/tensor.cc
+9
-0
mindspore/ccsrc/dataset/core/tensor.h
mindspore/ccsrc/dataset/core/tensor.h
+4
-0
tests/ut/cpp/dataset/tensor_test.cc
tests/ut/cpp/dataset/tensor_test.cc
+14
-0
未找到文件。
mindspore/ccsrc/dataset/core/tensor.cc
浏览文件 @
79445012
...
...
@@ -513,6 +513,15 @@ const unsigned char *Tensor::GetBuffer() const {
return
data_
;
}
// check for empty
bool
Tensor
::
HasData
()
const
{
if
(
data_
==
nullptr
)
{
return
true
;
}
else
{
return
false
;
}
}
unsigned
char
*
Tensor
::
GetMutableBuffer
()
{
if
(
!
shape_
.
known
()
||
type_
==
DataType
::
DE_UNKNOWN
)
{
return
nullptr
;
...
...
mindspore/ccsrc/dataset/core/tensor.h
浏览文件 @
79445012
...
...
@@ -277,6 +277,10 @@ class Tensor {
// @return
const
TensorShape
&
shape
()
const
{
return
shape_
;
}
/// Check if tensor has data
/// \return bool - true if tensor is empty
bool
HasData
()
const
;
// Reshape the tensor. The given shape should have the same number of elements in the Tensor
// @param shape
virtual
Status
Reshape
(
const
TensorShape
&
shape
);
...
...
tests/ut/cpp/dataset/tensor_test.cc
浏览文件 @
79445012
...
...
@@ -432,3 +432,17 @@ TEST_F(MindDataTestTensorDE, TensorConcatenate) {
s
=
t1
->
Concatenate
({
5
},
t2
);
EXPECT_FALSE
(
s
.
IsOk
());
}
TEST_F
(
MindDataTestTensorDE
,
TensorEmpty
)
{
std
::
shared_ptr
<
Tensor
>
t
=
std
::
make_shared
<
Tensor
>
(
TensorShape
({
2
,
3
}),
DataType
(
DataType
::
DE_UINT64
));
ASSERT_TRUE
(
t
->
HasData
());
}
TEST_F
(
MindDataTestTensorDE
,
TensorEmptyInvalidate
)
{
std
::
vector
<
uint32_t
>
values1
=
{
1
,
2
,
3
,
0
,
0
,
0
};
std
::
shared_ptr
<
Tensor
>
t
;
Tensor
::
CreateTensor
(
&
t
,
values1
);
t
->
Invalidate
();
ASSERT_TRUE
(
t
->
HasData
());
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录