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 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "minddata/dataset/util/circular_pool.h"
  17. #include "minddata/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}).SetWorkerConnectorSize(16);
  34. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  35. schema->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  36. builder.SetDataSchema(std::move(schema));
  37. Status rc = builder.Build(&my_tfreader_op); ASSERT_TRUE(rc.IsOk());
  38. rc = my_tree->AssociateNode(my_tfreader_op);
  39. ASSERT_TRUE(rc.IsOk());
  40. // SkipOp
  41. std::shared_ptr<SkipOp> skip_op = std::make_shared<SkipOp>(5);
  42. rc = my_tree->AssociateNode(skip_op);
  43. ASSERT_TRUE(rc.IsOk());
  44. // Set children/root layout.
  45. rc = skip_op->AddChild(my_tfreader_op);
  46. ASSERT_TRUE(rc.IsOk());
  47. rc = my_tree->AssignRoot(skip_op);
  48. ASSERT_TRUE(rc.IsOk());
  49. MS_LOG(INFO) << "Launching tree and begin iteration.";
  50. rc = my_tree->Prepare();
  51. ASSERT_TRUE(rc.IsOk());
  52. rc = my_tree->Launch();
  53. ASSERT_TRUE(rc.IsOk());
  54. // Start the loop of reading tensors from our pipeline
  55. DatasetIterator di(my_tree);
  56. TensorRow tensor_list;
  57. rc = di.FetchNextTensorRow(&tensor_list);
  58. ASSERT_TRUE(rc.IsOk());
  59. int row_count = 0;
  60. while (!tensor_list.empty()) {
  61. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  62. // Display the tensor by calling the printer on it
  63. for (int i = 0; i < tensor_list.size(); i++) {
  64. std::ostringstream ss;
  65. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  66. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  67. }
  68. rc = di.FetchNextTensorRow(&tensor_list);
  69. ASSERT_TRUE(rc.IsOk());
  70. row_count++;
  71. }
  72. ASSERT_EQ(row_count, 7);
  73. }