Polynomial

Module

Provides two implementations for evaluating polynomials.

polynomial_evaluate

polynomial_evaluate[simd_width: Int, dtype: DType, coefficients: VariadicList[SIMD[dtype, simd_width]]](x: SIMD[dtype, simd_width]) -> SIMD[dtype, simd_width]

Evaluate the 1st degree polynomial using the passed in value and the specified coefficients.

These methods evaluate the polynomial using either the Estrin scheme or the Horner scheme. The Estrin scheme is only implemented for polynomials of degrees between 4 and 10. The Horner scheme is implemented for polynomials for any polynomial degree.

Parameters:

  • simd_width (Int): The simd_width of the computed value.
  • dtype (DType): The dtype of the value.
  • coefficients (VariadicList[SIMD[dtype, simd_width]]): The coefficients.

Args:

  • x (SIMD[dtype, simd_width]): The value to compute the polynomial with.

Returns:

The polynomial evaluation results using the specified value and the constant coefficients.

polynomial_evaluate[simd_width: Int, dtype: DType, coefficients: VariadicList[SIMD[dtype, simd_width]]](x: SIMD[dtype, simd_width]) -> SIMD[dtype, simd_width]

Evaluate the polynomial using the Horner scheme.

The Horner scheme evaluates the polynomial as horner(val, coeffs), where val is a scalar and coeffs is a list of coefficients [c0, c1, c2, ..., cn], by performing the following computation:

horner(val, coeffs) = c0 + val * (c1 + val * (c2 + val * (... + val * cn)))
            = fma(val, horner(val, coeffs[1:]), c0)

Parameters:

  • simd_width (Int): The simd_width of the computed value.
  • dtype (DType): The dtype of the value.
  • coefficients (VariadicList[SIMD[dtype, simd_width]]): The coefficients.

Args:

  • x (SIMD[dtype, simd_width]): The value to compute the polynomial with.

Returns:

The polynomial evaluation results using the specified value and the constant coefficients.