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.

trope.py 3.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # This is the Python adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
  2. #
  3. # Copyright 2020 Huawei Technologies Co., Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # ============================================================================
  17. """Trope some system function symbol to ops."""
  18. # This operation function is not meant to be called directly
  19. # support operator symbol, ast
  20. from operator import ( # noqa
  21. add, sub, mul, truediv, floordiv, mod, eq, ne, lt, gt, le, ge, pos, neg,
  22. not_, and_, or_, xor, lshift, rshift, invert, is_, is_not, contains,
  23. matmul, getitem, setitem
  24. )
  25. # support system function call
  26. from builtins import ( # noqa
  27. bool, getattr, setattr, len, iter, next, pow, range, map, zip, print
  28. )
  29. # support functools
  30. from functools import ( # noqa
  31. partial
  32. )
  33. # support numpy symbol
  34. from numpy import ( # noqa
  35. exp, log, sin, cos, tan
  36. )
  37. __all__ = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'mod', 'eq', 'ne', 'lt', 'gt', 'le', 'ge', 'pos', 'neg',
  38. 'not_', 'and_', 'or_', 'xor', 'lshift', 'rshift', 'invert', 'is_', 'is_not', 'contains',
  39. 'matmul', 'getitem', 'setitem',
  40. 'bool', 'getattr', 'setattr', 'len', 'iter', 'next', 'pow', 'range', 'map', 'zip',
  41. 'partial', 'print',
  42. 'exp', 'log', 'sin', 'cos', 'tan']
  43. def make_tuple(*elts): # pragma: no cover
  44. """Tuple builder."""
  45. raise RuntimeError('This operation is not meant to be called directly.')
  46. def make_dict(key, value): # pragma: no cover
  47. """Dict builder."""
  48. raise RuntimeError('This operation is not meant to be called directly.')
  49. def make_list(*elts): # pragma: no cover
  50. """List builder."""
  51. raise RuntimeError('This operation is not meant to be called directly.')
  52. def make_slice(*elts): # pragma: no cover
  53. """Slice builder."""
  54. raise RuntimeError('This operation is not meant to be called directly.')
  55. def make_range(*elts): # pragma: no cover
  56. """Range tuple builder."""
  57. raise RuntimeError('This operation is not meant to be called directly.')
  58. def switch(cond, tb, fb): # pragma: no cover
  59. """Switch statement, returns one of the two values."""
  60. raise RuntimeError('This operation is not meant to be called directly.')
  61. def hasnext(it): # pragma: no cover
  62. """Hasnext function."""
  63. raise RuntimeError('This operation is not meant to be called directly.')
  64. def to_array(x): # pragma: no cover
  65. """The to_array function."""
  66. raise RuntimeError('This operation is not meant to be called directly.')
  67. def not_contains(x): # pragma: no cover
  68. """Not in function."""
  69. raise RuntimeError('This operation is not meant to be called directly.')
  70. def while_cond(x): # pragma: no cover
  71. """Not in function."""
  72. raise RuntimeError('This operation is not meant to be called directly.')