Expand math to polynomials
expand_math_to_polynomials
¶
ExpandExp
dataclass
¶
Bases: RewritePattern
Replace math.exp operations with a polynomial expansion.
Only expands when the number of terms is specified, either via an attribute on the operation or via the pass-level default.
Source code in xdsl/transforms/expand_math_to_polynomials.py
default_terms: int | None = None
class-attribute
instance-attribute
¶
Pass-level default for number of terms. None means don't expand unless the operation has an explicit terms attribute.
__init__(default_terms: int | None = None) -> None
¶
match_and_rewrite(op: math.ExpOp, rewriter: PatternRewriter) -> None
¶
Source code in xdsl/transforms/expand_math_to_polynomials.py
ExpandMathToPolynomialsPass
dataclass
¶
Bases: ModulePass
This pass expands math operations to a polynomial expansion using the Taylor series.
Currently only expands math.exp operations.
Operations are only expanded when the number of terms is specified,
either via a terms attribute on the operation itself or via the
pass-level terms parameter.
Source code in xdsl/transforms/expand_math_to_polynomials.py
name = 'expand-math-to-polynomials'
class-attribute
instance-attribute
¶
terms: int | None = None
class-attribute
instance-attribute
¶
Number of terms in the resulting polynomial expansion. If not set, only operations with an explicit terms attribute are expanded.
__init__(terms: int | None = None) -> None
¶
expand_exp(op: math.ExpOp, rewriter: PatternRewriter, terms: int) -> Operation
¶
Expand exp(x) using a Taylor-series polynomial expansion.
Pseudo-code::
result = 1.0
term = 1.0
for i in range(1, terms): # loop will be unrolled by the rewriter
term *= x / i
result += term
return result