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

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