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

Function as_factors

numpy/f2py/symbolic.py:1073–1091  ·  view source on GitHub ↗

Return expression as FACTORS expression.

(obj)

Source from the content-addressed store, hash-verified

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

Callers 3

test_sanityMethod · 0.90
__mul__Method · 0.85
normalizeFunction · 0.85

Calls 5

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

Tested by 1

test_sanityMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…