Package mikera.vectorz

Examples of mikera.vectorz.Vector


      v.scale(2.0);
    }   
  }
 
  public void timeImmutable(int runs) {
    Vector v=Vector.createLength(8388608);
    Vectorz.fillGaussian(v);
   
    for (int i=0; i<runs; i++) {
      Vector a=(Vector) v.addCopy(0.375);
      a=(Vector) a.sqrtCopy();
      a=(Vector) a.scaleCopy(2.0);
    }   
  }
View Full Code Here


    }   
  }
 
  @SuppressWarnings("unused")
  public void timeOpsImmutable(int runs) {
    Vector v=Vector.createLength(8388608);
    Vectorz.fillGaussian(v);

    Op op = Ops.compose(Linear.create(2.0,0.0), Ops.compose(Ops.SQRT, Linear.create(0.0,0.375)));
    for (int i=0; i<runs; i++) {
      Vector a=(Vector) v.applyOpCopy(op);
    }   
  }
View Full Code Here

      Vector a=(Vector) v.applyOpCopy(op);
    }   
  }
 
  public void timeOpsMutable(int runs) {
    Vector v=Vector.createLength(8388608);
    Vectorz.fillGaussian(v);

    Op op = Ops.compose(Linear.create(2.0,0.0), Ops.compose(Ops.SQRT, Linear.create(0.0,0.375)));
    for (int i=0; i<runs; i++) {
      v.applyOp(op);
    }   
  }
View Full Code Here

      v.applyOp(op);
    }   
  }
 
  public void timeOptimised(int runs) {
    Vector v=Vector.createLength(8388608);
    Vectorz.fillGaussian(v);

    for (int i=0; i<runs; i++) {
      v.scaleAdd(4.0, 1.5); // combine scaling and addition
      v.sqrt();
    }   
  }
View Full Code Here

public class TestSparseColumnMatrix {

  @Test public void testReplace() {
    SparseColumnMatrix m=SparseColumnMatrix.create(3, 3);
   
    Vector v=Vector.of(1,2,3);
   
    m.replaceColumn(1, v);
    assertTrue(v==m.getColumn(1)); // identical objects
    assertEquals(Vector.of(0,2,0),m.getRow(1));
  }
View Full Code Here

  }

    @Test public void testSetColumn() {
        SparseColumnMatrix m=SparseColumnMatrix.create(3, 3);
       
        Vector v=Vector.of(1,2,3);
       
        m.setColumn(0, v);
        assertEquals(v,m.getColumn(0));
        assertEquals(1,m.getColumn(0).get(0),0.0);
    }
View Full Code Here

    assertEquals(m,m2);
  }

  @Test public void testArithmetic() {
    SparseColumnMatrix M=SparseColumnMatrix.create(3, 3);
    Vector v=Vector.of(-1,2,3);
    M.replaceColumn(1, v);

    assertEquals(4, M.elementSum(), 0.01);
    assertEquals(14, M.elementSquaredSum(), 0.01);
    assertEquals(-1, M.elementMin(), 0.01);
    assertEquals(3, M.elementMax(), 0.01);
    assertEquals(3, M.nonZeroCount());

    SparseRowMatrix N = SparseRowMatrix.create(3,3);
    v=Vector.of(4,5,6);
    N.replaceRow(1, v);
        M.add(N);           // test add
        M.swapColumns(0,1);      // test swapColumns
    assertEquals(7, M.get(1,0), 0.01);

    SparseColumnMatrix M1 = SparseColumnMatrix.create(3, 3);
    Vector v1=Vector.of(-1,2,3);
    M1.replaceColumn(1, v1);

        int[] index = {0,2};
        double[] data = {7,8};
    SparseColumnMatrix M2 = SparseColumnMatrix.create(Vector.of(0,1,2),SparseIndexedVector.wrap(3, index, data),null);
View Full Code Here

    assertEquals(2, M1.get(1,1), 0.01);
  }

  @Test public void testSparseRowMultiply() {
    SparseColumnMatrix M=SparseColumnMatrix.create(3, 3);
    Vector v=Vector.of(1,2,3);
    M.replaceColumn(1, v);

    SparseRowMatrix N = SparseRowMatrix.create(3,3);
    v=Vector.of(4,5,6);
    N.replaceRow(1, v);
View Full Code Here

    // TODO: confirm this is a "Thin SVD"
    // as per Wikipedia
    int n = Math.min(rc, cc); // this should always be cc??

    Matrix u = Matrix.create(rc, n);
    Vector s = Vector.createLength(cc);
    Matrix v = Matrix.create(cc, cc);

    Vector e = Vector.createLength(cc);
    Vector work = Vector.createLength(rc);

    int nct = Math.min(rc - 1, cc);
    int nrt = Math.max(0, Math.min(cc - 2, rc));

    for (int k = 0; k < Math.max(nct, nrt); k++) {

      if (k < nct) {

        for (int i = k; i < rc; i++) {
          s.set(k, Math.hypot(s.get(k), a.get(i, k)));
        }

        if (Math.abs(s.get(k)) > Constants.EPS) {

          if (a.get(k, k) < 0.0) {
            s.set(k, -s.get(k));
          }

          for (int i = k; i < rc; i++) {
            a.set(i, k, a.get(i, k) / (s.get(k)));
          }

          a.addAt(k, k, 1.0);
        }

        s.set(k, -s.get(k));
      }

      for (int j = k + 1; j < cc; j++) {

        if ((k < nct) && (Math.abs(s.get(k)) > Constants.EPS)) {

          double t = 0;

          for (int i = k; i < rc; i++) {
            t += a.get(i, k) * a.get(i, j);
          }

          t = -t / a.get(k, k);

          for (int i = k; i < rc; i++) {
            a.addAt(i, j, (t * a.get(i, k)));
          }
        }

        e.set(j, a.get(k, j));
      }

      if (k < nct) {

        for (int i = k; i < rc; i++) {
          u.set(i, k, a.get(i, k));
        }

      }

      if (k < nrt) {

        e.set(k, 0);

        for (int i = k + 1; i < cc; i++) {
          e.set(k, Math.hypot(e.get(k), e.get(i)));
        }

        if (Math.abs(e.get(k)) > Constants.EPS) {

          if (e.get(k + 1) < 0.0) {

            e.set(k, -e.get(k));
          }

          for (int i = k + 1; i < cc; i++) {
            e.set(i, e.get(i) / (e.get(k)));
          }

          e.addAt(k + 1, 1.0);
        }

        e.set(k, -e.get(k));

        if ((k + 1 < rc) && (Math.abs(e.get(k)) > Constants.EPS)) {

          for (int j = k + 1; j < cc; j++) {
            for (int i = k + 1; i < rc; i++) {
              work.addAt(i, (e.get(j) * a.get(i, j)));
            }
          }

          for (int j = k + 1; j < cc; j++) {

            double t = -e.get(j) / e.get(k + 1);

            for (int i = k + 1; i < rc; i++) {
              a.addAt(i, j, (t * work.get(i)));
            }
          }
        }

        for (int i = k + 1; i < cc; i++) {
View Full Code Here

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

TOP

Related Classes of mikera.vectorz.Vector

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.