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.

project_op_test.cc 3.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Copyright 2019 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 MindDataTestProjectOp : public UT::DatasetOpTesting {};
  30. TEST_F(MindDataTestProjectOp, TestProjectProject) {
  31. // Start with an empty execution tree
  32. auto my_tree = std::make_shared<ExecutionTree>();
  33. std::string dataset_path;
  34. dataset_path = datasets_root_path_ + "/testTFTestAllTypes/test.data";
  35. std::shared_ptr<TFReaderOp> my_tfreader_op;
  36. TFReaderOp::Builder builder;
  37. builder.SetDatasetFilesList({dataset_path}).SetWorkerConnectorSize(16);
  38. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  39. schema->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  40. builder.SetDataSchema(std::move(schema));
  41. Status rc = builder.Build(&my_tfreader_op); ASSERT_TRUE(rc.IsOk());
  42. rc = my_tree->AssociateNode(my_tfreader_op);
  43. ASSERT_TRUE(rc.IsOk());
  44. // ProjectOp
  45. std::vector<std::string> columns_to_project = {"col_sint16", "col_float", "col_2d"};
  46. std::shared_ptr<ProjectOp> my_project_op = std::make_shared<ProjectOp>(columns_to_project);
  47. rc = my_tree->AssociateNode(my_project_op);
  48. ASSERT_TRUE(rc.IsOk());
  49. // Set children/root layout.
  50. rc = my_project_op->AddChild(my_tfreader_op);
  51. ASSERT_TRUE(rc.IsOk());
  52. rc = my_tree->AssignRoot(my_project_op);
  53. ASSERT_TRUE(rc.IsOk());
  54. MS_LOG(INFO) << "Launching tree and begin iteration.";
  55. rc = my_tree->Prepare();
  56. ASSERT_TRUE(rc.IsOk());
  57. rc = my_tree->Launch();
  58. ASSERT_TRUE(rc.IsOk());
  59. // Start the loop of reading tensors from our pipeline
  60. DatasetIterator di(my_tree);
  61. TensorRow tensor_list;
  62. rc = di.FetchNextTensorRow(&tensor_list);
  63. ASSERT_TRUE(rc.IsOk());
  64. int row_count = 0;
  65. while (!tensor_list.empty()) {
  66. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  67. ASSERT_EQ(tensor_list.size(), columns_to_project.size());
  68. // Display the tensor by calling the printer on it
  69. for (int i = 0; i < tensor_list.size(); i++) {
  70. std::ostringstream ss;
  71. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  72. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  73. }
  74. rc = di.FetchNextTensorRow(&tensor_list);
  75. ASSERT_TRUE(rc.IsOk());
  76. row_count++;
  77. }
  78. ASSERT_EQ(row_count, 12);
  79. }