class PiecewisePolynomialFunction1D {

  public DoubleMatrix1D evaluate(final PiecewisePolynomialResult pp, final double xKey) {
    ArgumentChecker.notNull(pp, "pp");

    ArgumentChecker.isFalse(Double.isNaN(xKey), "xKey containing NaN");
    ArgumentChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity");

    final double[] knots = pp.getKnots().getData();
    final int nKnots = knots.length;
    final DoubleMatrix2D coefMatrix = pp.getCoefMatrix();
    final int dim = pp.getDimensions();

    double[] res = new double[dim];

    int indicator = FunctionUtils.getLowerBoundIndex(knots, xKey);
    if (indicator == nKnots - 1) {
      indicator--; //there is 1 less interval that knots 
    }

    for (int j = 0; j < dim; ++j) {
      final double[] coefs = coefMatrix.getRowVector(dim * indicator + j).getData();
      res[j] = getValue(coefs, xKey, knots[indicator]);

      ArgumentChecker.isFalse(Double.isInfinite(res[j]), "Too large input");
      ArgumentChecker.isFalse(Double.isNaN(res[j]), "Too large input");
    }

    return new DoubleMatrix1D(res);
  }

  public  PiecewisePolynomialFunction1D();

}