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.

take_op_test.cc 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "common/utils.h"
  21. #include "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 MindDataTestTakeOp : public UT::DatasetOpTesting {};
  30. TEST_F(MindDataTestTakeOp, TestTakeProject) {
  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. // TFReaderOp
  36. std::shared_ptr<TFReaderOp> my_tfreader_op;
  37. TFReaderOp::Builder builder;
  38. builder.SetDatasetFilesList({dataset_path})
  39. .SetRowsPerBuffer(16)
  40. .SetWorkerConnectorSize(16)
  41. .SetNumWorkers(16);
  42. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  43. schema->LoadSchemaFile(datasets_root_path_ + "/testTFTestAllTypes/datasetSchema.json", {});
  44. builder.SetDataSchema(std::move(schema));
  45. Status rc = builder.Build(&my_tfreader_op);
  46. ASSERT_TRUE(rc.IsOk());
  47. // TakeOp
  48. std::shared_ptr<TakeOp> my_take_op;
  49. TakeOp::Builder builder_take(5);
  50. rc = builder_take.Build(&my_take_op);
  51. ASSERT_TRUE(rc.IsOk());
  52. rc = my_tree->AssociateNode(my_tfreader_op);
  53. ASSERT_TRUE(rc.IsOk());
  54. rc = my_tree->AssociateNode(my_take_op);
  55. ASSERT_TRUE(rc.IsOk());
  56. // Set children/root layout.
  57. rc = my_take_op->AddChild(my_tfreader_op);
  58. ASSERT_TRUE(rc.IsOk());
  59. rc = my_tree->AssignRoot(my_take_op);
  60. ASSERT_TRUE(rc.IsOk());
  61. MS_LOG(DEBUG) << "Launching tree and begin iteration.";
  62. rc = my_tree->Prepare();
  63. ASSERT_TRUE(rc.IsOk());
  64. rc = my_tree->Launch();
  65. ASSERT_TRUE(rc.IsOk());
  66. // Start the loop of reading tensors from our pipeline
  67. DatasetIterator di(my_tree);
  68. TensorRow tensor_list;
  69. rc = di.FetchNextTensorRow(&tensor_list);
  70. ASSERT_TRUE(rc.IsOk());
  71. int row_count = 0;
  72. while (!tensor_list.empty()) {
  73. MS_LOG(DEBUG) << "Row display for row #: " << row_count << ".";
  74. // Display the tensor by calling the printer on it
  75. for (int i = 0; i < tensor_list.size(); i++) {
  76. std::ostringstream ss;
  77. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  78. MS_LOG(DEBUG) << "Tensor print: " << ss.str() << ".";
  79. }
  80. rc = di.FetchNextTensorRow(&tensor_list);
  81. ASSERT_TRUE(rc.IsOk());
  82. row_count++;
  83. }
  84. ASSERT_EQ(row_count, 5);
  85. }