- File:
-
- 1 edited
-
sage/structure/coerce.pxi (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/structure/coerce.pxi
r5497 r6677 45 45 def parent(x): 46 46 return parent_c(x) 47 48 ################################################################################# 49 # operators 50 ################################################################################# 51 52 cdef add, sub, mul, div, iadd, isub, imul, idiv 53 from operator import add, sub, mul, div, iadd, isub, imul, idiv 54 55 cdef inline inplace_op(op): 56 return operator.__dict__['i'+op.__name__] 57 58 cdef inline no_inplace_op(op): 59 return operator.__dict__[op.__name__[1:]] 47 60 48 61 ################################################################################# 49 62 # errors 50 63 ################################################################################# 51 cdef D = {'mul':'*', 'add':'+', 'sub':'-', 'div':'/' }64 cdef D = {'mul':'*', 'add':'+', 'sub':'-', 'div':'/', 'imul': '*', 'iadd': '+', 'isub':'-', 'idiv':'/'} 52 65 53 66 cdef inline arith_error_message(x, y, op): … … 58 71 return "unsupported operand parent(s) for '%s': '%s' and '%s'"%(n, parent_c(x), parent_c(y)) 59 72 73 ################################################################################# 74 # Inline arithmatic dispatchers for ModuleElements and RingElements 75 ################################################################################# 76 77 cdef inline ModuleElement _add_c(ModuleElement left, ModuleElement right): 78 if HAS_DICTIONARY(left): 79 return left._add_(right) 80 else: 81 return left._add_c_impl(right) 82 83 cdef inline ModuleElement _iadd_c(ModuleElement left, ModuleElement right): 84 if HAS_DICTIONARY(left): 85 return left._iadd_(right) 86 else: 87 return left._iadd_c_impl(right) 88 89 cdef inline ModuleElement _sub_c(ModuleElement left, ModuleElement right): 90 if HAS_DICTIONARY(left): 91 return left._sub_(right) 92 else: 93 return left._sub_c_impl(right) 94 95 cdef inline ModuleElement _isub_c(ModuleElement left, ModuleElement right): 96 if HAS_DICTIONARY(left): 97 return left._isub_(right) 98 else: 99 return left._isub_c_impl(right) 100 101 # rmul -- left * self 102 cdef inline ModuleElement _rmul_c(ModuleElement right, RingElement left): 103 if HAS_DICTIONARY(right): 104 return right._rmul_(left) 105 else: 106 return right._rmul_c_impl(left) 107 108 # lmul -- self * right 109 cdef inline ModuleElement _lmul_c(ModuleElement left, RingElement right): 110 if HAS_DICTIONARY(left): 111 return left._lmul_(right) 112 else: 113 return left._lmul_c_impl(right) 114 115 # ilmul -- inplace self * right 116 cdef inline ModuleElement _ilmul_c(ModuleElement self, RingElement right): 117 if HAS_DICTIONARY(self): 118 return self._ilmul_(right) 119 else: 120 return self._ilmul_c_impl(right) 121 122 cdef inline RingElement _mul_c(RingElement left, RingElement right): 123 if HAS_DICTIONARY(left): 124 return left._mul_(right) 125 else: 126 return left._mul_c_impl(right) 127 128 cdef inline RingElement _imul_c(RingElement left, RingElement right): 129 if HAS_DICTIONARY(left): 130 return left._imul_(right) 131 else: 132 return left._imul_c_impl(right) 133 134 cdef inline RingElement _div_c(RingElement left, RingElement right): 135 if HAS_DICTIONARY(left): 136 return left._div_(right) 137 else: 138 return left._div_c_impl(right) 139 140 cdef inline RingElement _idiv_c(RingElement left, RingElement right): 141 if HAS_DICTIONARY(left): 142 return left._idiv_(right) 143 else: 144 return left._idiv_c_impl(right) 145 146 cdef enum: 147 # 3 references: handle, scope container, and arithmatic call stack 148 inplace_threshold = 3 149 150 151
Note: See TracChangeset
for help on using the changeset viewer.
