Package no.uib.cipr.matrix

Examples of no.uib.cipr.matrix.DenseMatrix


    }
  }

  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);
    }
  }
View Full Code Here


    }
  }

  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);
    }
  }
View Full Code Here

    for (int r = 0; r < 10; r++) {
      for (int m = 10000; m <= 100000; m = m + 10000) {
        for (int n = 1000; n <= 10000; n = n + 1000) {
          int[][] patternA = Utilities.getRowPattern(n, n, m / n);
          DenseMatrix origA = new DenseMatrix(n, n);
          Utilities.rowPopulate(origA, patternA);
          int[][] patternB = Utilities.getRowPattern(n, n, m / n);
          DenseMatrix origB = new DenseMatrix(n, n);
          Utilities.rowPopulate(origB, patternB);
          // to be fair, we reuse the same matrix values

          long denseMem, denseInitTime, denseMultTime, sparseMem, sparseInitTime, sparseMultTime;

          Stopwatch timer = Stopwatch.createUnstarted();
          {
            timer.reset();
            timer.start();
            DenseMatrix A = new DenseMatrix(origA);
            timer.stop();
            // all attempts to measure memory usage failed
            denseMem = n * n * 8;
            denseInitTime = timer.elapsed(TimeUnit.NANOSECONDS);
            timer.reset();

            DenseMatrix B = origB.copy();
            DenseMatrix C = new DenseMatrix(n, n);
            timer.start();
            A.mult(B, C);
            timer.stop();
            denseMultTime = timer.elapsed(TimeUnit.NANOSECONDS);
          }
          {
            timer.reset();
            timer.start();
            LinkedSparseMatrix A = new LinkedSparseMatrix(origA);
            timer.stop();
            // using compressedooms
            sparseMem = m * 28 + 16 * n;
            sparseInitTime = timer.elapsed(TimeUnit.NANOSECONDS);
            timer.reset();

            DenseMatrix B = origB.copy();
            DenseMatrix C = new DenseMatrix(n, n);
            timer.start();
            A.mult(B, C);
            timer.stop();
            sparseMultTime = timer.elapsed(TimeUnit.NANOSECONDS);
          }
View Full Code Here

    }

    private void assertEquals(Matrix A, SVD svd) {
        TridiagMatrix S = new TridiagMatrix(svd.getS().length);
        System.arraycopy(svd.getS(), 0, S.getDiagonal(), 0, svd.getS().length);
        DenseMatrix U = svd.getU();
        DenseMatrix Vt = svd.getVt();

        // Compute U*S*Vt
        Matrix s = U.mult(S.mult(Vt, new DenseMatrix(S.numRows(), Vt
                .numColumns())), new DenseMatrix(A.numRows(), A.numColumns()));

        // Check that A=U*S*Vt
        for (int i = 0; i < A.numRows(); ++i)
            for (int j = 0; j < A.numColumns(); ++j)
                assertEquals(A.get(i, j), s.get(i, j), 1e-12);
View Full Code Here

        A = null;
    }

    protected void assertEquals(Matrix A, double[] w, DenseMatrix Z) {
        // A*X
        Matrix left = A.mult(Z, new DenseMatrix(A.numRows(), A.numColumns()));

        // lambda*X
        Matrix right = new DenseMatrix(Z);
        for (int i = 0; i < w.length; ++i)
            for (int j = 0; j < w.length; ++j)
                right.set(i, j, w[j] * right.get(i, j));

        // Check that A*X=lambda*X
        for (int i = 0; i < A.numRows(); ++i)
            for (int j = 0; j < A.numColumns(); ++j)
                assertEquals(left.get(i, j), right.get(i, j), 1e-12);
    }
View Full Code Here

TOP

Related Classes of no.uib.cipr.matrix.DenseMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.