MCPcopy Create free account
hub / github.com/numpy/numpy / as_term_coeff

Function as_term_coeff

numpy/f2py/symbolic.py:1095–1113  ·  view source on GitHub ↗

Return expression as term-coefficient pair.

(obj)

Source from the content-addressed store, hash-verified

1093
1094
1095def as_term_coeff(obj):
1096 """Return expression as term-coefficient pair.
1097 """
1098 if isinstance(obj, Expr):
1099 obj = normalize(obj)
1100 if obj.op is Op.INTEGER:
1101 return as_integer(1, obj.data[1]), obj.data[0]
1102 if obj.op is Op.REAL:
1103 return as_real(1, obj.data[1]), obj.data[0]
1104 if obj.op is Op.TERMS:
1105 if len(obj.data) == 1:
1106 (term, coeff), = obj.data.items()
1107 return term, coeff
1108 # TODO: find common divisor of coefficients
1109 if obj.op is Op.APPLY and obj.data[0] is ArithOp.DIV:
1110 t, c = as_term_coeff(obj.data[1][0])
1111 return as_apply(ArithOp.DIV, t, obj.data[1][1]), c
1112 return obj, 1
1113 raise OpError(f'cannot convert {type(obj)} to term and coeff')
1114
1115
1116def as_numer_denom(obj):

Callers 1

normalizeFunction · 0.85

Calls 5

normalizeFunction · 0.85
as_integerFunction · 0.85
as_realFunction · 0.85
as_applyFunction · 0.85
OpErrorClass · 0.85

Tested by

no test coverage detected