Example usage for org.apache.commons.math.linear RealVector getLInfNorm

List of usage examples for org.apache.commons.math.linear RealVector getLInfNorm

Introduction

In this page you can find the example usage for org.apache.commons.math.linear RealVector getLInfNorm.

Prototype

double getLInfNorm();

Source Link

Document

Returns the L norm of the vector.

Usage

From source file:com.opengamma.analytics.math.matrix.CommonsMatrixAlgebra.java

/**
 * {@inheritDoc}/*from   w  w w .j  a v  a 2  s .  c  o m*/
 */
@Override
public double getNormInfinity(final Matrix<?> m) {
    Validate.notNull(m, "m");
    if (m instanceof DoubleMatrix1D) {
        final RealVector temp = CommonsMathWrapper.wrap((DoubleMatrix1D) m);
        return temp.getLInfNorm();
    } else if (m instanceof DoubleMatrix2D) {
        final RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix2D) m);
        //REVIEW Commons getNorm() is wrong - it returns the column norm
        // TODO find if commons implements this anywhere, so we are not doing it
        // by hand
        double max = 0.0;
        for (int row = temp.getRowDimension() - 1; row >= 0; row--) {
            max = Math.max(max, temp.getRowVector(row).getL1Norm());
        }
        return max;
    }
    throw new IllegalArgumentException("Can only find normInfinity of DoubleMatrix2D; have " + m.getClass());
}