提交 79445012 编写于 作者: E Eric

Tensor ut works

new test case

Name change for empty check
上级 915ddd25
......@@ -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;
......
......@@ -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);
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册