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

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