Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix3D.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix3D.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix3D.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix3D.java Thu Sep 9 23:57:51 2010 @@ -23,28 +23,28 @@ package org.apache.mahout.math.matrix.im public abstract class AbstractMatrix3D extends AbstractMatrix { /** the number of slices this matrix (view) has */ - protected int slices; + private int slices; /** the number of rows this matrix (view) has */ - protected int rows; + private int rows; /** the number of columns this matrix (view) has */ - protected int columns; + private int columns; /** the number of elements between two slices, i.e. <tt>index(k+1,i,j) - index(k,i,j)</tt>. */ - protected int sliceStride; + private int sliceStride; /** the number of elements between two rows, i.e. <tt>index(k,i+1,j) - index(k,i,j)</tt>. */ - protected int rowStride; + private int rowStride; /** the number of elements between two columns, i.e. <tt>index(k,i,j+1) - index(k,i,j)</tt>. */ - protected int columnStride; + private int columnStride; /** the index of the first element */ - protected int sliceZero; - protected int rowZero; - protected int columnZero; + private int sliceZero; + private int rowZero; + private int columnZero; // this.isNoView implies: offset==0, sliceStride==rows*slices, rowStride==columns, columnStride==1 @@ -59,7 +59,7 @@ public abstract class AbstractMatrix3D e * @param absRank the absolute rank of the element. * @return the position. */ - protected int _columnOffset(int absRank) { + protected int columnOffset(int absRank) { return absRank; } @@ -69,7 +69,7 @@ public abstract class AbstractMatrix3D e * @param rank the relative rank of the element. * @return the absolute rank of the element. */ - protected int _columnRank(int rank) { + protected int columnRank(int rank) { return columnZero + rank * columnStride; } @@ -80,7 +80,7 @@ public abstract class AbstractMatrix3D e * @param absRank the absolute rank of the element. * @return the position. */ - protected int _rowOffset(int absRank) { + protected int rowOffset(int absRank) { return absRank; } @@ -90,7 +90,7 @@ public abstract class AbstractMatrix3D e * @param rank the relative rank of the element. * @return the absolute rank of the element. */ - protected int _rowRank(int rank) { + protected int rowRank(int rank) { return rowZero + rank * rowStride; } @@ -101,7 +101,7 @@ public abstract class AbstractMatrix3D e * @param absRank the absolute rank of the element. * @return the position. */ - protected int _sliceOffset(int absRank) { + protected int sliceOffset(int absRank) { return absRank; } @@ -111,7 +111,7 @@ public abstract class AbstractMatrix3D e * @param rank the relative rank of the element. * @return the absolute rank of the element. */ - protected int _sliceRank(int rank) { + protected int sliceRank(int rank) { return sliceZero + rank * sliceStride; } @@ -122,10 +122,10 @@ public abstract class AbstractMatrix3D e * slice+depth>slices || column<0 || width<0 || column+width>columns</tt> */ protected void checkBox(int slice, int row, int column, int depth, int height, int width) { - if (slice < 0 || depth < 0 || slice + depth > slices || row < 0 || height < 0 || row + height > rows || - column < 0 || width < 0 || column + width > columns) { - throw new IndexOutOfBoundsException("Slice:" + slice + ", row:" + row + " ,column:" + column + ", depth:" + depth + - " ,height:" + height + ", width:" + width); + if (slice < 0 || depth < 0 || slice + depth > slices || row < 0 || height < 0 || row + height > rows + || column < 0 || width < 0 || column + width > columns) { + throw new IndexOutOfBoundsException("Slice:" + slice + ", row:" + row + " ,column:" + column + ", depth:" + + depth + " ,height:" + height + ", width:" + width); } } @@ -198,8 +198,8 @@ public abstract class AbstractMatrix3D e * slices() != C.slices() || rows() != C.rows() || columns() != C.columns()</tt>. */ public void checkShape(AbstractMatrix3D B, AbstractMatrix3D C) { - if (slices != B.slices || rows != B.rows || columns != B.columns || slices != C.slices || rows != C.rows || - columns != C.columns) { + if (slices != B.slices || rows != B.rows || columns != B.columns || slices != C.slices || rows != C.rows + || columns != C.columns) { throw new IllegalArgumentException("Incompatible dimensions"); } } @@ -242,7 +242,7 @@ public abstract class AbstractMatrix3D e * @param column the index of the third-coordinate. */ protected int index(int slice, int row, int column) { - return _sliceOffset(_sliceRank(slice)) + _rowOffset(_rowRank(row)) + _columnOffset(_columnRank(column)); + return sliceOffset(sliceRank(slice)) + rowOffset(rowRank(row)) + columnOffset(columnRank(column)); } /** Returns the number of rows. */ @@ -338,8 +338,8 @@ public abstract class AbstractMatrix3D e */ protected AbstractMatrix3D vDice(int axis0, int axis1, int axis2) { int d = 3; - if (axis0 < 0 || axis0 >= d || axis1 < 0 || axis1 >= d || axis2 < 0 || axis2 >= d || - axis0 == axis1 || axis0 == axis2 || axis1 == axis2) { + if (axis0 < 0 || axis0 >= d || axis1 < 0 || axis1 >= d || axis2 < 0 || axis2 >= d + || axis0 == axis1 || axis0 == axis2 || axis1 == axis2) { throw new IllegalArgumentException("Illegal Axes: " + axis0 + ", " + axis1 + ", " + axis2); }
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java Thu Sep 9 23:57:51 2010 @@ -377,7 +377,8 @@ public class DenseDoubleMatrix2D extends */ @Override public double getQuick(int row, int column) { - //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column); + //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) + // throw new IndexOutOfBoundsException("row:"+row+", column:"+column); //return elements[index(row,column)]; //manually inlined: return elements[rowZero + row * rowStride + columnZero + column * columnStride]; @@ -472,7 +473,8 @@ public class DenseDoubleMatrix2D extends */ @Override public void setQuick(int row, int column, double value) { - //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column); + //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) + // throw new IndexOutOfBoundsException("row:"+row+", column:"+column); //elements[index(row,column)] = value; //manually inlined: elements[rowZero + row * rowStride + columnZero + column * columnStride] = value; @@ -511,13 +513,15 @@ public class DenseDoubleMatrix2D extends * * // 8 neighbors org.apache.mahout.math.function.Double9Function f = new Double9Function() { * public final double apply( double a00, double a01, double - * a02, double a10, double a11, double a12, double + * a02, double a10, double a11, double a12, + * double * a20, double a21, double a22) { return beta*a11 + * alpha*(a00+a01+a02 + a10+a12 + a20+a21+a22); } }; A.zAssign8Neighbors(B,f); * * // 4 neighbors org.apache.mahout.math.function.Double9Function g = new Double9Function() { * public final double apply( double a00, double a01, double - * a02, double a10, double a11, double a12, double + * a02, double a10, double a11, double a12, + * double * a20, double a21, double a22) { return beta*a11 + alpha*(a01+a10+a12+a21); * } C.zAssign8Neighbors(B,g); // fast, even though it doesn't look like it }; </pre> * @@ -647,10 +651,10 @@ public class DenseDoubleMatrix2D extends sum += AElems[i += As] * yElems[j += ys]; } for (int k = cols / 4; --k >= 0;) { - sum += AElems[i += As] * yElems[j += ys] + - AElems[i += As] * yElems[j += ys] + - AElems[i += As] * yElems[j += ys] + - AElems[i += As] * yElems[j += ys]; + sum += AElems[i += As] * yElems[j += ys] + + AElems[i += As] * yElems[j += ys] + + AElems[i += As] * yElems[j += ys] + + AElems[i += As] * yElems[j += ys]; } zElems[indexZ] = alpha * sum + beta * zElems[indexZ]; @@ -734,15 +738,15 @@ public class DenseDoubleMatrix2D extends --- ------- xxx xxxxxxx */ - int BLOCK_SIZE = 30000; // * 8 == Level 2 cache in bytes + int blockSize = 30000; // * 8 == Level 2 cache in bytes //if (n+p == 0) return C; //int m_optimal = (BLOCK_SIZE - n*p) / (n+p); - int m_optimal = (BLOCK_SIZE - n) / (n + 1); - if (m_optimal <= 0) { - m_optimal = 1; + int mOptimal = (blockSize - n) / (n + 1); + if (mOptimal <= 0) { + mOptimal = 1; } - int blocks = m / m_optimal; - if (m % m_optimal != 0) { + int blocks = m / mOptimal; + if (m % mOptimal != 0) { blocks++; } int rr = 0; @@ -750,15 +754,15 @@ public class DenseDoubleMatrix2D extends int jB = BB.index(0, 0); int indexA = index(rr, 0); int jC = CC.index(rr, 0); - rr += m_optimal; + rr += mOptimal; if (blocks == 0) { - m_optimal += m - rr; + mOptimal += m - rr; } for (int j = p; --j >= 0;) { int iA = indexA; int iC = jC; - for (int i = m_optimal; --i >= 0;) { + for (int i = mOptimal; --i >= 0;) { int kA = iA; int kB = jB; @@ -781,10 +785,10 @@ public class DenseDoubleMatrix2D extends s += AElems[kA += cA] * BElems[kB += rB]; } for (int k = n / 4; --k >= 0;) { - s += AElems[kA += cA] * BElems[kB += rB] + - AElems[kA += cA] * BElems[kB += rB] + - AElems[kA += cA] * BElems[kB += rB] + - AElems[kA += cA] * BElems[kB += rB]; + s += AElems[kA += cA] * BElems[kB += rB] + + AElems[kA += cA] * BElems[kB += rB] + + AElems[kA += cA] * BElems[kB += rB] + + AElems[kA += cA] * BElems[kB += rB]; } CElems[iC] = alpha * s + beta * CElems[iC]; Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java Thu Sep 9 23:57:51 2010 @@ -137,7 +137,8 @@ public class Algebra extends PersistentO /* int i=size; int a; - while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) throw new IndexOutOfBoundsException("invalid permutation"); + while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) + throw new IndexOutOfBoundsException("invalid permutation"); if (i<0) return; // nothing to permute */ @@ -214,7 +215,8 @@ public class Algebra extends PersistentO /* int i=size; int a; - while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) throw new IndexOutOfBoundsException("invalid permutation"); + while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) + throw new IndexOutOfBoundsException("invalid permutation"); if (i<0) return; // nothing to permute */ Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java Thu Sep 9 23:57:51 2010 @@ -13,11 +13,13 @@ import org.apache.mahout.math.matrix.Dou import org.apache.mahout.math.matrix.DoubleMatrix1D; import org.apache.mahout.math.matrix.DoubleMatrix2D; +import java.io.Serializable; + import static org.apache.mahout.math.matrix.linalg.Property.*; /** @deprecated until unit tests are in place. Until this time, this class/interface is unsupported. */ @Deprecated -public class EigenvalueDecomposition implements java.io.Serializable { +public class EigenvalueDecomposition implements Serializable { /** Row and column dimension (square matrix). */ private final int n; @@ -122,7 +124,7 @@ public class EigenvalueDecomposition imp D[i][i - 1] = e[i]; } } - return DoubleFactory2D.dense.make(D); + return DoubleFactory2D.DENSE.make(D); } /** @@ -149,7 +151,7 @@ public class EigenvalueDecomposition imp * @return <tt>V</tt> */ public DoubleMatrix2D getV() { - return DoubleFactory2D.dense.make(V); + return DoubleFactory2D.DENSE.make(V); } /** Nonsymmetric reduction from Hessenberg to real Schur form. */ @@ -351,9 +353,8 @@ public class EigenvalueDecomposition imp if (m == l) { break; } - if (Math.abs(H[m][m - 1]) * (Math.abs(q) + Math.abs(r)) < - eps * (Math.abs(p) * (Math.abs(H[m - 1][m - 1]) + Math.abs(z) + - Math.abs(H[m + 1][m + 1])))) { + if (Math.abs(H[m][m - 1]) * (Math.abs(q) + Math.abs(r)) + < eps * (Math.abs(p) * (Math.abs(H[m - 1][m - 1]) + Math.abs(z) + Math.abs(H[m + 1][m + 1])))) { break; } m--; @@ -369,11 +370,11 @@ public class EigenvalueDecomposition imp // Double QR step involving rows l:n and columns m:n for (int k = m; k <= n - 1; k++) { - boolean notlast = (k != n - 1); + boolean notlast = k != n - 1; if (k != m) { p = H[k][k - 1]; q = H[k + 1][k - 1]; - r = (notlast ? H[k + 2][k - 1] : 0.0); + r = notlast ? H[k + 2][k - 1] : 0.0; x = Math.abs(p) + Math.abs(q) + Math.abs(r); if (x != 0.0) { p /= x; @@ -546,8 +547,7 @@ public class EigenvalueDecomposition imp double vr = (d[i] - p) * (d[i] - p) + e[i] * e[i] - q * q; double vi = (d[i] - p) * 2.0 * q; if (vr == 0.0 && vi == 0.0) { - vr = eps * norm * (Math.abs(w) + Math.abs(q) + - Math.abs(x) + Math.abs(y) + Math.abs(z)); + vr = eps * norm * (Math.abs(w) + Math.abs(q) + Math.abs(x) + Math.abs(y) + Math.abs(z)); } cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi); H[i][n - 1] = cdivr; @@ -664,7 +664,7 @@ public class EigenvalueDecomposition imp for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { - V[i][j] = (i == j ? 1.0 : 0.0); + V[i][j] = i == j ? 1.0 : 0.0; } } @@ -707,32 +707,28 @@ public class EigenvalueDecomposition imp String unknown = "Illegal operation or error: "; try { buf.append(String.valueOf(this.getRealEigenvalues())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\nimagEigenvalues = "); try { buf.append(String.valueOf(this.getImagEigenvalues())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\nD = "); try { buf.append(String.valueOf(this.getD())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\nV = "); try { buf.append(String.valueOf(this.getV())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } @@ -930,7 +926,7 @@ public class EigenvalueDecomposition imp f = d[j]; g = e[j]; for (int k = j; k <= i - 1; k++) { - V[k][j] -= (f * e[k] + g * d[k]); + V[k][j] -= f * e[k] + g * d[k]; } d[j] = V[i - 1][j]; V[i][j] = 0.0; Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java Thu Sep 9 23:57:51 2010 @@ -646,7 +646,7 @@ public class LUDecompositionQuick implem } buf.append("\n\ninverse(A) = "); - DoubleMatrix2D identity = org.apache.mahout.math.matrix.DoubleFactory2D.dense.identity(lu.rows()); + DoubleMatrix2D identity = org.apache.mahout.math.matrix.DoubleFactory2D.DENSE.identity(lu.rows()); try { this.solve(identity); buf.append(String.valueOf(identity)); Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java Thu Sep 9 23:57:51 2010 @@ -396,7 +396,7 @@ public class Property extends Persistent public boolean isOrthogonal(DoubleMatrix2D a) { checkSquare(a); return equals(a.zMult(a, null, 1, 0, false, true), - DoubleFactory2D.dense.identity(a.rows())); + DoubleFactory2D.DENSE.identity(a.rows())); } /** A matrix <tt>A</tt> is <i>positive</i> if <tt>A[i,j] > 0</tt> holds for all cells. Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java (original) +++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java Thu Sep 9 23:57:51 2010 @@ -252,40 +252,35 @@ public class QRDecomposition implements String unknown = "Illegal operation or error: "; try { buf.append(String.valueOf(this.hasFullRank())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\nH = "); try { buf.append(String.valueOf(this.getH())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\nQ = "); try { buf.append(String.valueOf(this.getQ())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\nR = "); try { buf.append(String.valueOf(this.getR())); - } - catch (IllegalArgumentException exc) { + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } buf.append("\n\npseudo inverse(A) = "); try { - buf.append(String.valueOf(this.solve(DoubleFactory2D.dense.identity(QR.rows())))); - } - catch (IllegalArgumentException exc) { + buf.append(String.valueOf(this.solve(DoubleFactory2D.DENSE.identity(QR.rows())))); + } catch (IllegalArgumentException exc) { buf.append(unknown).append(exc.getMessage()); } Modified: mahout/trunk/utils/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java URL: http://svn.apache.org/viewvc/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java?rev=995610&r1=995609&r2=995610&view=diff ============================================================================== --- mahout/trunk/utils/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java (original) +++ mahout/trunk/utils/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java Thu Sep 9 23:57:51 2010 @@ -62,8 +62,7 @@ public final class SequenceFileDumper { withDescription("The number of chars of the asFormatString() to print").withShortName("b").create(); Option countOpt = obuilder.withLongName("count").withRequired(false). withDescription("Report the count only").withShortName("c").create(); - Option helpOpt = obuilder.withLongName("help"). - withDescription("Print out help").withShortName("h").create(); + Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h").create(); Group group = gbuilder.withName("Options").withOption(seqOpt).withOption(outputOpt) .withOption(substringOpt).withOption(countOpt).withOption(helpOpt).create(); @@ -100,8 +99,8 @@ public final class SequenceFileDumper { boolean countOnly = cmdLine.hasOption(countOpt); Writable key = reader.getKeyClass().asSubclass(Writable.class).newInstance(); Writable value = reader.getValueClass().asSubclass(Writable.class).newInstance(); - writer.append("Key class: ").append(String.valueOf(reader.getKeyClass())).append(" Value Class: ") - .append(String.valueOf(value.getClass())).append('\n'); + writer.append("Key class: ").append(String.valueOf(reader.getKeyClass())); + writer.append(" Value Class: ").append(String.valueOf(value.getClass())).append('\n'); writer.flush(); long count = 0; if (countOnly) {
