Package com.browseengine.bobo.util

Examples of com.browseengine.bobo.util.MutableSparseFloatArray


  public void testMute() throws Throwable {
    try {
      Random rand = new Random(SEED);
     
      float[] orig = new float[1024];
      MutableSparseFloatArray fromEmpty = new MutableSparseFloatArray(new float[1024]);
      float density = 0.2f;
      int idx = 0;
      while (rand.nextFloat() > density) {
        idx++;
      }
      int count = 0;
      while (idx < orig.length) {
        float val = rand.nextFloat();
        orig[idx] = val;
        fromEmpty.set(idx, val);
        count++;
        idx += 1;
        while (rand.nextDouble() > density) {
          idx++;
        }
      }
      float[] copy =new float[orig.length];
      System.arraycopy(orig, 0, copy, 0, orig.length);
      MutableSparseFloatArray fromPartial = new MutableSparseFloatArray(copy);
     
      // do 128 modifications
      int mods = 128;
      for (int i = 0; i < mods; i++) {
        float val = rand.nextFloat();
        idx = rand.nextInt(orig.length);
        orig[idx] = val;
        fromEmpty.set(idx, val);
        fromPartial.set(idx, val);       
      }
     
      for (int i = 0; i < orig.length; i++) {
        assertTrue("orig "+orig[i]+" wasn't the same as fromEmpty "+fromEmpty.get(i)+" at i="+i, orig[i] == fromEmpty.get(i));
        assertTrue("orig "+orig[i]+" wasn't the same as fromPartial "+fromPartial.get(i)+" at i="+i, orig[i] == fromPartial.get(i));
      }
     
      System.out.println(getName()+" success!");
    } catch (Throwable t) {
      System.err.println("fail: "+t);
View Full Code Here


  public void testSpeed() throws Throwable {
    try {
      Random r = new Random(SEED);
     
      float[] orig = new float[16*1024*1024];
      MutableSparseFloatArray arr = new MutableSparseFloatArray(new float[orig.length]);
     
      for (int i = 0; i < 32*1024; i++) {
        int idx = r.nextInt(orig.length);
        if (r.nextBoolean()) {
          assertTrue("orig "+orig[idx]+" not the same as arr "+arr.get(idx)+" at idx="+idx, orig[idx] == arr.get(idx));
        } else {
          float val = r.nextFloat();
          orig[idx] = val;
          arr.set(idx, val);
        }
      }
     
      // repeat it, but timed
      orig = new float[orig.length];
      arr = new MutableSparseFloatArray(new float[orig.length]);
      int[] idxs = new int[1024*1024];
      float[] vals = new float[idxs.length];
      for (int i = 0; i < idxs.length; i++) {
        idxs[i] = r.nextInt(orig.length);
        vals[i] = r.nextFloat();
      }
     
      long markTime = System.currentTimeMillis();
      for (int i = 0; i < idxs.length; i++) {
        orig[i] = vals[i];
      }
      long elapsedTimePrim = System.currentTimeMillis()-markTime;
     
      markTime = System.currentTimeMillis();
      for (int i = 0; i < idxs.length; i++) {
        arr.set(idxs[i], vals[i]);
      }
      long elapsedTimeMutable = System.currentTimeMillis()-markTime;
     
      System.out.println("elapsed time on the primitive array: "+elapsedTimePrim+"; elapsed time on the mutable condensed arr: "+elapsedTimeMutable);
      System.out.println("ratio of time to do it on the mutable condensed arr, to time on primitive array: "+(double)elapsedTimeMutable/elapsedTimePrim);
View Full Code Here

  public void testMute() throws Throwable {
    try {
      Random rand = new Random(SEED);

      float[] orig = new float[1024];
      MutableSparseFloatArray fromEmpty = new MutableSparseFloatArray(new float[1024]);
      float density = 0.2f;
      int idx = 0;
      while (rand.nextFloat() > density) {
        idx++;
      }
      while (idx < orig.length) {
        float val = rand.nextFloat();
        orig[idx] = val;
        fromEmpty.set(idx, val);
        idx += 1;
        while (rand.nextDouble() > density) {
          idx++;
        }
      }
      float[] copy = new float[orig.length];
      System.arraycopy(orig, 0, copy, 0, orig.length);
      MutableSparseFloatArray fromPartial = new MutableSparseFloatArray(copy);

      // do 128 modifications
      int mods = 128;
      for (int i = 0; i < mods; i++) {
        float val = rand.nextFloat();
        idx = rand.nextInt(orig.length);
        orig[idx] = val;
        fromEmpty.set(idx, val);
        fromPartial.set(idx, val);
      }

      for (int i = 0; i < orig.length; i++) {
        assertTrue("orig " + orig[i] + " wasn't the same as fromEmpty " + fromEmpty.get(i)
            + " at i=" + i, orig[i] == fromEmpty.get(i));
        assertTrue("orig " + orig[i] + " wasn't the same as fromPartial " + fromPartial.get(i)
            + " at i=" + i, orig[i] == fromPartial.get(i));
      }

      System.out.println(getName() + " success!");
    } catch (Throwable t) {
      System.err.println("fail: " + t);
View Full Code Here

  public void testSpeed() throws Throwable {
    try {
      Random r = new Random(SEED);

      float[] orig = new float[16 * 1024 * 1024];
      MutableSparseFloatArray arr = new MutableSparseFloatArray(new float[orig.length]);

      for (int i = 0; i < 32 * 1024; i++) {
        int idx = r.nextInt(orig.length);
        if (r.nextBoolean()) {
          assertTrue("orig " + orig[idx] + " not the same as arr " + arr.get(idx) + " at idx="
              + idx, orig[idx] == arr.get(idx));
        } else {
          float val = r.nextFloat();
          orig[idx] = val;
          arr.set(idx, val);
        }
      }

      // repeat it, but timed
      orig = new float[orig.length];
      arr = new MutableSparseFloatArray(new float[orig.length]);
      int[] idxs = new int[1024 * 1024];
      float[] vals = new float[idxs.length];
      for (int i = 0; i < idxs.length; i++) {
        idxs[i] = r.nextInt(orig.length);
        vals[i] = r.nextFloat();
      }

      long markTime = System.currentTimeMillis();
      for (int i = 0; i < idxs.length; i++) {
        orig[i] = vals[i];
      }
      long elapsedTimePrim = System.currentTimeMillis() - markTime;

      markTime = System.currentTimeMillis();
      for (int i = 0; i < idxs.length; i++) {
        arr.set(idxs[i], vals[i]);
      }
      long elapsedTimeMutable = System.currentTimeMillis() - markTime;

      System.out.println("elapsed time on the primitive array: " + elapsedTimePrim
          + "; elapsed time on the mutable condensed arr: " + elapsedTimeMutable);
View Full Code Here

TOP

Related Classes of com.browseengine.bobo.util.MutableSparseFloatArray

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.