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.

prim2func_test.cc 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <vector>
  19. #include "common/common_test.h"
  20. #include "ir/anf.h"
  21. #include "ir/dtype.h"
  22. #include "operator/prim_to_function.h"
  23. namespace mindspore {
  24. namespace prim {
  25. class TestPrimFunc : public UT::Common {
  26. public:
  27. TestPrimFunc() {}
  28. virtual void SetUp() {}
  29. };
  30. TEST_F(TestPrimFunc, ScalarAddTest) {
  31. auto prim = std::make_shared<Primitive>("scalar_add");
  32. FunctionPtr func = nullptr;
  33. PrimToFunction::GetInstance().GetFunction(prim, &func);
  34. std::vector<std::shared_ptr<Type>> two_args{std::make_shared<Number>(), std::make_shared<Number>()};
  35. std::shared_ptr<Type> retval = std::make_shared<Number>();
  36. Function func_add = Function(two_args, retval);
  37. std::cout << "func_add: " + func_add.ToString() << std::endl;
  38. std::cout << "prim_func: " + func->ToString() << std::endl;
  39. ASSERT_EQ(func_add.ToString(), func->ToString());
  40. }
  41. TEST_F(TestPrimFunc, ScalarExpTest) {
  42. auto prim = std::make_shared<Primitive>("scalar_exp");
  43. FunctionPtr func = nullptr;
  44. PrimToFunction::GetInstance().GetFunction(prim, &func);
  45. std::vector<std::shared_ptr<Type>> one_arg{std::make_shared<Number>()};
  46. std::shared_ptr<Type> retval = std::make_shared<Number>();
  47. Function func_add = Function(one_arg, retval);
  48. std::cout << "func_exp: " + func_add.ToString() << std::endl;
  49. std::cout << "prim_func: " + func->ToString() << std::endl;
  50. ASSERT_EQ(func_add.ToString(), func->ToString());
  51. }
  52. } // namespace prim
  53. } // namespace mindspore