canonical#
A module for compiled code for polynomial manipulation in the canonical basis.
Notes
The most “fine-grained” functions must be defined first in order for Numba to properly infer the function types.
- minterpy.jit_compiled.canonical.can_eval_mult(x_multiple, coeffs, exponents, result_placeholder)[source]#
Naive evaluation of polynomials in canonical basis.
m
spatial dimensionk
number of pointsN
number of monomialsp
number of polynomials
- Parameters:
x_multiple – numpy array with coordinates of points where polynomial is to be evaluated. The shape has to be
(k x m)
.coeffs – numpy array of polynomial coefficients in canonical basis. The shape has to be
(N x p)
.exponents – numpy array with exponents for the polynomial. The shape has to be
(N x m)
.result_placeholder – placeholder numpy array where the results of evaluation are stored. The shape has to be
(k x p)
.
Notes
This is a naive evaluation; a more numerically accurate approach would be to transform to Newton basis and using the newton evaluation scheme.
Multiple polynomials in the canonical basis can be evaluated at once by having a 2D coeffs array. It is assumed that they all have the same set of exponents.
- minterpy.jit_compiled.canonical.compute_coeffs_poly_prod(exponents_1, coeffs_1, exponents_2, coeffs_2, exponents_prod, coeffs_prod)[source]#
Compute the coefficients of polynomial product in the canonical basis.
For example, suppose: \(A = \{ (0, 0) , (1, 0), (0, 1) \}\) with coefficients \(c_A = (1.0 , 2.0, 3.0)\) is multiplied with \(B = \{ (0, 0) , (1, 0) \}\) with coefficients \(c_B = (1.0 , 5.0)\). The product multi-index set is \(A \times B = \{ (0, 0) , (1, 0), (2, 0), (0, 1), (1, 1) \}\).
The corresponding coefficients of the product are:
\((0, 0)\) is coming from \((0, 0) + (0, 0)\), the coefficient is \(1.0 \times 1.0 = 1.0\)
\((1, 0)\) is coming from \((0, 0) + (1, 0)\) and \((1, 0) + (0, 0)\), the coefficient is \(1.0 \times 5.0 + 2.0 \times 1.0 = 7.0\)
\((2, 0)\) is coming from \((1, 0) + (1, 0)\), the coefficient is \(2.0 \times 5.0 = 10.0\)
\((0, 1)\) is coming from \((0, 1) + (0, 0)\), the coefficient is \(3.0 \times 1.0 = 3.0\)
\((1, 1)\) is coming from \((0, 1) + (1, 0)\), the coefficient is \(3.0 \times 5.0 = 15.0\)
or \(c_{A \times B} = (1.0, 7.0, 10.0, 3.0, 15.0)\).
- Parameters:
exponents_1 (
numpy.ndarray
) – The multi-indices exponents of the first multidimensional polynomial operand in the multiplication expression.coeffs_1 (
numpy.ndarray
) – The coefficients of the first multidimensional polynomial operand.exponents_2 (
numpy.ndarray
) – The multi-indices exponents of the second multidimensional polynomial.coeffs_2 (
numpy.ndarray
) – The coefficients of the second multidimensional polynomial operand.exponents_prod (
numpy.ndarray
) – The multi-indices exponents that are the product betweenexponents_1
andexponents_2
(i.e., the sum of cartesian products).coeffs_prod (
numpy.ndarray
) – The placeholder for the corresponding product coefficients.
Notes
exponents_1
,exponents_2
,exponents_prod
are assumed to be two-dimensional integer arrays that are sorted lexicographically.exponents_prod
is assumed to be the result of multiplyingexponents_1
andexponents_2
as multi-indices.coeffs_1
,coeffs_2
, andcoeffs_prod
are assumed to be two-dimensional float arrays. Their number of columns must be the same.coeffs_prod
is a placeholder array to store the results; it must be initialized with zeros.The function does not check whether the above assumptions are fulfilled; the caller is responsible to make sure of that. If the assumptions are not fulfilled, the function may not raise any exception but produce the wrong results.