private static Matrix readClutoSparse(File matrix, Type matrixType,
                                          boolean transposeOnRead)
            throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(matrix));

        String[] rowCol = br.readLine().split("\\s+");

        // unknown number of rows, so do a quick scan to determine it
        int rows = Integer.parseInt(rowCol[0]);
        int cols = Integer.parseInt(rowCol[1]);

        // Create the matrix.
        Matrix m = (transposeOnRead)
            ? Matrices.create(cols, rows, matrixType)
            : Matrices.create(rows, cols, matrixType);

        // Cluto Sparse stores each row's values on a single line in the form of 
        // "col value" tuples with everything separated by space.
        int row = 0;
        for (String line = null; (line = br.readLine()) != null; ++row) {
            String[] colValuePairs = line.split("\\s+");
            for (int i = 0; i < colValuePairs.length; i+=2) {
                int col = Integer.parseInt(colValuePairs[i]) - 1;
                double value = Double.parseDouble(colValuePairs[i+1]);
                // Store the value in the matrix.
                if (transposeOnRead)
                    m.set(col, row, value);
                else
                    m.set(row, col, value);
            }
        }

        return m;
    }
private static Matrix readClutoSparse ( File matrix , Type matrixType , boolean transposeOnRead ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( matrix ) ) ; String [ ] rowCol = br . readLine ( ) . split ( "\\s+" ) ; int rows = Integer . parseInt ( rowCol [ 0 ] ) ; int cols = Integer . parseInt ( rowCol [ 1 ] ) ; Matrix m = ( transposeOnRead ) ? Matrices . create ( cols , rows , matrixType ) : Matrices . create ( rows , cols , matrixType ) ; int row = 0 ; for ( String line = null ; ( line = br . readLine ( ) ) != null ; ++ row ) { String [ ] colValuePairs = line . split ( "\\s+" ) ; for ( int i = 0 ; i < colValuePairs . length ; i += 2 ) { int col = Integer . parseInt ( colValuePairs [ i ] ) - 1 ; double value = Double . parseDouble ( colValuePairs [ i + 1 ] ) ; if ( transposeOnRead ) m . set ( col , row , value ) ; else m . set ( row , col , value ) ; } } return m ; }
Creates a {@code Matrix} from the data encoded as {@link
Format#CLUTO_SPARSE} in provided file.

@param matrix The matrix file to read from
@param matrixType The expected format of {@code matrix}
@param transposeOnRead If true, the returned matrix will be a transposed
form of the data in {@code matrix}.

@return A {@link SparseMatrix} containing the data in {@code matrix}.