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

Function as_factors

numpy/f2py/symbolic.py:1074–1092  ·  view source on GitHub ↗

Return expression as FACTORS expression.

(obj)

Source from the content-addressed store, hash-verified

1072
1073
1074def as_factors(obj):
1075 """Return expression as FACTORS expression.
1076 """
1077 if isinstance(obj, Expr):
1078 obj = normalize(obj)
1079 if obj.op is Op.FACTORS:
1080 return obj
1081 if obj.op is Op.TERMS:
1082 if len(obj.data) == 1:
1083 (term, coeff), = obj.data.items()
1084 if coeff == 1:
1085 return Expr(Op.FACTORS, {term: 1})
1086 return Expr(Op.FACTORS, {term: 1, Expr.number(coeff): 1})
1087 if ((obj.op is Op.APPLY
1088 and obj.data[0] is ArithOp.DIV
1089 and not obj.data[2])):
1090 return Expr(Op.FACTORS, {obj.data[1][0]: 1, obj.data[1][1]: -1})
1091 return Expr(Op.FACTORS, {obj: 1})
1092 raise OpError(f'cannot convert {type(obj)} to terms Expr')
1093
1094
1095def as_term_coeff(obj):

Callers 3

test_sanityMethod · 0.90
__mul__Method · 0.85
normalizeFunction · 0.85

Calls 4

normalizeFunction · 0.85
ExprClass · 0.85
OpErrorClass · 0.85
numberMethod · 0.80

Tested by 1

test_sanityMethod · 0.72