Example usage for org.apache.commons.math.linear SingularValueDecompositionImpl getRank

List of usage examples for org.apache.commons.math.linear SingularValueDecompositionImpl getRank

Introduction

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

Prototype

public int getRank() throws IllegalStateException 

Source Link

Usage

From source file:edu.cudenver.bios.matrixsvc.resource.MatrixRankResource.java

/**
 * Handle POST request to calculate the rank of a matrix
 * @param entity XMl formatted matrix list
 * @return XML representation of the matrix rank
 * @throws ResourceException//from  w ww  . java2s.c om
 */
@Post
public Representation matrixRank(Representation entity) throws ResourceException {
    if (entity == null) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                "No Input- Calculation of Matrix Rank not possible");
    }
    DomRepresentation rep = new DomRepresentation(entity);
    NamedRealMatrix reqMatrix = null;

    try {
        // parse the parameters from the entity body
        reqMatrix = MatrixParamParser.getMatrixRankParamsFromDomNode(rep.getDocument().getDocumentElement());

        //perform rank operation and set value in our parameter object
        SingularValueDecompositionImpl impl = new SingularValueDecompositionImpl(reqMatrix);

        //create our response representation
        RankXmlRepresentation response = new RankXmlRepresentation(impl.getRank());
        /* getResponse().setEntity(response); 
         getResponse().setStatus(Status.SUCCESS_CREATED);*/
        return response;
    } catch (IllegalArgumentException iae) {
        MatrixLogger.getInstance().error(iae.getMessage());
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, iae.getMessage());

    } catch (IOException ioe) {
        MatrixLogger.getInstance().error(ioe.getMessage());
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ioe.getMessage());

    }
}