Package cern.colt.matrix

Examples of cern.colt.matrix.DoubleMatrix1D


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

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

  final DoubleMatrix1D sliceView = matrix.viewRow(row).viewColumn(column);
  IntComparator comp = new IntComparator() { 
    public int compare(int a, int b) {
      double av = sliceView.getQuick(a);
      double bv = sliceView.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


* Sorts by sinus of cell values.
*/
public static void zdemo3() {
  Sorting sort = quickSort;
  double[] values = {0.5, 1.5, 2.5, 3.5};
  DoubleMatrix1D matrix = new DenseDoubleMatrix1D(values);
  cern.colt.function.DoubleComparator comp = new cern.colt.function.DoubleComparator() {
    public int compare(double a, double b) {
      double as = Math.sin(a); double bs = Math.sin(b);
      return as < bs ? -1 : as == bs ? 0 : 1;
    }
  };
  System.out.println("unsorted:"+matrix);
 
  DoubleMatrix1D sorted = sort.sort(matrix,comp);
  System.out.println("sorted  :"+sorted);

  // check whether it is really sorted
  sorted.assign(cern.jet.math.Functions.sin);
  /*
  sorted.assign(
    new cern.colt.function.DoubleFunction() {
      public double apply(double arg) { return Math.sin(arg); }
    }
View Full Code Here

* Demonstrates applying functions.
*/
protected static void zdemo4() {
  double[] values1 = {0, 1, 2, 3};
  double[] values2 = {0, 2, 4, 6};
  DoubleMatrix1D matrix1 = new DenseDoubleMatrix1D(values1);
  DoubleMatrix1D matrix2 = new DenseDoubleMatrix1D(values2);
  System.out.println("m1:"+matrix1);
  System.out.println("m2:"+matrix2);
 
  matrix1.assign(matrix2, cern.jet.math.Functions.pow);
 
View Full Code Here

      int tmp = g[b]; g[b] = g[c]; g[c] = tmp;
    }
  };
 
  // compare splitter[a] with columnView[rowIndexes[b]]
  final DoubleMatrix1D columnView = matrix.viewColumn(column)
  IntComparator comp = new IntComparator() {
    public int compare(int a, int b) {
      double av = splitters[a];
      double bv = columnView.getQuick(g[b]);
      return av<bv ? -1 : (av==bv ? 0 : 1);
    }
  };

  // compare columnView[rowIndexes[a]] with columnView[rowIndexes[b]]
  IntComparator comp2 = new IntComparator() {
    public int compare(int a, int b) {
      double av = columnView.getQuick(g[a]);
      double bv = columnView.getQuick(g[b]);
      return av<bv ? -1 : (av==bv ? 0 : 1);
    }
  };

  // compare splitter[a] with splitter[b]
View Full Code Here

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

import cern.colt.matrix.linalg.Algebra;

class NormInfinityTest {

  public static void main(String[] args) {
    DoubleMatrix1D x1 = DoubleFactory1D.dense
        .make(new double[] { 1.0, 2.0});
    DoubleMatrix1D x2 = DoubleFactory1D.dense
        .make(new double[] { 1.0, -2.0});
    DoubleMatrix1D x3 = DoubleFactory1D.dense.make(new double[] { -1.0, -2.0});

    System.out.println(Algebra.DEFAULT.normInfinity(x1));
    System.out.println(Algebra.DEFAULT.normInfinity(x2));
    System.out.println(Algebra.DEFAULT.normInfinity(x3));
  }
View Full Code Here

  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

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

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

  final DoubleMatrix1D sliceView = matrix.viewRow(row).viewColumn(column);
  IntComparator comp = new IntComparator() {
    public int compare(int a, int b) {
      double av = sliceView.getQuick(a);
      double bv = sliceView.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

* Sorts by sinus of cell values.
*/
public static void zdemo3() {
  Sorting sort = quickSort;
  double[] values = {0.5, 1.5, 2.5, 3.5};
  DoubleMatrix1D matrix = new DenseDoubleMatrix1D(values);
  cern.colt.function.DoubleComparator comp = new cern.colt.function.DoubleComparator() {
    public int compare(double a, double b) {
      double as = Math.sin(a); double bs = Math.sin(b);
      return as < bs ? -1 : as == bs ? 0 : 1;
    }
  };
  System.out.println("unsorted:"+matrix);

  DoubleMatrix1D sorted = sort.sort(matrix,comp);
  System.out.println("sorted  :"+sorted);

  // check whether it is really sorted
  sorted.assign(cern.jet.math.Functions.sin);
  /*
  sorted.assign(
    new cern.colt.function.DoubleFunction() {
      public double apply(double arg) { return Math.sin(arg); }
    }
View Full Code Here

* Demonstrates applying functions.
*/
protected static void zdemo4() {
  double[] values1 = {0, 1, 2, 3};
  double[] values2 = {0, 2, 4, 6};
  DoubleMatrix1D matrix1 = new DenseDoubleMatrix1D(values1);
  DoubleMatrix1D matrix2 = new DenseDoubleMatrix1D(values2);
  System.out.println("m1:"+matrix1);
  System.out.println("m2:"+matrix2);

  matrix1.assign(matrix2, cern.jet.math.Functions.pow);

View Full Code Here

TOP

Related Classes of cern.colt.matrix.DoubleMatrix1D

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.