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.

iterator.cc 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/include/iterator.h"
  17. #include "minddata/dataset/core/client.h"
  18. #include "minddata/dataset/engine/consumers/tree_consumer.h"
  19. #include "minddata/dataset/include/datasets.h"
  20. namespace mindspore {
  21. namespace dataset {
  22. namespace api {
  23. // Get the next row from the data pipeline.
  24. bool Iterator::GetNextRow(TensorMap *row) {
  25. Status rc = consumer_->GetNextAsMap(row);
  26. if (rc.IsError()) {
  27. MS_LOG(ERROR) << "GetNextRow: Failed to get next row. Error status: " << rc;
  28. row->clear();
  29. return false;
  30. }
  31. return true;
  32. }
  33. // Get the next row from the data pipeline.
  34. bool Iterator::GetNextRow(TensorVec *row) {
  35. Status rc = consumer_->GetNextAsVector(row);
  36. if (rc.IsError()) {
  37. MS_LOG(ERROR) << "GetNextRow: Failed to get next row. Error status: " << rc;
  38. row->clear();
  39. return false;
  40. }
  41. return true;
  42. }
  43. // Shut down the data pipeline.
  44. void Iterator::Stop() { runtime_context->Terminate(); }
  45. // Function to build and launch the execution tree.
  46. Status Iterator::BuildAndLaunchTree(std::shared_ptr<Dataset> ds) {
  47. runtime_context = std::make_unique<RuntimeContext>();
  48. RETURN_IF_NOT_OK(runtime_context->Init());
  49. auto consumer = std::make_unique<IteratorConsumer>();
  50. consumer_ = consumer.get();
  51. RETURN_IF_NOT_OK(consumer->Init(ds));
  52. runtime_context->AssignConsumer(std::move(consumer));
  53. return Status::OK();
  54. }
  55. } // namespace api
  56. } // namespace dataset
  57. } // namespace mindspore