Polynomial
polynomial
¶
A polynomial dialect for representing unevaluated polynomial approximations, designed for use with equality saturation.
Cost estimation can be done on a single polynomial.eval op
that carries all the information needed. After extraction, the selected
polynomial variant will be expanded into arithmetic operations.
Polynomial = Dialect('polynomial', [EvalOp], [ChebyshevPolynomialAttr, TypedChebyshevPolynomialAttr, RingAttr, PolynomialType])
module-attribute
¶
EvalScheme
¶
Bases: StrEnum
Evaluation scheme used to lower a polynomial.eval op to arithmetic ops.
Stored on the op as a builtin string attribute so that compilers like HEIR
that don't know about this xDSL extension can preserve it on round-trip
(the same way they ignore domain_lower/domain_upper).
Source code in xdsl/dialects/polynomial.py
CLENSHAW = 'clenshaw'
class-attribute
instance-attribute
¶
RingAttr
dataclass
¶
Bases: ParametrizedAttribute
A polynomial ring, parameterized by the coefficient type.
Syntax: #polynomial.ring
Source code in xdsl/dialects/polynomial.py
PolynomialType
dataclass
¶
Bases: ParametrizedAttribute, TypeAttribute
Type of an element of a polynomial ring.
Syntax: !polynomial.polynomial<ring=
Source code in xdsl/dialects/polynomial.py
name = 'polynomial.polynomial'
class-attribute
instance-attribute
¶
ring: RingAttr
instance-attribute
¶
parse_parameters(parser: AttrParser) -> Sequence[Attribute]
classmethod
¶
Source code in xdsl/dialects/polynomial.py
ChebyshevPolynomialAttr
¶
Bases: ParametrizedAttribute
Untyped Chebyshev polynomial with double precision floating point coefficients.
For use directly inside polynomial.eval, prefer TypedChebyshevPolynomialAttr,
which carries an explicit polynomial type and matches HEIR's polynomial.eval
op signature.
Syntax: #polynomial.chebyshev_polynomial<[coefficients]> Example: #polynomial.chebyshev_polynomial<[0.5 : f64, 1.2 : f64, 0.3 : f64]>
Source code in xdsl/dialects/polynomial.py
name = 'polynomial.chebyshev_polynomial'
class-attribute
instance-attribute
¶
coefficients: ArrayAttr[FloatAttr]
instance-attribute
¶
degree: int
property
¶
Polynomial degree (number of coefficients minus one).
coeff_values: tuple[float, ...]
property
¶
Extract coefficient values as Python floats.
__init__(coefficients: tuple[float, ...] | ArrayAttr[FloatAttr])
¶
Source code in xdsl/dialects/polynomial.py
TypedChebyshevPolynomialAttr
¶
Bases: ParametrizedAttribute
Chebyshev polynomial with an explicit polynomial type.
Syntax: #polynomial.typed_chebyshev_polynomial<[coefficients]> : !polynomial.polynomial<...>
Example:
#polynomial.typed_chebyshev_polynomial<[1.0, 2.0]> :
!polynomial.polynomial<ring=
Source code in xdsl/dialects/polynomial.py
name = 'polynomial.typed_chebyshev_polynomial'
class-attribute
instance-attribute
¶
type: Attribute
instance-attribute
¶
value: ChebyshevPolynomialAttr
instance-attribute
¶
degree: int
property
¶
coeff_values: tuple[float, ...]
property
¶
__init__(type: Attribute, value: ChebyshevPolynomialAttr | tuple[float, ...])
¶
parse_parameters(parser: AttrParser) -> Sequence[Attribute]
classmethod
¶
Source code in xdsl/dialects/polynomial.py
EvalOp
¶
Bases: IRDLOperation
Evaluate a polynomial at a given point.
This op is unevaluated but carries all information needed for
later lowering to arithmetic ops, dispatched on scheme.
Syntax: polynomial.eval $polynomial , $value attr-dict : type($value)
Example:
%result = polynomial.eval
#polynomial.typed_chebyshev_polynomial<[0.5, 1.2]> :
!polynomial.polynomial<ring=
Source code in xdsl/dialects/polynomial.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
name = 'polynomial.eval'
class-attribute
instance-attribute
¶
T: ClassVar = VarConstraint('T', container_of(AnyFloat))
class-attribute
instance-attribute
¶
value = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
polynomial = prop_def(TypedChebyshevPolynomialAttr)
class-attribute
instance-attribute
¶
scheme = attr_def(StringAttr)
class-attribute
instance-attribute
¶
domain_lower = opt_attr_def(FloatAttr)
class-attribute
instance-attribute
¶
domain_upper = opt_attr_def(FloatAttr)
class-attribute
instance-attribute
¶
traits = traits_def(Pure(), SameOperandsAndResultType())
class-attribute
instance-attribute
¶
assembly_format = 'qualified($polynomial) `,` $value attr-dict `:` type($value)'
class-attribute
instance-attribute
¶
degree: int
property
¶
eval_scheme: EvalScheme
property
¶
Return the scheme as an EvalScheme enum.
__init__(value: SSAValue, polynomial: TypedChebyshevPolynomialAttr, scheme: StringAttr, domain_lower: FloatAttr | None = None, domain_upper: FloatAttr | None = None)
¶
Source code in xdsl/dialects/polynomial.py
get(value: Operation | SSAValue, coefficients: tuple[float, ...], element_type: AnyFloat, scheme: EvalScheme | str, domain_lower: float | None = None, domain_upper: float | None = None) -> EvalOp
classmethod
¶
Build an EvalOp from raw Python floats.
element_type is the floating-point type used for the polynomial
coefficients, the ring's coefficient type, and the domain bounds.