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.

graph_utils_test.cc 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <sstream>
  18. #include <memory>
  19. #include <algorithm>
  20. #include "common/common_test.h"
  21. #include "common/py_func_graph_fetcher.h"
  22. #include "ir/anf.h"
  23. #include "ir/graph_utils.h"
  24. #include "utils/convert_utils.h"
  25. #include "pipeline/jit/parse/parse_base.h"
  26. #include "pipeline/jit/parse/parse.h"
  27. namespace mindspore {
  28. class TestGraphUtils : public UT::Common {
  29. public:
  30. TestGraphUtils() : getPyFun("gtest_input.utils.graph_utils_test", true), equiv_graph(), equiv_node() {}
  31. std::shared_ptr<FuncGraph> GetPythonFunction(std::string function);
  32. public:
  33. UT::PyFuncGraphFetcher getPyFun;
  34. FuncGraphPairMapEquiv equiv_graph;
  35. NodeMapEquiv equiv_node;
  36. };
  37. TEST_F(TestGraphUtils, Isomorphic) {
  38. std::shared_ptr<FuncGraph> g1 = getPyFun("test_graph_utils_isomorphic_1");
  39. std::shared_ptr<FuncGraph> g2 = getPyFun("test_graph_utils_isomorphic_2");
  40. std::shared_ptr<FuncGraph> g3 = getPyFun("test_graph_utils_isomorphic_3");
  41. ASSERT_TRUE(nullptr != g1);
  42. ASSERT_TRUE(nullptr != g2);
  43. ASSERT_TRUE(Isomorphic(g1, g2, &equiv_graph, &equiv_node));
  44. ASSERT_TRUE(nullptr != g3);
  45. ASSERT_FALSE(Isomorphic(g1, g3, &equiv_graph, &equiv_node));
  46. }
  47. } // namespace mindspore