Examples of DoubleMatrix1D


Examples of cern.colt.matrix.DoubleMatrix1D

  testSort[0] = 5;
  testSort[1] = Double.NaN;
  testSort[2] = 2;
  testSort[3] = Double.NaN;
  testSort[4] = 1;
  DoubleMatrix1D doubleDense = new DenseDoubleMatrix1D(testSort);
  System.out.println("orig = "+doubleDense);
  doubleDense = doubleDense.viewSorted();
  doubleDense.toArray(testSort);
  System.out.println("sort = "+doubleDense);
  System.out.println("done\n");
}
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

System.out.println("\n"+master);
master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2
System.out.println("\n"+master);

int[] indexes = {0,1,3,0,1,2};
DoubleMatrix1D view1 = master.viewRow(0).viewSelection(indexes);
System.out.println("view1="+view1);
DoubleMatrix1D view2 = view1.viewPart(0,3);
System.out.println("view2="+view2);

view2.viewPart(0,2).assign(-1);
System.out.println("master replaced"+master);
System.out.println("flip1 replaced"+view1);
System.out.println("flip2 replaced"+view2);

View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

  //precompute and cache some views to avoid regenerating them time and again
  DoubleMatrix1D[] LUrows = new DoubleMatrix1D[m];
  for (int i = 0; i < m; i++) LUrows[i] = LU.viewRow(i);
 
  cern.colt.list.IntArrayList nonZeroIndexes = new cern.colt.list.IntArrayList(); // sparsity
  DoubleMatrix1D LUcolj = LU.viewColumn(0).like()// blocked column j
  cern.jet.math.Mult multFunction = cern.jet.math.Mult.mult(0);

  // Outer loop.
  for (int j = 0; j < n; j++) {
    // blocking (make copy of j-th column to localize references)
    LUcolj.assign(LU.viewColumn(j));
   
    // sparsity detection
    int maxCardinality = m/CUT_OFF; // == heuristic depending on speedup
    LUcolj.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    // Apply previous transformations.
    for (int i = 0; i < m; i++) {
      int kmax = Math.min(i,j);
      double s;
      if (sparse) {
        s = LUrows[i].zDotProduct(LUcolj,0,kmax,nonZeroIndexes);
      }
      else {
        s = LUrows[i].zDotProduct(LUcolj,0,kmax);
      }
      double before = LUcolj.getQuick(i);
      double after = before -s;
      LUcolj.setQuick(i, after); // LUcolj is a copy
      LU.setQuick(i,j, after);   // this is the original
      if (sparse) {
        if (before==0 && after!=0) { // nasty bug fixed!
          int pos = nonZeroIndexes.binarySearch(i);
          pos = -pos -1;
          nonZeroIndexes.beforeInsert(pos,i);
        }
        if (before!=0 && after==0) {
          nonZeroIndexes.remove(nonZeroIndexes.binarySearch(i));
        }
      }
    }
 
    // Find pivot and exchange if necessary.
    int p = j;
    if (p < m) {
      double max = Math.abs(LUcolj.getQuick(p));
      for (int i = j+1; i < m; i++) {
        double v = Math.abs(LUcolj.getQuick(i));
        if (v > max) {
          p = i;
          max = v;
        }
      }
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

  // transformations
  cern.jet.math.Mult     div       = cern.jet.math.Mult.div(0);
  cern.jet.math.PlusMult minusMult = cern.jet.math.PlusMult.minusMult(0);
 
  cern.colt.list.IntArrayList nonZeroIndexes = new cern.colt.list.IntArrayList(); // sparsity
  DoubleMatrix1D Browk = cern.colt.matrix.DoubleFactory1D.dense.make(nx); // blocked row k
 
  // Solve L*Y = B(piv,:)
  for (int k = 0; k < n; k++) {
    // blocking (make copy of k-th row to localize references)   
    Browk.assign(Brows[k]);
   
    // sparsity detection
    int maxCardinality = nx/CUT_OFF; // == heuristic depending on speedup
    Browk.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    for (int i = k+1; i < n; i++) {
      //for (int j = 0; j < nx; j++) B[i][j] -= B[k][j]*LU[i][k];
      //for (int j = 0; j < nx; j++) B.set(i,j, B.get(i,j) - B.get(k,j)*LU.get(i,k));
     
      minusMult.multiplicator = -LU.getQuick(i,k);
      if (minusMult.multiplicator != 0) {
        if (sparse) {
          Brows[i].assign(Browk,minusMult,nonZeroIndexes);
        }
        else {
          Brows[i].assign(Browk,minusMult);
        }
      }
    }
  }
 
  // Solve U*B = Y;
  for (int k = n-1; k >= 0; k--) {
    // for (int j = 0; j < nx; j++) B[k][j] /= LU[k][k];
    // for (int j = 0; j < nx; j++) B.set(k,j, B.get(k,j) / LU.get(k,k));
    div.multiplicator = 1 / LU.getQuick(k,k);
    Brows[k].assign(div);

    // blocking
    if (Browk==null) Browk = cern.colt.matrix.DoubleFactory1D.dense.make(B.columns());
    Browk.assign(Brows[k]);

    // sparsity detection
    int maxCardinality = nx/CUT_OFF; // == heuristic depending on speedup
    Browk.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    //Browk.getNonZeros(nonZeroIndexes,null);
    //boolean sparse = nonZeroIndexes.size() < nx/10;
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

public double dnrm2(DoubleMatrix1D x) {
  return Math.sqrt(Algebra.DEFAULT.norm2(x));
}
public void drot(DoubleMatrix1D x, DoubleMatrix1D y, double c, double s) {
  x.checkSize(y);
  DoubleMatrix1D tmp = x.copy();
 
  x.assign(F.mult(c));
  x.assign(y,F.plusMult(s));

  y.assign(F.mult(c));
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

  Property.DEFAULT.checkSquare(A);
  int size = A.rows();
  if (size != x.size() || size!=y.size()) {
    throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort() + ", " + y.toStringShort());
  }
  DoubleMatrix1D tmp = x.like();
  for (int i = 0; i < size; i++) {
    double sum = 0;
    for (int j = 0; j <= i; j++) {
      sum += A.getQuick(i,j) * x.getQuick(j);
    }
    for (int j = i + 1; j < size; j++) {
      sum += A.getQuick(j,i) * x.getQuick(j);
    }
    tmp.setQuick(i, alpha * sum + beta * y.getQuick(i));
  }
  y.assign(tmp);
}
 
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

  int size = A.rows();
  if (size != x.size()) {
    throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort());
  }
     
  DoubleMatrix1D b = x.like();
  DoubleMatrix1D y = x.like();
  if (isUnitTriangular) {
    y.assign(1);
  }
  else {
    for (int i = 0; i < size; i++) {
      y.setQuick(i, A.getQuick(i,i));
    }
  }
 
  for (int i = 0; i < size; i++) {
    double sum = 0;
    if (!isUpperTriangular) {
      for (int j = 0; j < i; j++) {
        sum += A.getQuick(i,j) * x.getQuick(j);
      }
      sum += y.getQuick(i) * x.getQuick(i);
    }
    else {
      sum += y.getQuick(i) * x.getQuick(i);
      for (int j = i + 1; j < size; j++) {
        sum += A.getQuick(i,j) * x.getQuick(j);      }
    }
    b.setQuick(i,sum);
  }
 
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

String[] formats =         {"%G", "%1.19G"};


// now the processing
int size = formats.length;
DoubleMatrix1D matrix = new DenseDoubleMatrix1D(values);

String[] strings = new String[size];
//String[] javaStrings = new String[size];

for (int i=0; i<size; i++) {
  String format = formats[i];
  strings[i] = new Formatter(format).toString(matrix);
  for (int j=0; j<matrix.size(); j++) {
    System.out.println(String.valueOf(matrix.get(j)));
  }
}

System.out.println("original:\n"+new Formatter().toString(matrix));
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

    final int offset = i*span;
    if (i==noOfTasks-1) span = width - span*i; // last span may be a bit larger

    // split A along rows into blocks
    final DoubleMatrix2D AA = A.viewPart(offset,0,span,n);
    final DoubleMatrix1D yy = y.viewPart(offset,span);
       
    subTasks[i] = new FJTask() {
      public void run() {
        seqBlas.dgemv(transposeA,alpha,AA,x,beta,yy);
        //System.out.println("Hello "+offset);
View Full Code Here

Examples of cern.colt.matrix.DoubleMatrix1D

  if (column < 0 || column >= matrix.columns()) throw new IndexOutOfBoundsException("column="+column+", matrix="+Formatter.shape(matrix));

  int[] rowIndexes = new int[matrix.rows()]; // row indexes to reorder instead of matrix itself
  for (int i=rowIndexes.length; --i >= 0; ) rowIndexes[i] = i;

  final DoubleMatrix1D col = matrix.viewColumn(column);
  IntComparator comp = new IntComparator() { 
    public int compare(int a, int b) {
      double av = col.getQuick(a);
      double bv = col.getQuick(b);
      if (av!=av || bv!=bv) return compareNaN(av,bv); // swap NaNs to the end
      return av<bv ? -1 : (av==bv ? 0 : 1);
    }
  };
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.