double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts);
ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt);
final DoubleMatrix2D coefMatrix = solve(xValuesSrt, yValuesSrt);
for (int i = 0; i < coefMatrix.getNumberOfRows(); ++i) {
for (int j = 0; j < coefMatrix.getNumberOfColumns(); ++j) {
ArgumentChecker.isFalse(Double.isNaN(coefMatrix.getData()[i][j]), "Too large input");
ArgumentChecker.isFalse(Double.isInfinite(coefMatrix.getData()[i][j]), "Too large input");
}
double ref = 0.;
final double interval = xValuesSrt[i + 1] - xValuesSrt[i];
for (int j = 0; j < 2; ++j) {
ref += coefMatrix.getData()[i][j] * Math.pow(interval, 1 - j);
ArgumentChecker.isFalse(Double.isNaN(coefMatrix.getData()[i][j]), "Too large input");
ArgumentChecker.isFalse(Double.isInfinite(coefMatrix.getData()[i][j]), "Too large input");
}
final double bound = Math.max(Math.abs(ref) + Math.abs(yValuesSrt[i + 1]), 1.e-1);
ArgumentChecker.isTrue(Math.abs(ref - yValuesSrt[i + 1]) < ERROR * bound, "Input is too large/small or data are not distinct enough");
}
return new PiecewisePolynomialResult(new DoubleMatrix1D(xValuesSrt), coefMatrix, coefMatrix.getNumberOfColumns(), 1);
}