diff --git a/mindspore/ccsrc/minddata/dataset/core/tensor.h b/mindspore/ccsrc/minddata/dataset/core/tensor.h index 349f45a8f3b..a5d0c5b59dd 100644 --- a/mindspore/ccsrc/minddata/dataset/core/tensor.h +++ b/mindspore/ccsrc/minddata/dataset/core/tensor.h @@ -301,7 +301,7 @@ class Tensor { const TensorShape &shape() const { return shape_; } /// Check if tensor has data - /// \return bool - true if tensor is empty + /// \return bool - true if tensor is not empty bool HasData() const { return data_ != nullptr; } /// Reshape the tensor. The given shape should have the same number of elements in the Tensor diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc index fcfd66f97ad..0aa9c3c9322 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc @@ -380,7 +380,7 @@ Status AlbumOp::LoadIDTensor(const std::string &file, uint32_t col_num, TensorRo Status AlbumOp::LoadEmptyTensor(uint32_t col_num, TensorRow *row) { // hack to get the file name without extension, the 1 is to get rid of the backslash character TensorPtr empty_tensor; - RETURN_IF_NOT_OK(Tensor::CreateEmpty(TensorShape({}), data_schema_->column(col_num).type(), &empty_tensor)); + RETURN_IF_NOT_OK(Tensor::CreateEmpty(TensorShape({0}), data_schema_->column(col_num).type(), &empty_tensor)); row->push_back(std::move(empty_tensor)); return Status::OK(); } diff --git a/tests/ut/cpp/dataset/schema_test.cc b/tests/ut/cpp/dataset/schema_test.cc index d4c47cdf51e..a387ec6dc92 100644 --- a/tests/ut/cpp/dataset/schema_test.cc +++ b/tests/ut/cpp/dataset/schema_test.cc @@ -62,7 +62,7 @@ TEST_F(MindDataTestSchema, TestAlbumSchema) { } else { int32_t num_cols = schema->NumColumns(); MS_LOG(INFO) << "num_cols: " << num_cols << "."; - EXPECT_TRUE(num_cols == 7); + EXPECT_TRUE(num_cols == 8); } } diff --git a/tests/ut/cpp/dataset/tensor_string_test.cc b/tests/ut/cpp/dataset/tensor_string_test.cc index 232fefc2ae9..db55b4430f1 100644 --- a/tests/ut/cpp/dataset/tensor_string_test.cc +++ b/tests/ut/cpp/dataset/tensor_string_test.cc @@ -117,6 +117,17 @@ TEST_F(MindDataTestStringTensorDE, Empty) { } } +TEST_F(MindDataTestStringTensorDE, EmptyData) { + std::shared_ptr t; + Tensor::CreateScalar("", &t); + // empty string has 1 element + ASSERT_TRUE(t->HasData()); + + std::shared_ptr t1; + Tensor::CreateEmpty(TensorShape({0}), DataType(DataType::DE_STRING), &t1); + ASSERT_TRUE(!t1->HasData()); +} + TEST_F(MindDataTestStringTensorDE, SetItem) { std::vector strings{"abc", "defg", "hi", "klmno", "123", "789"}; std::shared_ptr t3; @@ -159,4 +170,4 @@ TEST_F(MindDataTestStringTensorDE, Iterator) { ASSERT_TRUE(*itr == strings[index]); index += 2; } -} \ No newline at end of file +} diff --git a/tests/ut/data/dataset/testAlbum/fullSchema.json b/tests/ut/data/dataset/testAlbum/fullSchema.json index 6e9f497468b..1e99b240fdb 100644 --- a/tests/ut/data/dataset/testAlbum/fullSchema.json +++ b/tests/ut/data/dataset/testAlbum/fullSchema.json @@ -8,6 +8,10 @@ "type": "string", "rank": 1 }, + "optional" : { + "type": "string", + "rank": 1 + }, "id" : { "type": "int64", "rank": 0