Package mikera.vectorz

Examples of mikera.vectorz.AVector


      int n = (int) a.elementCount();

      INDArray b = a.exactClone();
      INDArray c = a.exactClone();
      INDArray d = a.exactClone();
      AVector v = Vector.create(b);
      assertEquals(n,v.length());
      double[] ds = new double[n];
      double[] tmp = new double[n];
      a.getElements(ds, 0);

      boolean nan=false;
      for (int i = 0; i < n; i++) {
        double x= op.apply(v.unsafeGet(i));
        if (Double.isNaN(x)) nan=true;
        tmp[i] = x;
      }
      if (nan) continue; // TODO: compare NaNs properly
      b.validate();
View Full Code Here


    DoubleBuffer buf = DoubleBuffer.allocate(len);
    assertEquals(len, buf.remaining());
    a.toDoubleBuffer(buf);
    assertEquals(0, buf.remaining());
    buf.flip();
    AVector vv = Vectorz.create(buf);
    assertEquals(a.asVector(), vv);
    assertEquals(a, vv.reshape(a.getShape()));
  }
View Full Code Here

 
  private void testElementIterator(INDArray m) {
    Iterator<Double> it=m.elementIterator();
   
    int i=0;
    AVector av=m.asVector();
    while (it.hasNext()) {
      double v=it.next();
      assertEquals(av.get(i++),v,0.0);
    }
    assertEquals(m.elementCount(),i);
  }
View Full Code Here

      a1.reciprocal();
      assertTrue(a.toVector().epsilonEquals(a1.toVector()));
    }

    INDArray b = a.exactClone();
    AVector v = b.toVector();
    b.pow(2.5);
    v.pow(2.5);
    assertTrue(v.epsilonEquals(b.toVector()));

    b = a.exactClone();
    v = b.toVector();
    b.square();
    v.square();
    assertEquals(v, b.toVector());
  }
View Full Code Here

public class TestMisc {
  @Test
  public void testCompose() {
    double angle = Math.random();
    AVector v = Vectorz.createUniformRandomVector(3);
    Matrix33 rot = Matrixx.createRotationMatrix(v, angle);

    AMatrix tr = Matrixx.createRandomMatrix(6, 3);

    AMatrix r = tr.compose(rot);

    assertEquals(6, r.rowCount());
    assertEquals(3, r.columnCount());

    AVector x = Vectorz.createUniformRandomVector(3);
    AVector x2 = x.clone();

    AVector y = r.transform(x);
    AVector y2 = tr.transform(rot.transform(x2));

    assertTrue(y.epsilonEquals(y2));
  }
View Full Code Here

    assertTrue(y.epsilonEquals(y2));
  }

  @Test
  public void test180RotationMatrix() {
    AVector v = Vector.of(Math.random(), 0, 0);
    double angle = Math.PI;
    Matrix33 rot = Matrixx.createYAxisRotationMatrix(angle);

    AVector r = rot.transform(v);
    v.negate();
    assertTrue(v.epsilonEquals(r));
  }
View Full Code Here

    }
  }

  @Test
  public void testRandomRotation() {
    AVector v = Vectorz.createUniformRandomVector(3);
    AVector axis = Vectorz.createUniformRandomVector(3);
    double angle = Math.random();
    Matrix33 rot = Matrixx.createRotationMatrix(axis, angle);

    AVector r = rot.transform(v);
    assertEquals(v.magnitude(), r.magnitude(), 0.00001);

    Matrix33 inv = rot.inverse();
    AVector ri = inv.transform(r);
    assertTrue(v.epsilonEquals(ri));
  }
View Full Code Here

  }

  @Test
  public void testScale() {
    for (int i = 1; i < 10; i++) {
      AVector v = Vectorz.newVector(i);
      for (int j = 0; j < v.length(); j++) {
        v.set(j, j + 1.3);
      }

      AVector tv = v.clone();

      AMatrix m = Matrixx.createScaleMatrix(i, 2.3);

      m.transform(v, tv);

      assertEquals(v.magnitude() * 2.3, tv.magnitude(), 0.0001);
    }
  }
View Full Code Here

  }

  @Test
  public void testCompoundTransform() {
    AVector v = Vector.of(1, 2, 3);

    AMatrix m1 = Matrixx.createScaleMatrix(3, 2.0);
    AMatrix m2 = Matrixx.createScaleMatrix(3, 1.5);
    ATransform ct = new MatrixTransform(m2)
        .compose(new MatrixTransform(m1));
View Full Code Here

    assertTrue(Vector3.of(3, 6, 9).epsilonEquals(ct.transform(v)));
  }
 
  @Test
  public void testRotationMatrix() {
    AVector v=Vectorz.createUniformRandomVector(3)
    double angle=Math.random();
    Matrix33 rot=Matrixx.createRotationMatrix(v, angle);
   
    AVector r=rot.transform(v);
    assertEquals(v.get(0),r.get(0),0.00001);
    assertEquals(v.get(1),r.get(1),0.00001);
    assertEquals(v.get(2),r.get(2),0.00001);
    assertEquals(v.magnitude(),r.magnitude(),0.00001);
    assertTrue(r.epsilonEquals(v));
  }
View Full Code Here

TOP

Related Classes of mikera.vectorz.AVector

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.