m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8 KiB

6 months ago
  1. """ The core's core. """
  2. # used for canonical ordering of symbolic sequences
  3. # via __cmp__ method:
  4. # FIXME this is *so* irrelevant and outdated!
  5. ordering_of_classes = [
  6. # singleton numbers
  7. 'Zero', 'One', 'Half', 'Infinity', 'NaN', 'NegativeOne', 'NegativeInfinity',
  8. # numbers
  9. 'Integer', 'Rational', 'Float',
  10. # singleton symbols
  11. 'Exp1', 'Pi', 'ImaginaryUnit',
  12. # symbols
  13. 'Symbol', 'Wild', 'Temporary',
  14. # arithmetic operations
  15. 'Pow', 'Mul', 'Add',
  16. # function values
  17. 'Derivative', 'Integral',
  18. # defined singleton functions
  19. 'Abs', 'Sign', 'Sqrt',
  20. 'Floor', 'Ceiling',
  21. 'Re', 'Im', 'Arg',
  22. 'Conjugate',
  23. 'Exp', 'Log',
  24. 'Sin', 'Cos', 'Tan', 'Cot', 'ASin', 'ACos', 'ATan', 'ACot',
  25. 'Sinh', 'Cosh', 'Tanh', 'Coth', 'ASinh', 'ACosh', 'ATanh', 'ACoth',
  26. 'RisingFactorial', 'FallingFactorial',
  27. 'factorial', 'binomial',
  28. 'Gamma', 'LowerGamma', 'UpperGamma', 'PolyGamma',
  29. 'Erf',
  30. # special polynomials
  31. 'Chebyshev', 'Chebyshev2',
  32. # undefined functions
  33. 'Function', 'WildFunction',
  34. # anonymous functions
  35. 'Lambda',
  36. # Landau O symbol
  37. 'Order',
  38. # relational operations
  39. 'Equality', 'Unequality', 'StrictGreaterThan', 'StrictLessThan',
  40. 'GreaterThan', 'LessThan',
  41. ]
  42. class Registry:
  43. """
  44. Base class for registry objects.
  45. Registries map a name to an object using attribute notation. Registry
  46. classes behave singletonically: all their instances share the same state,
  47. which is stored in the class object.
  48. All subclasses should set `__slots__ = ()`.
  49. """
  50. __slots__ = ()
  51. def __setattr__(self, name, obj):
  52. setattr(self.__class__, name, obj)
  53. def __delattr__(self, name):
  54. delattr(self.__class__, name)
  55. #A set containing all SymPy class objects
  56. all_classes = set()
  57. class BasicMeta(type):
  58. def __init__(cls, *args, **kws):
  59. all_classes.add(cls)
  60. cls.__sympy__ = property(lambda self: True)
  61. def __cmp__(cls, other):
  62. # If the other object is not a Basic subclass, then we are not equal to
  63. # it.
  64. if not isinstance(other, BasicMeta):
  65. return -1
  66. n1 = cls.__name__
  67. n2 = other.__name__
  68. if n1 == n2:
  69. return 0
  70. UNKNOWN = len(ordering_of_classes) + 1
  71. try:
  72. i1 = ordering_of_classes.index(n1)
  73. except ValueError:
  74. i1 = UNKNOWN
  75. try:
  76. i2 = ordering_of_classes.index(n2)
  77. except ValueError:
  78. i2 = UNKNOWN
  79. if i1 == UNKNOWN and i2 == UNKNOWN:
  80. return (n1 > n2) - (n1 < n2)
  81. return (i1 > i2) - (i1 < i2)
  82. def __lt__(cls, other):
  83. if cls.__cmp__(other) == -1:
  84. return True
  85. return False
  86. def __gt__(cls, other):
  87. if cls.__cmp__(other) == 1:
  88. return True
  89. return False