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.

any.cc 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "utils/any.h"
  17. #include <cxxabi.h>
  18. #include <memory>
  19. namespace mindspore {
  20. // only support (int, float, bool) as Literal
  21. bool AnyIsLiteral(const Any &any) {
  22. static const std::type_index typeid_int = std::type_index(typeid(int));
  23. static const std::type_index typeid_float = std::type_index(typeid(float));
  24. static const std::type_index typeid_bool = std::type_index(typeid(bool));
  25. std::type_index typeid_any = std::type_index(any.type());
  26. return typeid_int == typeid_any || typeid_float == typeid_any || typeid_bool == typeid_any;
  27. }
  28. std::ostream &operator<<(std::ostream &os, const pybind11::object &obj) {
  29. os << "[py::object]";
  30. return os;
  31. }
  32. Any &Any::operator=(const Any &other) {
  33. if (m_ptr == other.m_ptr || &other == this) {
  34. return *this;
  35. }
  36. m_ptr = other.clone();
  37. m_tpIndex = other.m_tpIndex;
  38. return *this;
  39. }
  40. bool Any::operator<(const Any &other) const { return this < &other; }
  41. Any &Any::operator=(Any &&other) {
  42. if (this != &other) {
  43. if (m_ptr == other.m_ptr || &other == this) {
  44. return *this;
  45. }
  46. m_ptr = std::move(other.m_ptr);
  47. m_tpIndex = std::move(other.m_tpIndex);
  48. other.m_ptr = nullptr;
  49. }
  50. return *this;
  51. }
  52. } // namespace mindspore