Package cern.colt.matrix

Examples of cern.colt.matrix.DoubleMatrix3D


  }
  DenseDoubleMatrix3D other = (DenseDoubleMatrix3D) source;
  if (other==this) return this;
  checkShape(other);
  if (haveSharedCells(other)) {
    DoubleMatrix3D c = other.copy();
    if (! (c instanceof DenseDoubleMatrix3D)) { // should not happen
      return super.assign(source);
    }
    other = (DenseDoubleMatrix3D) c;
  }
View Full Code Here


    public double apply(double a, double b) { return Math.PI*Math.log(b/a); }
   }
)
);

DoubleMatrix3D x = cern.colt.matrix.DoubleFactory3D.dense.ascending(2,2,2);
System.out.println(x);

// Sum( x[slice,row,col]*x[slice,row,col] )
System.out.println(x.aggregate(F.plus,F.square));
//--> 140


DoubleMatrix3D y = x.copy();
// Sum( (x[i]+y[i])^2 )
System.out.println(x.aggregate(y, F.plus, F.chain(F.square,F.plus)));
//--> 560

System.out.println(matrix.assign(F.random()));
View Full Code Here

@param convergenceIterations the number of iterations to pass between each convergence check.
  (Since a convergence may be expensive, you may want to do it only every 2,4 or 8 iterations.)
@return the number of iterations actually executed.
*/
public static int stencil27(DoubleMatrix3D A, cern.colt.function.Double27Function function, int maxIterations, DoubleMatrix3DProcedure hasConverged, int convergenceIterations) {
  DoubleMatrix3D B = A.copy();
  if (convergenceIterations <= 1) convergenceIterations=2;
  if (convergenceIterations%2 != 0) convergenceIterations++; // odd -> make it even

  int i=0;
  while (i<maxIterations) { // do two steps at a time for efficiency
    A.zAssign27Neighbors(B,function);
    B.zAssign27Neighbors(A,function);
    i=i+2;
    if (i%convergenceIterations == 0 && hasConverged!=null) {
      if (hasConverged.apply(A)) return i;
    }
  }
View Full Code Here

* Demonstrates advanced sorting.
* Sorts by sum of slice.
*/
public static void zdemo2() {
  Sorting sort = quickSort;
  DoubleMatrix3D matrix = DoubleFactory3D.dense.descending(4,3,2);
  DoubleMatrix2DComparator comp = new DoubleMatrix2DComparator() {
    public int compare(DoubleMatrix2D a, DoubleMatrix2D b) {
      double as = a.zSum();
      double bs = b.zSum();
      return as < bs ? -1 : as == bs ? 0 : 1;
View Full Code Here

  //double[] densities = {0.001,0.01,0.1,0.999};
 
  //int[] sizes = {3};
  //double[] densities = {0.1};

  DoubleMatrix3D timings = DoubleFactory3D.dense.make(types.length,sizes.length,densities.length);
  cern.colt.Timer runTime = new cern.colt.Timer().start();
  for (int k=0; k<types.length; k++) {
    //DoubleFactory2D factory = (k==0 ? DoubleFactory2D.dense : k==1 ? DoubleFactory2D.sparse : DoubleFactory2D.rowCompressed);
    //DoubleFactory2D factory = (k==0 ? DoubleFactory2D.dense : k==1 ? DoubleFactory2D.sparse : k==2 ? DoubleFactory2D.rowCompressed : DoubleFactory2D.rowCompressedModified);
    DoubleFactory2D factory = getFactory(types[k]);
    System.out.print("\n@");

    for (int i=0; i<sizes.length; i++) {
      int size = sizes[i];
      System.out.print("x");
      //System.out.println("doing size="+size+"...");

      for (int j=0; j<densities.length; j++) {
        final double density = densities[j];
        System.out.print(".");
        //System.out.println("   doing density="+density+"...");
        float opsPerSec;

        //if (true) {
        //if (!((k==1 && density >= 0.1 && size >=100) || (size>5000 && (k==0 || density>1.0E-4) ))) {
        if (!((k>0 && density >= 0.1 && size >=500) )) {
          double val = 0.5;
          function.A=null; function.B=null; function.C=null; function.D=null; // --> help gc before allocating new mem
          DoubleMatrix2D A = factory.sample(size,size,val,density);
          DoubleMatrix2D B = factory.sample(size,size,val,density);
          function.setParameters(A,B);
          A = null; B = null; // help gc
          double ops = function.operations();
          double secs = BenchmarkKernel.run(minSeconds,function);
          opsPerSec = (float) (ops / secs);
        }
        else { // skip this parameter combination (not used in practice & would take a lot of memory and time)
          opsPerSec = Float.NaN;
        }
        timings.set(k,i,j,opsPerSec);
        //System.out.println(secs);
        //System.out.println(opsPerSec+" Mops/sec\n");
      }
    }
  }
  runTime.stop();
 
  String sliceAxisName = "type";
  String rowAxisName = "size";
  String colAxisName = "d"; //"density";
  //String[] sliceNames = {"dense", "sparse"};
  //String[] sliceNames = {"dense", "sparse", "rowCompressed"};
  String[] sliceNames = types;
  hep.aida.bin.BinFunctions1D F = hep.aida.bin.BinFunctions1D.functions;
  hep.aida.bin.BinFunction1D[] aggr = null; //{F.mean, F.median, F.sum};
  String[] rowNames = new String[sizes.length];
  String[] colNames = new String[densities.length];
  for (int i=sizes.length; --i >= 0; ) rowNames[i]=Integer.toString(sizes[i]);
  for (int j=densities.length; --j >= 0; ) colNames[j]=Double.toString(densities[j]);
  System.out.println("*");
  // show transposed
  String tmp = rowAxisName; rowAxisName = colAxisName; colAxisName = tmp;
  String[] tmp2 = rowNames; rowNames = colNames; colNames = tmp2;
  timings = timings.viewDice(0,2,1);
  System.out.println(new cern.colt.matrix.doublealgo.Formatter("%1.3G").toTitleString(timings,sliceNames,rowNames,colNames,sliceAxisName,rowAxisName,colAxisName,"Performance of "+title,aggr));
  /*
  title = "Speedup of dense over sparse";
  DoubleMatrix2D speedup = cern.colt.matrix.doublealgo.Transform.div(timings.viewSlice(0).copy(),timings.viewSlice(1));
  System.out.println("\n"+new cern.colt.matrix.doublealgo.Formatter("%1.3G").toTitleString(speedup,rowNames,colNames,rowAxisName,colAxisName,title,aggr));
View Full Code Here

@param convergenceIterations the number of iterations to pass between each convergence check.
  (Since a convergence may be expensive, you may want to do it only every 2,4 or 8 iterations.)
@return the number of iterations actually executed.
*/
public static int stencil27(DoubleMatrix3D A, cern.colt.function.Double27Function function, int maxIterations, DoubleMatrix3DProcedure hasConverged, int convergenceIterations) {
  DoubleMatrix3D B = A.copy();
  if (convergenceIterations <= 1) convergenceIterations=2;
  if (convergenceIterations%2 != 0) convergenceIterations++; // odd -> make it even

  int i=0;
  while (i<maxIterations) { // do two steps at a time for efficiency
    A.zAssign27Neighbors(B,function);
    B.zAssign27Neighbors(A,function);
    i=i+2;
    if (i%convergenceIterations == 0 && hasConverged!=null) {
      if (hasConverged.apply(A)) return i;
    }
  }
View Full Code Here

* Demonstrates advanced sorting.
* Sorts by sum of slice.
*/
public static void zdemo2() {
  Sorting sort = quickSort;
  DoubleMatrix3D matrix = DoubleFactory3D.dense.descending(4,3,2);
  DoubleMatrix2DComparator comp = new DoubleMatrix2DComparator() {
    public int compare(DoubleMatrix2D a, DoubleMatrix2D b) {
      double as = a.zSum();
      double bs = b.zSum();
      return as < bs ? -1 : as == bs ? 0 : 1;
View Full Code Here

  }
  DenseDoubleMatrix3D other = (DenseDoubleMatrix3D) source;
  if (other==this) return this;
  checkShape(other);
  if (haveSharedCells(other)) {
    DoubleMatrix3D c = other.copy();
    if (! (c instanceof DenseDoubleMatrix3D)) { // should not happen
      return super.assign(source);
    }
    other = (DenseDoubleMatrix3D) c;
  }
View Full Code Here

    public double apply(double a, double b) { return Math.PI*Math.log(b/a); }
   }
)
);

DoubleMatrix3D x = cern.colt.matrix.DoubleFactory3D.dense.ascending(2,2,2);
System.out.println(x);

// Sum( x[slice,row,col]*x[slice,row,col] )
System.out.println(x.aggregate(F.plus,F.square));
//--> 140


DoubleMatrix3D y = x.copy();
// Sum( (x[i]+y[i])^2 )
System.out.println(x.aggregate(y, F.plus, F.chain(F.square,F.plus)));
//--> 560

System.out.println(matrix.assign(F.random()));
View Full Code Here

TOP

Related Classes of cern.colt.matrix.DoubleMatrix3D

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.