Inconsistent Shape of Polynomial Evaluation Output
Evaluating a polynomial with multiple sets of coefficients in the Newton and canonical bases returns an array of inconsistent shape.
Consider the following example:
>>> import minterpy as mp
>>> import numpy as np
>>> grd = mp.Grid.from_degree(1, 4, 2.0)
>>> coeffs = np.random.rand(len(grd.multi_index), 5) # 5 sets of coefficients
>>> coeffs
array([[0.87786913, 0.11311806, 0.68556543, 0.12270705, 0.63383129],
[0.13390747, 0.80416283, 0.35518111, 0.90840093, 0.07781837],
[0.12600742, 0.00205992, 0.27260169, 0.20907449, 0.43723158],
[0.08506146, 0.33686894, 0.42170443, 0.07871695, 0.48833954],
[0.15988932, 0.90407252, 0.90430009, 0.29781589, 0.39525778]])
>>> xx_test = -1 + 2 * np.random.rand(1, 1) # A single point in 1 dimension
Evaluating a Chebyshev polynomial yields the expected result:
>>> cheb_poly = mp.ChebyshevPolynomial.from_grid(grd, coeffs)
>>> cheb_poly(xx_test)
array([[-0.52430559, 1.30012146, -0.49883996, 0.23899706, 1.73091275]])
that is, a two-dimensional array of length 1 (i.e., a single point) and five columns (five coefficient sets).
The results of the same evaluation for the Newton and canonical polynomials, however, differ:
>>> nwt_poly = mp.NewtonPolynomial.from_grid(grd, coeffs)
>>> nwt_poly(xx_test)
array([-0.1361846 , -1.37283508, -0.25926144, 0.99998167, -0.07744399])
>>> can_poly = mp.CanonicalPolynomial.from_grid(grd, coeffs)
>>> can_poly(xx_test)
array([ 0.64476517, 0.68272056, -0.69108107, 0.76952266, 0.07609529])
Both are one-dimensional arrays of length 5 (the number of coefficient sets). Evaluating on two points instead yields two-dimensional array of length two (because of two points) and five columns as expected:
>>> nwt_poly = mp.NewtonPolynomial.from_grid(grd, coeffs)
>>> nwt_poly(xx_test)
array([[-0.81144809, -1.22351575, -0.1741787 , -0.89894496, -1.02820969],
[-0.85313429, -1.62959671, -0.23978442, -0.48025346, -1.10547368]])
>>> can_poly = mp.CanonicalPolynomial.from_grid(grd, coeffs)
>>> can_poly(xx_test)
array([[-0.11094505, -0.1097223 , -0.04669623, 0.14757899, 0.36053963],
[-0.28853074, -0.5195505 , -0.52513973, 0.66737786, 0.52640189]])
This further highlights the inconsistency.
The possible culprit is the function minterpy.utils.verification.convert_eval_output()
that forces the output array to its squeezed version, such that two-dimensional array of a single row is squeezed into a one-dimensional array.