Example usage for org.apache.mahout.math SparseMatrix viewRow

List of usage examples for org.apache.mahout.math SparseMatrix viewRow

Introduction

In this page you can find the example usage for org.apache.mahout.math SparseMatrix viewRow.

Prototype

@Override
    public Vector viewRow(int row) 

Source Link

Usage

From source file:com.twitter.algebra.AlgebraCommon.java

License:Apache License

/**
 * Assuming that the input is generated by {@link MatrixOutputFormat}, this method
 * convert its first row it to a centralized sparse matrix.
 * @param inPath the path to the {@link MapDir matrix}
 * @param nRows/* w  w w . jav  a 2 s.  c  o  m*/
 * @param nCols
 * @param conf
 * @return
 * @throws IOException
 */
public static Vector mapDirToSparseVector(Path inPath, int nRows, int nCols, Configuration conf)
        throws IOException {
    SparseMatrix matrix = mapDirToSparseMatrix(inPath, nRows, nCols, conf);
    Vector v = matrix.viewRow(0);
    return v;
}

From source file:com.twitter.algebra.AlgebraCommon.java

License:Apache License

/***
 * If the MapDir matrix is small, we can convert it to an in memory representation
 * and then run efficient centralized operations
 * /* w ww.ja  va2s .  co m*/
 * @param origMtx in MapDir format (generated by MatrixOutputFormat)
 * @return a dense matrix including the data
 * @throws IOException 
 */
static SparseMatrix toSparseMatrix(DistributedRowMatrix origMtx) throws IOException {
    MapDir mapDir = new MapDir(new Configuration(), origMtx.getRowPath());
    SparseMatrix mtx = new SparseMatrix(origMtx.numRows(), origMtx.numCols());
    Iterator<MatrixSlice> sliceIterator = mapDir.iterateAll();
    while (sliceIterator.hasNext()) {
        MatrixSlice slice = sliceIterator.next();
        mtx.viewRow(slice.index()).assign(slice.vector());
    }
    mapDir.close();
    return mtx;
}