Package mikera.matrixx.impl

Examples of mikera.matrixx.impl.PermutationMatrix


    assertTrue(m.getTranspose() instanceof Matrix);
  }

  @Test
  public void testPermutationMatrix() {
    PermutationMatrix p = PermutationMatrix.createRandomPermutation(10);

    assertTrue(p.innerProduct(p.getTranspose()).isIdentity());

    try {
      p = PermutationMatrix.create(0, 1, 2, 2, 4);
      fail("Should not be able to create PermutationMatrix with invalid permutation");
    } catch (Throwable t) {
View Full Code Here


      throw new IllegalArgumentException("Wrong matrix size: " + "not square");
    }

    int n = m.rowCount();

    PermutationMatrix p = PermutationMatrix.createIdentity(n);

    for (int j = 0; j < n; j++) {

      Vector jcolumn = m.getColumn(j).toVector();

      for (int i = 0; i < n; i++) {

        int kmax = Math.min(i, j);

        double s = 0.0;
        for (int k = 0; k < kmax; k++) {
          s += m.get(i, k) * jcolumn.unsafeGet(k);
        }

        jcolumn.set(i, jcolumn.unsafeGet(i) - s);
        m.set(i, j, jcolumn.unsafeGet(i));
      }

      int biggest = j;

      for (int i = j + 1; i < n; i++) {
        if (Math.abs(jcolumn.unsafeGet(i)) > Math.abs(jcolumn.unsafeGet(biggest)))
          biggest = i;
      }

      if (biggest != j) {
        m.swapRows(biggest, j);
        p.swapRows(biggest, j);
      }

      if ((j < n) && (m.get(j, j) != 0.0)) {
        for (int i = j + 1; i < n; i++) {
          m.set(i, j, m.get(i, j) / m.get(j, j));
View Full Code Here

TOP

Related Classes of mikera.matrixx.impl.PermutationMatrix

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.