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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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})
  47. .SetRowsPerBuffer(16)
  48. .SetWorkerConnectorSize(16)
  49. .SetNumWorkers(16);
  50. std::unique_ptr<DataSchema> schema1 = std::make_unique<DataSchema>();
  51. schema1->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  52. builder1.SetDataSchema(std::move(schema1));
  53. Status rc = builder1.Build(&my_tfreader_op1);
  54. ASSERT_TRUE(rc.IsOk());
  55. rc = my_tree->AssociateNode(my_tfreader_op1);
  56. ASSERT_TRUE(rc.IsOk());
  57. // TFReaderOp2
  58. std::shared_ptr<TFReaderOp> my_tfreader_op2;
  59. TFReaderOp::Builder builder2;
  60. builder2.SetDatasetFilesList({dataset_path})
  61. .SetRowsPerBuffer(16)
  62. .SetWorkerConnectorSize(16)
  63. .SetNumWorkers(16);
  64. std::unique_ptr<DataSchema> schema2 = std::make_unique<DataSchema>();
  65. schema2->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  66. builder2.SetDataSchema(std::move(schema2));
  67. rc = builder2.Build(&my_tfreader_op2);
  68. ASSERT_TRUE(rc.IsOk());
  69. rc = my_tree->AssociateNode(my_tfreader_op2);
  70. ASSERT_TRUE(rc.IsOk());
  71. // Creating ConcatOp
  72. std::shared_ptr<ConcatOp> concat_op;
  73. rc = ConcatOp::Builder().Build(&concat_op);
  74. EXPECT_TRUE(rc.IsOk());
  75. rc = my_tree->AssociateNode(concat_op);
  76. EXPECT_TRUE(rc.IsOk());
  77. rc = concat_op->AddChild(std::move(my_tfreader_op1));
  78. EXPECT_TRUE(rc.IsOk());
  79. rc = concat_op->AddChild(std::move(my_tfreader_op2));
  80. EXPECT_TRUE(rc.IsOk());
  81. rc = my_tree->AssignRoot(concat_op);
  82. EXPECT_TRUE(rc.IsOk());
  83. rc = my_tree->Prepare();
  84. EXPECT_TRUE(rc.IsOk());
  85. // Launch the tree execution to kick off threads and start running the pipeline
  86. MS_LOG(INFO) << "Launching my tree.";
  87. rc = my_tree->Launch();
  88. EXPECT_TRUE(rc.IsOk());
  89. // Simulate a parse of data from our pipeline.
  90. std::shared_ptr<DatasetOp> rootNode = my_tree->root();
  91. DatasetIterator di(my_tree);
  92. TensorRow tensor_list;
  93. rc = di.FetchNextTensorRow(&tensor_list);
  94. EXPECT_TRUE(rc.IsOk());
  95. int row_count = 0;
  96. while (!tensor_list.empty()) {
  97. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  98. // Display the tensor by calling the printer on it
  99. for (int i = 0; i < tensor_list.size(); i++) {
  100. std::ostringstream ss;
  101. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  102. MS_LOG(INFO) << "Tensor print: " << common::SafeCStr(ss.str()) << ".";
  103. }
  104. rc = di.FetchNextTensorRow(&tensor_list);
  105. EXPECT_TRUE(rc.IsOk());
  106. row_count++;
  107. }
  108. ASSERT_EQ(row_count, 24); // Should be 24 rows fetched
  109. }