/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of slices, rows and columns as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != slices() || for any 0 <= slice < slices(): values[slice].length != rows()</tt>. * @throws IllegalArgumentException if <tt>for any 0 <= column < columns(): values[slice][row].length != columns()</tt>. */ public DoubleMatrix3D assign(double[][][] values) { if (values.length != slices) throw new IllegalArgumentException("Must have same number of slices: slices="+values.length+"slices()="+slices()); for (int slice=slices; --slice >= 0;) { double[][] currentSlice = values[slice]; if (currentSlice.length != rows) throw new IllegalArgumentException("Must have same number of rows in every slice: rows="+currentSlice.length+"rows()="+rows()); for (int row=rows; --row >= 0;) { double[] currentRow = currentSlice[row]; if (currentRow.length != columns) throw new IllegalArgumentException("Must have same number of columns in every row: columns="+currentRow.length+"columns()="+columns()); for (int column=columns; --column >= 0;) { setQuick(slice,row,column,currentRow[column]); } } } return this; } /**
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of slices, rows and columns as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != slices() || for any 0 <= slice < slices(): values[slice].length != rows()</tt>. * @throws IllegalArgumentException if <tt>for any 0 <= column < columns(): values[slice][row].length != columns()</tt>. */ public DoubleMatrix3D assign(double[][][] values) { if (values.length != slices) throw new IllegalArgumentException("Must have same number of slices: slices="+values.length+"slices()="+slices()); for (int slice=slices; --slice >= 0;) { double[][] currentSlice = values[slice]; if (currentSlice.length != rows) throw new IllegalArgumentException("Must have same number of rows in every slice: rows="+currentSlice.length+"rows()="+rows()); for (int row=rows; --row >= 0;) { double[] currentRow = currentSlice[row]; if (currentRow.length != columns) throw new IllegalArgumentException("Must have same number of columns in every row: columns="+currentRow.length+"columns()="+columns()); for (int column=columns; --column >= 0;) { setQuick(slice,row,column,currentRow[column]); } } } return this; } /**
int ncols = (int) Math.round(matrix.columns() * columnFraction); int max = Math.max(nslices,Math.max(nrows,ncols)); long[] selected = new long[max]; // sampler works on long's, not int's N = matrix.columns(); cern.jet.random.sampling.RandomSampler.sample(n,N,n,0,selected,0,randomGenerator); int[] selectedCols = new int[n];
int ncols = (int) Math.round(matrix.columns() * columnFraction); int max = Math.max(nslices,Math.max(nrows,ncols)); long[] selected = new long[max]; // sampler works on long's, not int's N = matrix.columns(); cern.jet.random.sampling.RandomSampler.sample(n,N,n,0,selected,0,randomGenerator); int[] selectedCols = new int[n];
/** * Returns whether all cells of the given matrix <tt>A</tt> are equal to the given value. * The result is <tt>true</tt> if and only if <tt>A != null</tt> and * <tt>! (Math.abs(value - A[slice,row,col]) > tolerance())</tt> holds for all coordinates. * @param A the first matrix to compare. * @param value the value to compare against. * @return <tt>true</tt> if the matrix is equal to the value; * <tt>false</tt> otherwise. */ public boolean equals(DoubleMatrix3D A, double value) { if (A==null) return false; int rows = A.rows(); int columns = A.columns(); double epsilon = tolerance(); for (int slice=A.slices(); --slice >= 0;) { for (int row=rows; --row >= 0;) { for (int column=columns; --column >= 0;) { //if (!(A.getQuick(slice,row,column) == value)) return false; //if (Math.abs(value - A.getQuick(slice,row,column)) > epsilon) return false; double x = A.getQuick(slice,row,column); double diff = Math.abs(value - x); if ((diff!=diff) && ((value!=value && x!=x) || value==x)) diff = 0; if (!(diff <= epsilon)) return false; } } } return true; } /**
/** * Returns whether all cells of the given matrix <tt>A</tt> are equal to the given value. * The result is <tt>true</tt> if and only if <tt>A != null</tt> and * <tt>! (Math.abs(value - A[slice,row,col]) > tolerance())</tt> holds for all coordinates. * @param A the first matrix to compare. * @param value the value to compare against. * @return <tt>true</tt> if the matrix is equal to the value; * <tt>false</tt> otherwise. */ public boolean equals(DoubleMatrix3D A, double value) { if (A==null) return false; int rows = A.rows(); int columns = A.columns(); double epsilon = tolerance(); for (int slice=A.slices(); --slice >= 0;) { for (int row=rows; --row >= 0;) { for (int column=columns; --column >= 0;) { //if (!(A.getQuick(slice,row,column) == value)) return false; //if (Math.abs(value - A.getQuick(slice,row,column)) > epsilon) return false; double x = A.getQuick(slice,row,column); double diff = Math.abs(value - x); if ((diff!=diff) && ((value!=value && x!=x) || value==x)) diff = 0; if (!(diff <= epsilon)) return false; } } } return true; } /**
if (column < 0 || column >= matrix.columns()) throw new IndexOutOfBoundsException("column="+column+", matrix="+Formatter.shape(matrix));
if (column < 0 || column >= matrix.columns()) throw new IndexOutOfBoundsException("column="+column+", matrix="+Formatter.shape(matrix));