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

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