BivariateGridInterpolator interpolator = new PiecewiseBicubicSplineInterpolator();
BivariateFunction p = interpolator.interpolate(xval, yval, zval);
double x, y;
final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
final UniformRealDistribution distX = new UniformRealDistribution( rng, xval[0], xval[xval.length - 1] );
final UniformRealDistribution distY = new UniformRealDistribution( rng, yval[0], yval[yval.length - 1] );
final int numSamples = 50;
final double tol = 2e-14;
for ( int i = 0; i < numSamples; i++ )
{
x = distX.sample();
for ( int j = 0; j < numSamples; j++ )
{
y = distY.sample();
// System.out.println(x + " " + y + " " + f.value(x, y) + " " + p.value(x, y));
Assert.assertEquals(f.value(x, y), p.value(x, y), tol);
}
// System.out.println();
}