forked from mindspore-Ecosystem/mindspore
!7538 Add empty string tensor support for Album
Merge pull request !7538 from EricZ/album_empty_string
This commit is contained in:
commit
643366ea70
|
@ -301,7 +301,7 @@ class Tensor {
|
||||||
const TensorShape &shape() const { return shape_; }
|
const TensorShape &shape() const { return shape_; }
|
||||||
|
|
||||||
/// Check if tensor has data
|
/// 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; }
|
bool HasData() const { return data_ != nullptr; }
|
||||||
|
|
||||||
/// Reshape the tensor. The given shape should have the same number of elements in the Tensor
|
/// Reshape the tensor. The given shape should have the same number of elements in the Tensor
|
||||||
|
|
|
@ -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) {
|
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
|
// hack to get the file name without extension, the 1 is to get rid of the backslash character
|
||||||
TensorPtr empty_tensor;
|
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));
|
row->push_back(std::move(empty_tensor));
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ TEST_F(MindDataTestSchema, TestAlbumSchema) {
|
||||||
} else {
|
} else {
|
||||||
int32_t num_cols = schema->NumColumns();
|
int32_t num_cols = schema->NumColumns();
|
||||||
MS_LOG(INFO) << "num_cols: " << num_cols << ".";
|
MS_LOG(INFO) << "num_cols: " << num_cols << ".";
|
||||||
EXPECT_TRUE(num_cols == 7);
|
EXPECT_TRUE(num_cols == 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,17 @@ TEST_F(MindDataTestStringTensorDE, Empty) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MindDataTestStringTensorDE, EmptyData) {
|
||||||
|
std::shared_ptr<Tensor> t;
|
||||||
|
Tensor::CreateScalar<std::string>("", &t);
|
||||||
|
// empty string has 1 element
|
||||||
|
ASSERT_TRUE(t->HasData());
|
||||||
|
|
||||||
|
std::shared_ptr<Tensor> t1;
|
||||||
|
Tensor::CreateEmpty(TensorShape({0}), DataType(DataType::DE_STRING), &t1);
|
||||||
|
ASSERT_TRUE(!t1->HasData());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MindDataTestStringTensorDE, SetItem) {
|
TEST_F(MindDataTestStringTensorDE, SetItem) {
|
||||||
std::vector<std::string> strings{"abc", "defg", "hi", "klmno", "123", "789"};
|
std::vector<std::string> strings{"abc", "defg", "hi", "klmno", "123", "789"};
|
||||||
std::shared_ptr<Tensor> t3;
|
std::shared_ptr<Tensor> t3;
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"rank": 1
|
"rank": 1
|
||||||
},
|
},
|
||||||
|
"optional" : {
|
||||||
|
"type": "string",
|
||||||
|
"rank": 1
|
||||||
|
},
|
||||||
"id" : {
|
"id" : {
|
||||||
"type": "int64",
|
"type": "int64",
|
||||||
"rank": 0
|
"rank": 0
|
||||||
|
|
Loading…
Reference in New Issue