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.

symbolic.cc 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
  3. *
  4. * Copyright 2019 Huawei Technologies Co., Ltd
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "utils/symbolic.h"
  19. #include <memory>
  20. namespace mindspore {
  21. std::ostream &operator<<(std::ostream &out, const std::shared_ptr<EnvInstance> &objPtr) {
  22. out << "(";
  23. MS_EXCEPTION_IF_NULL(objPtr);
  24. for (auto &iter : objPtr->contents_) {
  25. out << iter.first << ":" << iter.second << ";";
  26. }
  27. out << ")";
  28. return out;
  29. }
  30. bool EnvInstance::operator==(const EnvInstance &other) const {
  31. if (Len() != other.Len()) {
  32. return false;
  33. }
  34. bool equal = std::all_of(contents_.begin(), contents_.end(),
  35. [&other](const std::pair<SymbolicKeyInstancePtr, Any> &item) -> bool {
  36. return other.contents_.find(item.first) != other.contents_.end();
  37. });
  38. return equal;
  39. }
  40. bool EnvInstance::operator==(const Value &other) const {
  41. if (other.isa<EnvInstance>()) {
  42. auto other_env_inst = static_cast<const EnvInstance *>(&other);
  43. return *this == *other_env_inst;
  44. }
  45. return false;
  46. }
  47. std::shared_ptr<EnvInstance> newenv = std::make_shared<EnvInstance>();
  48. } // namespace mindspore