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.

anf_test.cc 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "common/common_test.h"
  19. #include "ir/anf.h"
  20. #include "ir/func_graph.h"
  21. #include "frontend/operator/ops.h"
  22. #include "base/core_ops.h"
  23. namespace mindspore {
  24. using Named = Named;
  25. class TestAnf : public UT::Common {
  26. public:
  27. TestAnf() {}
  28. };
  29. TEST_F(TestAnf, test_ValueNode) {
  30. auto prim = std::make_shared<Primitive>(prim::kScalarAdd);
  31. ValueNodePtr c = NewValueNode(prim);
  32. ASSERT_EQ(c->isa<ValueNode>(), true);
  33. ASSERT_EQ(IsValueNode<Primitive>(c), true);
  34. ASSERT_EQ(IsValueNode<FuncGraph>(c), false);
  35. FuncGraphPtr fg = std::make_shared<FuncGraph>();
  36. ValueNode c1(fg);
  37. ASSERT_EQ(c1.value()->isa<FuncGraph>(), true);
  38. }
  39. TEST_F(TestAnf, test_Parameter) {
  40. FuncGraphPtr fg = std::make_shared<FuncGraph>();
  41. Parameter a(fg);
  42. assert(a.isa<Parameter>());
  43. }
  44. TEST_F(TestAnf, test_CNode) {
  45. auto primitive = prim::kPrimScalarAdd;
  46. FuncGraphPtr fg = std::make_shared<FuncGraph>();
  47. std::string s = fg->ToString();
  48. Parameter param(fg);
  49. std::vector<AnfNodePtr> params;
  50. CNode app_1(params, fg);
  51. params.push_back(NewValueNode(primitive));
  52. params.push_back(AnfNodePtr(new Parameter(param)));
  53. CNode app(params, fg);
  54. assert(app.isa<CNode>());
  55. assert(app.IsApply(primitive));
  56. }
  57. TEST_F(TestAnf, is_exception) {
  58. FuncGraphPtr fg = std::make_shared<FuncGraph>();
  59. Parameter a(fg);
  60. assert(!a.isa<CNode>());
  61. assert(!a.isa<ValueNode>());
  62. }
  63. } // namespace mindspore