class ShermanMorrisonMatrixUpdateFunction implements NewtonRootFinderMatrixUpdateFunction {

  @Override
  public DoubleMatrix2D getUpdatedMatrix(final Function1D<DoubleMatrix1D, DoubleMatrix2D> g, DoubleMatrix1D x, final DoubleMatrix1D deltaX, final DoubleMatrix1D deltaY, final DoubleMatrix2D matrix) {
    Validate.notNull(deltaX);
    Validate.notNull(deltaY);
    Validate.notNull(matrix);
    DoubleMatrix1D v1 = (DoubleMatrix1D) _algebra.multiply(deltaX, matrix);
    final double length = _algebra.getInnerProduct(v1, deltaY);
    if (length == 0) {
      return matrix;
    }
    v1 = (DoubleMatrix1D) _algebra.scale(v1, 1. / length);
    final DoubleMatrix1D v2 = (DoubleMatrix1D) _algebra.subtract(deltaX, _algebra.multiply(matrix, deltaY));
    final DoubleMatrix2D m = _algebra.getOuterProduct(v2, v1);
    return (DoubleMatrix2D) _algebra.add(matrix, m);
  }

  public  ShermanMorrisonMatrixUpdateFunction(final MatrixAlgebra algebra);

}