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.

skip_op_test.cc 3.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "dataset/util/circular_pool.h"
  17. #include "dataset/core/client.h"
  18. #include "common/common.h"
  19. #include "gtest/gtest.h"
  20. #include "utils/log_adapter.h"
  21. using namespace mindspore::dataset;
  22. using mindspore::MsLogLevel::INFO;
  23. using mindspore::ExceptionType::NoExceptionType;
  24. using mindspore::LogStream;
  25. class MindDataTestSkipOp : public UT::DatasetOpTesting {};
  26. TEST_F(MindDataTestSkipOp, TestSkipOpFuntions) {
  27. // Start with an empty execution tree
  28. auto my_tree = std::make_shared<ExecutionTree>();
  29. std::string dataset_path;
  30. dataset_path = datasets_root_path_ + "/testTFTestAllTypes/test.data";
  31. std::shared_ptr<TFReaderOp> my_tfreader_op;
  32. TFReaderOp::Builder builder;
  33. builder.SetDatasetFilesList({dataset_path})
  34. .SetRowsPerBuffer(16)
  35. .SetWorkerConnectorSize(16)
  36. .SetNumWorkers(16);
  37. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  38. schema->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  39. builder.SetDataSchema(std::move(schema));
  40. Status rc = builder.Build(&my_tfreader_op); ASSERT_TRUE(rc.IsOk());
  41. rc = my_tree->AssociateNode(my_tfreader_op);
  42. ASSERT_TRUE(rc.IsOk());
  43. // SkipOp
  44. std::shared_ptr<SkipOp> skip_op = std::make_shared<SkipOp>(5);
  45. rc = my_tree->AssociateNode(skip_op);
  46. ASSERT_TRUE(rc.IsOk());
  47. // Set children/root layout.
  48. rc = skip_op->AddChild(my_tfreader_op);
  49. ASSERT_TRUE(rc.IsOk());
  50. rc = my_tree->AssignRoot(skip_op);
  51. ASSERT_TRUE(rc.IsOk());
  52. MS_LOG(INFO) << "Launching tree and begin iteration.";
  53. rc = my_tree->Prepare();
  54. ASSERT_TRUE(rc.IsOk());
  55. rc = my_tree->Launch();
  56. ASSERT_TRUE(rc.IsOk());
  57. // Start the loop of reading tensors from our pipeline
  58. DatasetIterator di(my_tree);
  59. TensorRow tensor_list;
  60. rc = di.FetchNextTensorRow(&tensor_list);
  61. ASSERT_TRUE(rc.IsOk());
  62. int row_count = 0;
  63. while (!tensor_list.empty()) {
  64. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  65. // Display the tensor by calling the printer on it
  66. for (int i = 0; i < tensor_list.size(); i++) {
  67. std::ostringstream ss;
  68. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  69. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  70. }
  71. rc = di.FetchNextTensorRow(&tensor_list);
  72. ASSERT_TRUE(rc.IsOk());
  73. row_count++;
  74. }
  75. ASSERT_EQ(row_count, 7);
  76. }