Package mikera.vectorz

Examples of mikera.vectorz.Vector


        assertTrue(sv.includesIndex(6));
        assertFalse(sv.includesIndex(5));
  }
 
  @Test public void testSet() {
    Vector v=Vector.of(-1,0,1);
    SparseHashedVector sv=SparseHashedVector.create(Vector.of(10,11,12));
    sv.set(v);
    assertEquals(v,sv);
  }
View Full Code Here


  int result;
 
  int LIST_SIZE=100;

  public void timeCloneArray(int runs) {
    Vector v=Vector.createLength(LIST_SIZE);
   
    Vector res=v;
    double[] data=v.getArray();
    for (int i=0; i<runs; i++) {
      res=Vector.wrap(data.clone());
    }
    result=v.length();
View Full Code Here

    }
    result=v.length();
  }
 
  public void timeCopyOfArray(int runs) {
    Vector v=Vector.createLength(LIST_SIZE);
   
    Vector res=v;
    double[] data=v.getArray();
    for (int i=0; i<runs; i++) {
      res=Vector.wrap(Arrays.copyOf(data, data.length));
    }
    result=v.length();
View Full Code Here

    }
    result=v.length();
  }
 
  public void timeDoubleArraysCopy(int runs) {
    Vector v=Vector.createLength(LIST_SIZE);
   
    Vector res=v;
    double[] data=v.getArray();
    for (int i=0; i<runs; i++) {
      res=Vector.wrap(DoubleArrays.copyOf(data));
    }
    result=v.length();
View Full Code Here

    }
    result=v.length();
  }
 
  public void timeArrayCopyClone(int runs) {
    Vector v=Vector.createLength(LIST_SIZE);
   
    Vector res=v;
    double[] data=v.getArray();
    for (int i=0; i<runs; i++) {
      double[] ds=new double[data.length];
      System.arraycopy(data, 0, ds, 0, data.length);
      res=Vector.wrap(ds);
View Full Code Here

public class TestSparseRowMatrix {

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

  }

    @Test public void testSetRow() {
        SparseRowMatrix m=SparseRowMatrix.create(3, 3);

        Vector v=Vector.of(1,2,3);

        m.setRow(0, v);
        assertEquals(v,m.getRow(0));
        assertEquals(1,m.getRow(0).get(0),0.0);
    }
View Full Code Here

    assertEquals(5,mc.get(0,0),0.0);
  }

  @Test public void testArithmetic() {
    SparseRowMatrix M=SparseRowMatrix.create(3, 3);
    Vector v=Vector.of(-1,2,3);
    M.replaceRow(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());

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

    SparseRowMatrix M1 = SparseRowMatrix.create(3, 3);
    Vector v1=Vector.of(-1,2,3);
    M1.replaceRow(1, v1);

        int[] index = {0,2};
        double[] data = {7,8};
    SparseRowMatrix M2 = SparseRowMatrix.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 testSparseColumnMultiply() {
    SparseRowMatrix M=SparseRowMatrix.create(3, 3);
    Vector v=Vector.of(1,2,3);
    M.replaceRow(1, v);

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

public class ArrayPerfBenchmark extends SimpleBenchmark {
  public static final int MATRIX_SIZE=10;

  public void timeMutable(int runs) {
    Vector v=Vector.createLength(8388608);
    Vectorz.fillGaussian(v);
   
    for (int i=0; i<runs; i++) {
      v.add(0.375);
      v.sqrt();
      v.scale(2.0);
    }   
  }
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.