Package mikera.indexz

Examples of mikera.indexz.Index


  }

  @Test public void testIndexedDotProduct() {
    Vector v1=Vector.of(0,1,2,3,4,5,6,7,8,9);
    Vector v2=Vector.of(1,2,3);
    Index ix=Index.of (2,7,4);
   
    assertEquals((1*2)+(2*7)+(3*4),v1.dotProduct(v2,ix),0.0);
  }
 
View Full Code Here


      Vectorz.fillGaussian(v);
    }
    int len=v.length();
    int tlen=len+10;
   
    Index ix=Indexz.createRandomChoice(len, tlen);
    Vector tv=Vector.createLength(tlen);
   
    tv.addMultiple(v, ix, 2.0);
    assertEquals(v.elementSum()*2.0,tv.elementSum(),0.0001);
  }
 
View Full Code Here

    v=v.exactClone();
    int len=v.length();
   
    Vector tv=Vector.createLength(len);
    Vectorz.fillGaussian(tv);
    Index ix=Indexz.createLength(len);
    for (int i=0; i<len; i++) {
      ix.set(i, Rand.r(len));
    }
   
    v.addMultiple(tv, ix, 2.0);
    assertEquals(len+tv.elementSum()*2.0,v.elementSum(),0.0001);
  }
 
View Full Code Here

   
    if (n>0) {
      assertTrue(v.isRangeZero(0, nzi[0])); // check the leading part of the vector is all zero
    }
   
    Index ind=Index.of(nzi);
    assertEquals(n,nzi.length);
   
    for (int i=0; i<nzi.length; i++) {
      assertTrue(v.unsafeGet(nzi[i])!=0.0);
    }
   
    for (int i=0; i<len; i++) {
      if (v.unsafeGet(i)==0.0) {
        assertFalse(ind.containsSorted(i));
      } else {
        assertTrue(ind.containsSorted(i));       
      }
    }
  }
View Full Code Here

import mikera.indexz.Index;

public class TestIntArrays {
  @Test public void testCreate() {
    Index ix=Index.of(1,2,3,4);
   
    assertTrue(IntArrays.equals(ix.data, IntArrays.create(ix)));
  }
View Full Code Here

    for (int i=0; i<SSIZE; i++) {
      double[] data=new double[DSIZE];
      for (int j=0; j<DSIZE; j++) {
        data[j]=Rand.nextDouble();
      }
      Index indy=Indexz.createRandomChoice(DSIZE, SSIZE);
      M.replaceRow(i,SparseIndexedVector.create(SSIZE, indy, data));
    }
    Matrix D = Matrix.create(M);
    assertTrue(M.equals(D));
    assertTrue(D.epsilonEquals(M, 0.1));
View Full Code Here

    for (int i=0; i<SSIZE; i++) {
      double[] data=new double[DSIZE];
      for (int j=0; j<DSIZE; j++) {
        data[j]=Rand.nextDouble();
      }
      Index indy=Indexz.createRandomChoice(DSIZE, SSIZE);
      M.replaceColumn(i,SparseIndexedVector.create(SSIZE, indy, data));
    }
    Matrix D = Matrix.create(M);
    assertTrue(M.equals(D));
    assertTrue(D.epsilonEquals(M, 0.1));
View Full Code Here

   * @return
   */
  public Index nonSparseIndex(){
    int n=(int)nonZeroCount();
    int length=length();
    Index ind=Index.createLength(n);
    int di=0;
    for (int i=0; i<length; i++) {
      double v=unsafeGet(i);
      if (v!=0.0) {
        ind.data[di++]=i;
View Full Code Here

  public static PermutationMatrix wrap(Index rowPermutations) {
    return new PermutationMatrix(rowPermutations);
  }
 
  public static PermutationMatrix create(int... rowPermutations) {
    Index index=Index.of(rowPermutations);
    return wrap(index);
  }
View Full Code Here

  public static PermutationMatrix wrap(int[] rowPermutations) {
    return wrap(Index.wrap(rowPermutations));
  }
 
  public static PermutationMatrix createRandomPermutation(int length) {
    Index index=Indexz.createRandomPermutation(length);
    return new PermutationMatrix(index);
  }
View Full Code Here

TOP

Related Classes of mikera.indexz.Index

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.