/** 27 point stencil operation. Applies a function to a moving <tt>3 x 3 x 3</tt> window. @param A the matrix to operate on. @param function the function to be applied to each window. @param maxIterations the maximum number of times the stencil shall be applied to the matrix. Should be a multiple of 2 because two iterations are always done in one atomic step. @param hasConverged Convergence condition; will return before maxIterations are done when <tt>hasConverged.apply(A)==true</tt>. Set this parameter to <tt>null</tt> to indicate that no convergence checks shall be made. @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; } } return i; } /**
/** 27 point stencil operation. Applies a function to a moving <tt>3 x 3 x 3</tt> window. @param A the matrix to operate on. @param function the function to be applied to each window. @param maxIterations the maximum number of times the stencil shall be applied to the matrix. Should be a multiple of 2 because two iterations are always done in one atomic step. @param hasConverged Convergence condition; will return before maxIterations are done when <tt>hasConverged.apply(A)==true</tt>. Set this parameter to <tt>null</tt> to indicate that no convergence checks shall be made. @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; } } return i; } /**
/** * Replaces all cell values of the receiver with the values of another matrix. * Both matrices must have the same number of slices, rows and columns. * If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>. * * @param other the source matrix to copy from (may be identical to the receiver). * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>slices() != other.slices() || rows() != other.rows() || columns() != other.columns()</tt> */ public DoubleMatrix3D assign(DoubleMatrix3D other) { if (other==this) return this; checkShape(other); if (haveSharedCells(other)) other = other.copy(); for (int slice=slices; --slice >= 0;) { for (int row=rows; --row >= 0;) { for (int column=columns; --column >= 0;) { setQuick(slice,row,column,other.getQuick(slice,row,column)); } } } return this; } /**
/** * Replaces all cell values of the receiver with the values of another matrix. * Both matrices must have the same number of slices, rows and columns. * If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>. * * @param other the source matrix to copy from (may be identical to the receiver). * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>slices() != other.slices() || rows() != other.rows() || columns() != other.columns()</tt> */ public DoubleMatrix3D assign(DoubleMatrix3D other) { if (other==this) return this; checkShape(other); if (haveSharedCells(other)) other = other.copy(); for (int slice=slices; --slice >= 0;) { for (int row=rows; --row >= 0;) { for (int column=columns; --column >= 0;) { setQuick(slice,row,column,other.getQuick(slice,row,column)); } } } return this; } /**
DoubleMatrix3D y = x.copy();
DoubleMatrix3D y = x.copy();