* 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, org.apache.mahout.math.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 += 2;
if (i % convergenceIterations == 0 && hasConverged != null) {
if (hasConverged.apply(A)) {
return i;
}