You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

concat_op_test.cc 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <iostream>
  17. #include <memory>
  18. #include <vector>
  19. #include "common/common.h"
  20. #include "utils/ms_utils.h"
  21. #include "minddata/dataset/core/client.h"
  22. #include "gtest/gtest.h"
  23. #include "utils/log_adapter.h"
  24. namespace common = mindspore::common;
  25. using namespace mindspore::dataset;
  26. using mindspore::MsLogLevel::INFO;
  27. using mindspore::ExceptionType::NoExceptionType;
  28. using mindspore::LogStream;
  29. class MindDataTestConcatOp : public UT::DatasetOpTesting {};
  30. TEST_F(MindDataTestConcatOp, TestConcatProject) {
  31. /* Tree:
  32. *
  33. * OpId(2) ConcatOp
  34. * / \
  35. * OpId(0) TFReaderOp OpId(1) TFReaderOp
  36. *
  37. * Start with an empty execution tree
  38. */
  39. MS_LOG(INFO) << "UT test TestConcatProject.";
  40. auto my_tree = std::make_shared<ExecutionTree>();
  41. std::string dataset_path;
  42. dataset_path = datasets_root_path_ + "/testTFTestAllTypes/test.data";
  43. // TFReaderOp1
  44. std::shared_ptr<TFReaderOp> my_tfreader_op1;
  45. TFReaderOp::Builder builder1;
  46. builder1.SetDatasetFilesList({dataset_path}).SetWorkerConnectorSize(16);
  47. std::unique_ptr<DataSchema> schema1 = std::make_unique<DataSchema>();
  48. schema1->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema1Row.json", {});
  49. builder1.SetDataSchema(std::move(schema1));
  50. Status rc = builder1.Build(&my_tfreader_op1);
  51. ASSERT_TRUE(rc.IsOk());
  52. rc = my_tree->AssociateNode(my_tfreader_op1);
  53. ASSERT_TRUE(rc.IsOk());
  54. // TFReaderOp2
  55. std::shared_ptr<TFReaderOp> my_tfreader_op2;
  56. TFReaderOp::Builder builder2;
  57. builder2.SetDatasetFilesList({dataset_path}).SetWorkerConnectorSize(16);
  58. std::unique_ptr<DataSchema> schema2 = std::make_unique<DataSchema>();
  59. schema2->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema1Row.json", {});
  60. builder2.SetDataSchema(std::move(schema2));
  61. rc = builder2.Build(&my_tfreader_op2);
  62. ASSERT_TRUE(rc.IsOk());
  63. rc = my_tree->AssociateNode(my_tfreader_op2);
  64. ASSERT_TRUE(rc.IsOk());
  65. // Creating ConcatOp
  66. std::shared_ptr<ConcatOp> concat_op;
  67. rc = ConcatOp::Builder().Build(&concat_op);
  68. EXPECT_TRUE(rc.IsOk());
  69. rc = my_tree->AssociateNode(concat_op);
  70. EXPECT_TRUE(rc.IsOk());
  71. rc = concat_op->AddChild(std::move(my_tfreader_op1));
  72. EXPECT_TRUE(rc.IsOk());
  73. rc = concat_op->AddChild(std::move(my_tfreader_op2));
  74. EXPECT_TRUE(rc.IsOk());
  75. rc = my_tree->AssignRoot(concat_op);
  76. EXPECT_TRUE(rc.IsOk());
  77. rc = my_tree->Prepare();
  78. EXPECT_TRUE(rc.IsOk());
  79. // Launch the tree execution to kick off threads and start running the pipeline
  80. MS_LOG(INFO) << "Launching my tree.";
  81. rc = my_tree->Launch();
  82. EXPECT_TRUE(rc.IsOk());
  83. // Simulate a parse of data from our pipeline.
  84. std::shared_ptr<DatasetOp> rootNode = my_tree->root();
  85. DatasetIterator di(my_tree);
  86. TensorRow tensor_list;
  87. rc = di.FetchNextTensorRow(&tensor_list);
  88. EXPECT_TRUE(rc.IsOk());
  89. int row_count = 0;
  90. while (!tensor_list.empty()) {
  91. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  92. // Display the tensor by calling the printer on it
  93. for (int i = 0; i < tensor_list.size(); i++) {
  94. std::ostringstream ss;
  95. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  96. MS_LOG(INFO) << "Tensor print: " << common::SafeCStr(ss.str()) << ".";
  97. }
  98. rc = di.FetchNextTensorRow(&tensor_list);
  99. EXPECT_TRUE(rc.IsOk());
  100. row_count++;
  101. }
  102. ASSERT_EQ(row_count, 2); // Should be 2 rows fetched
  103. }