Java Code Examples for no.uib.cipr.matrix.DenseMatrix#numRows()

The following examples show how to use no.uib.cipr.matrix.DenseMatrix#numRows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedSparseMatrixTest.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void ignoredTimedTransMult() {
    Stopwatch watch = Stopwatch.createUnstarted();
    DenseMatrix dense = new DenseMatrix(1000, 1000);
    int[][] nz = Utilities.getRowPattern(dense.numRows(),
            dense.numColumns(), 100);
    Utilities.rowPopulate(dense, nz);
    log.info("created matrices");
    Matrix sparse = new LinkedSparseMatrix(dense.numRows(),
            dense.numColumns());
    sparse.set(dense);

    for (Matrix m : Lists.newArrayList(dense, sparse)) {
        log.info("starting " + m.getClass());
        Matrix t = new DenseMatrix(m);
        Matrix o = new DenseMatrix(dense.numRows(), dense.numColumns());
        log.info("warming up " + m.getClass() + " " + o.getClass());
        for (int i = 0; i < 10; i++)
            m.transAmult(t, o);
        log.info("starting " + m.getClass() + " " + o.getClass());
        watch.start();
        for (int i = 0; i < 100; i++)
            m.transAmult(t, o);
        watch.stop();
        log.info(m.getClass() + " " + o.getClass() + " " + watch);
    }
}
 
Example 2
Source File: LinkedSparseMatrixTest.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void ignoredTimedMult() {
    Stopwatch watch = Stopwatch.createUnstarted();
    DenseMatrix dense = new DenseMatrix(1000, 1000);
    int[][] nz = Utilities.getRowPattern(dense.numRows(),
            dense.numColumns(), 100);
    Utilities.rowPopulate(dense, nz);
    log.info("created matrices");
    Matrix sparse = new LinkedSparseMatrix(dense.numRows(),
            dense.numColumns());
    sparse.set(dense);

    for (Matrix m : Lists.newArrayList(dense, sparse)) {
        log.info("starting " + m.getClass());
        Matrix t = new DenseMatrix(m);
        t.transpose();
        Matrix o = new DenseMatrix(dense.numRows(), dense.numColumns());
        log.info("warming up " + m.getClass() + " " + o.getClass());
        for (int i = 0; i < 10; i++)
            m.mult(t, o);
        log.info("starting " + m.getClass() + " " + o.getClass());
        watch.start();
        for (int i = 0; i < 100; i++)
            m.mult(t, o);
        watch.stop();
        log.info(m.getClass() + " " + o.getClass() + " " + watch);
    }
}
 
Example 3
Source File: MatrixTools.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public static DenseDoubleMatrix2D toDenseDoubleMatrix(DenseMatrix matrix) {
    DenseDoubleMatrix2D matrix2D = new DenseDoubleMatrix2D(matrix.numRows(), matrix.numColumns());
    
    for(int c = 0; c<matrix.numColumns(); c++){
        for(int r = 0; r<matrix.numRows(); r++){
            matrix2D.setQuick(r,c, matrix.get(r, c));
        }
    }
    
    return matrix2D;
}
 
Example 4
Source File: AMG.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setMatrix(Matrix A) {
    List<CompRowMatrix> Al = new LinkedList<CompRowMatrix>();
    List<CompColMatrix> Il = new LinkedList<CompColMatrix>();

    Al.add(new CompRowMatrix(A));

    for (int k = 0; Al.get(k).numRows() > min; ++k) {

        CompRowMatrix Af = Al.get(k);

        double eps = 0.08 * Math.pow(0.5, k);

        // Create the aggregates
        Aggregator aggregator = new Aggregator(Af, eps);

        // If no aggregates were created, no interpolation operator will be
        // created, and the setup phase stops
        if (aggregator.getAggregates().isEmpty())
            break;

        // Create an interpolation operator using smoothing. This also
        // creates the Galerkin operator
        Interpolator sa = new Interpolator(aggregator, Af, omega);

        Al.add(sa.getGalerkinOperator());
        Il.add(sa.getInterpolationOperator());
    }

    // Copy to array storage
    m = Al.size();
    if (m == 0)
        throw new RuntimeException("Matrix too small for AMG");

    I = new CompColMatrix[m - 1];
    this.A = new CompRowMatrix[m - 1];

    Il.toArray(I);
    for (int i = 0; i < Al.size() - 1; ++i)
        this.A[i] = Al.get(i);

    // Create a LU decomposition of the smallest Galerkin matrix
    DenseMatrix Ac = new DenseMatrix(Al.get(Al.size() - 1));
    lu = new DenseLU(Ac.numRows(), Ac.numColumns());
    lu.factor(Ac);

    // Allocate vectors at each level
    u = new DenseVector[m];
    f = new DenseVector[m];
    r = new DenseVector[m];
    for (int k = 0; k < m; ++k) {
        int n = Al.get(k).numRows();
        u[k] = new DenseVector(n);
        f[k] = new DenseVector(n);
        r[k] = new DenseVector(n);
    }

    // Set up the SSOR relaxation schemes
    preM = new SSOR[m - 1];
    postM = new SSOR[m - 1];
    for (int k = 0; k < m - 1; ++k) {
        CompRowMatrix Ak = this.A[k];
        preM[k] = new SSOR(Ak, reverse, omegaPreF, omegaPreR);
        postM[k] = new SSOR(Ak, reverse, omegaPostF, omegaPostR);
        preM[k].setMatrix(Ak);
        postM[k].setMatrix(Ak);
    }
}