Package cern.colt.matrix

Examples of cern.colt.matrix.DoubleMatrix2D


  System.out.println("\n\n");
  System.out.print("now initializing... ");
  cern.colt.Timer timer = new cern.colt.Timer().start();

  final cern.jet.math.Functions F = cern.jet.math.Functions.functions;
  DoubleMatrix2D A = cern.colt.matrix.DoubleFactory2D.dense.make(rows,columns);
  A.assign(new cern.jet.random.engine.DRand()); // initialize randomly
  timer.stop().display();

  // also benchmark copying in its several implementation flavours
  DoubleMatrix2D B = A.like();
  timer.reset().start();
  System.out.print("now copying... ");
  B.assign(A);
  timer.stop().display();

  timer.reset().start();
  System.out.print("now copying subrange... ");
  B.viewPart(0,0,rows,columns).assign(A.viewPart(0,0,rows,columns));
  timer.stop().display();
  //System.out.println(A);

  timer.reset().start();
  System.out.print("now copying selected... ");
  B.viewSelection(null,null).assign(A.viewSelection(null,null));
  timer.stop().display();

  System.out.print("now sorting - quick version with precomputation... ");
  timer.reset().start();
  // THE QUICK VERSION (takes some 10 secs)
View Full Code Here


    { 2,3,0 },
    { 1,0,0 },
    { 4,0,0 },
    { 2,0,0 }
  };
  DoubleMatrix2D A = DoubleFactory2D.dense.make(values);
  DoubleMatrix2D B,C;
  /*
  DoubleMatrix1DComparator comp = new DoubleMatrix1DComparator() {
    public int compare(DoubleMatrix1D a, DoubleMatrix1D b) {
      double as = a.zSum(); double bs = b.zSum();
      return as < bs ? -1 : as == bs ? 0 : 1;
View Full Code Here

  System.out.println("\n\n");
  System.out.println("now initializing... ");

  final cern.jet.math.Functions F = cern.jet.math.Functions.functions;
  DoubleMatrix2D A = cern.colt.matrix.DoubleFactory2D.dense.make(rows,columns);
  A.assign(new cern.jet.random.engine.DRand()); // initialize randomly
  DoubleMatrix2D B = A.copy();

  double[] v1 = A.viewColumn(0).toArray();
  double[] v2 = A.viewColumn(0).toArray();
  System.out.print("now quick sorting... ");
  cern.colt.Timer timer = new cern.colt.Timer().start();
View Full Code Here

    System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length);
    return this;
  }
 
  if (haveSharedCells(other)) {
    DoubleMatrix2D c = other.copy();
    if (! (c instanceof DenseDoubleMatrix2D)) { // should not happen
      return super.assign(other);
    }
    other = (DenseDoubleMatrix2D) c;
  }
View Full Code Here

  cern.colt.Timer timer3 = new cern.colt.Timer();
  cern.colt.Timer timer4 = new cern.colt.Timer();
  cern.colt.Timer timer5 = new cern.colt.Timer();
  cern.colt.Timer timer6 = new cern.colt.Timer();

  DoubleMatrix2D matrix = null;
  if (kind.equals("sparse")) matrix = new SparseDoubleMatrix2D(size,size,initialCapacity,minLoadFactor,maxLoadFactor);
  else if (kind.equals("dense")) matrix = cern.colt.matrix.DoubleFactory2D.dense.make(size,size);
  //else if (kind.equals("denseArray")) matrix = new DoubleArrayMatrix2D(size,size);
  else throw new RuntimeException("unknown kind");
 
  System.out.println("\nNow initializing...");
  //Matrix AJ = new Matrix(columnwise,3);
  //Basic.random(matrix, new cern.jet.random.Uniform(new cern.jet.random.engine.MersenneTwister()));
  double value = 2;
  DoubleMatrix2D tmp = DoubleFactory2D.dense.sample(matrix.rows(), matrix.columns(), value, percentNonZero);
  matrix.assign(tmp);
  tmp = null;
  /*
  long NN = matrix.size();
  int nn = (int) (NN*percentNonZero);
  long[] nonZeroIndexes = new long[nn];
  cern.jet.random.sampling.RandomSampler sampler = new cern.jet.random.sampling.RandomSampler(nn,NN,0,new cern.jet.random.engine.MersenneTwister());
  sampler.nextBlock(nn,nonZeroIndexes,0);
  for (int i=nn; --i >=0; ) {
    int row = (int) (nonZeroIndexes[i]/size);
    int column = (int) (nonZeroIndexes[i]%size);
    matrix.set(row,column, value);
  }
  */

  /*
  timer1.start();
  for (int i=0; i<runs; i++) {
    LUDecomposition LU = new LUDecomposition(matrix);
  }
  timer1.stop();
  timer1.display();

  {
    Jama.Matrix jmatrix = new Jama.Matrix(matrix.toArray());
    timer2.start();
    for (int i=0; i<runs; i++) {
      Jama.LUDecomposition LU = new Jama.LUDecomposition(jmatrix);
    }
    timer2.stop();
    timer2.display();
  }
  */
  System.out.println("\ntesting...");
  if (print) System.out.println(matrix);
  DoubleMatrix2D dense = DoubleFactory2D.dense.make(size,size);
  dense.assign(matrix);
  if (! dense.equals(matrix)) throw new InternalError();
  DoubleMatrix2D ADense = dense.copy();
  DoubleMatrix2D BDense = dense.copy();
  DoubleMatrix2D CDense = dense.copy();
  ADense.zMult(BDense,CDense);
  System.out.println("\nNext testing...");
  /*
  {
    timer6.start();
    double a = cubicLoop(runs,size);
    timer6.stop();
    timer6.display();
    System.out.println(a);
  }
  */
 

  {
    DoubleMatrix2D A = matrix.copy();
    DoubleMatrix2D B = matrix.copy();
    //DoubleMatrix2D C = Basic.product(A,B);
    DoubleMatrix2D C = matrix.copy();
    A.zMult(B,C);
    if (! (C.equals(CDense))) throw new InternalError();
    C.assign(matrix);
    System.out.println("\nNow benchmarking...");
   
    timer3.start();
    for (int i=0; i<runs; i++) {
      A.zMult(B,C);
View Full Code Here

 

  long before = Runtime.getRuntime().freeMemory();
  long size = (((long)rows)*columns)*runs;

  DoubleMatrix2D matrix = null;
  if (kind.equals("sparse")) matrix = new SparseDoubleMatrix2D(rows,columns,initialCapacity,minLoadFactor,maxLoadFactor);
  else if (kind.equals("dense")) matrix = new DenseDoubleMatrix2D(rows,columns);
  //else if (kind.equals("denseArray")) matrix = new DoubleArrayMatrix2D(rows,columns);
  else throw new RuntimeException("unknown kind");
 
  System.out.println("\nNow filling...");
  //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0;
  for (int i=0; i<runs; i++) {
    matrix.assign(0);
    matrix.ensureCapacity(initialCapacity);
    if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).ensureCapacity(initialCapacity);
    timer1.start();
    int value = 0;
    for (int row=0; row < rows; row++) {
      for (int column=0; column < columns; column++) {
        matrix.setQuick(row,column,value++);
      }
    }
    timer1.stop();
  }
  timer1.display();
  timer1.minus(emptyLoop).display();
  System.out.println(size / timer1.minus(emptyLoop).seconds() +" elements / sec");
 
  Runtime.getRuntime().gc(); // invite gc
  try { Thread.currentThread().sleep(1000); } catch (InterruptedException exc) {};
  long after = Runtime.getRuntime().freeMemory();
  System.out.println("KB needed="+(before-after) / 1024);
  System.out.println("bytes needed per non-zero="+(before-after) / (double)matrix.cardinality());
  if (print) {
    System.out.println(matrix);
    if (kind.equals("sparse")) System.out.println("map="+((SparseDoubleMatrix2D)matrix).elements);
  }
  /*
  if (kind.equals("sparse")) {
    int hashCollisions = ((SparseDoubleMatrix2D)matrix).elements.hashCollisions;
    System.out.println("hashCollisions="+hashCollisions);
    System.out.println("--> "+ ((double)hashCollisions / (rows*columns)) +" hashCollisions/element on average.");
  }
  */
 
  System.out.println("\nNow reading...");
  //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0;
  timer2.start();
  double element=0;
  for (int i=0; i<runs; i++) {
    for (int row=0; row < rows; row++) {
      for (int column=0; column < columns; column++) {
        element += matrix.getQuick(row,column);
      }
    }   
  }
  timer2.stop().display()
  timer2.minus(emptyLoop2).display();
  System.out.println(size / timer2.minus(emptyLoop2).seconds() +" elements / sec");
  if (print) System.out.println(matrix);
  //if (kind.equals("sparse")) System.out.println("hashCollisions="+((SparseDoubleMatrix2D)matrix).elements.hashCollisions);
  System.out.println(element); // !!! so that the jitter can't optimize away the whole loop
 
  System.out.println("\nNow reading view...");
  DoubleMatrix2D view = matrix.viewPart(0,0,rows,columns);
  timer4.start();
  element=0;
  for (int i=0; i<runs; i++) {
    for (int row=0; row < rows; row++) {
      for (int column=0; column < columns; column++) {
        element += view.getQuick(row,column);
      }
    }   
  }
  timer4.stop().display()
  timer4.minus(emptyLoop2).display();
View Full Code Here

  cern.colt.Timer timer1 = new cern.colt.Timer();
  cern.colt.Timer timer2 = new cern.colt.Timer();

  long size = (((long)rows)*columns)*runs;

  DoubleMatrix2D matrix = null;
  if (kind.equals("sparse")) matrix = new SparseDoubleMatrix2D(rows,columns,initialCapacity,minLoadFactor,maxLoadFactor);
  else if (kind.equals("dense")) matrix = new DenseDoubleMatrix2D(rows,columns);
  //else if (kind.equals("denseArray")) matrix = new DoubleArrayMatrix2D(rows,columns);
  else throw new RuntimeException("unknown kind");
 
  System.out.println("\nNow multiplying...");
  matrix.assign(1);
  //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0;
  for (int i=0; i<runs; i++) {
    timer1.start();
    cern.colt.matrix.doublealgo.Transform.mult(matrix, 3);
    timer1.stop();
  }
  timer1.display();
  System.out.println(size / timer1.seconds() +" elements / sec");
 
  if (print) {
    System.out.println(matrix);
  }
  /*
  if (kind.equals("sparse")) {
    int hashCollisions = ((SparseDoubleMatrix2D)matrix).elements.hashCollisions;
    System.out.println("hashCollisions="+hashCollisions);
    System.out.println("--> "+ ((double)hashCollisions / (rows*columns)) +" hashCollisions/element on average.");
  }
  */
 
  System.out.println("\nNow multiplying2...");
  matrix.assign(1);
  //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0;
  for (int i=0; i<runs; i++) {
    timer2.start();
    cern.colt.matrix.doublealgo.Transform.mult(matrix,3);
    timer2.stop();
View Full Code Here

  };
 
  double[] x = { 1, 2 };
  double[] y = { 3, 4 };

  DoubleMatrix2D A = new DenseDoubleMatrix2D(data);
  SeqBlas.seqBlas.dger(1,new DenseDoubleMatrix1D(x), new DenseDoubleMatrix1D(y), A);

  System.out.println(A);
}
View Full Code Here

    { 0, 0, 8 },
    { 0, 0, 0 },
    { 0, 0, 0 }
  };
 
  DoubleMatrix2D x = new TridiagonalDoubleMatrix2D(data);
 

  System.out.println("\n\n\n"+x);
  System.out.println("\n"+new DenseDoubleMatrix2D(data));
}
View Full Code Here

    { 0, 0, 0 },
    { 0, 0, 0 }
  };
  */
 
  DoubleMatrix2D x = new DenseDoubleMatrix2D(data);

  System.out.println("\n\n\n"+x);
  System.out.println("\n"+ x.equals(ninf));
}
View Full Code Here

TOP

Related Classes of cern.colt.matrix.DoubleMatrix2D

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.