Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 1562535) +++ CHANGES.txt (working copy) @@ -3,7 +3,8 @@ Release 0.7.0 (unreleased changes) NEW FEATURES - + + HAMA-864: Fix/improve DoubleVector and DenseDoubleVector (Yexi Jiang) HAMA-842: Add persistent queue option to JobConf (edwardyoon) HAMA-839: Support NullWritable in Hama Pipes (Martin Illecker) HAMA-837: Add sort behaviour to runtime partitioner (edwardyoon) Index: commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java =================================================================== --- commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java (revision 1562535) +++ commons/src/main/java/org/apache/hama/commons/math/DenseDoubleVector.java (working copy) @@ -127,36 +127,6 @@ /* * (non-Javadoc) - * @see de.jungblut.math.DoubleVector#apply(de.jungblut.math.function. - * DoubleVectorFunction) - */ - @Deprecated - @Override - public DoubleVector apply(DoubleVectorFunction func) { - DenseDoubleVector newV = new DenseDoubleVector(this.vector); - for (int i = 0; i < vector.length; i++) { - newV.vector[i] = func.calculate(i, vector[i]); - } - return newV; - } - - /* - * (non-Javadoc) - * @see de.jungblut.math.DoubleVector#apply(de.jungblut.math.DoubleVector, - * de.jungblut.math.function.DoubleDoubleVectorFunction) - */ - @Deprecated - @Override - public DoubleVector apply(DoubleVector other, DoubleDoubleVectorFunction func) { - DenseDoubleVector newV = (DenseDoubleVector) deepCopy(); - for (int i = 0; i < vector.length; i++) { - newV.vector[i] = func.calculate(i, vector[i], other.get(i)); - } - return newV; - } - - /* - * (non-Javadoc) * @see de.jungblut.math.DoubleVector#add(de.jungblut.math.DoubleVector) */ @Override Index: commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java =================================================================== --- commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java (revision 1562535) +++ commons/src/main/java/org/apache/hama/commons/math/DoubleVector.java (working copy) @@ -66,27 +66,6 @@ * @param func the function to apply. * @return a new vector with the applied function. */ - @Deprecated - public DoubleVector apply(DoubleVectorFunction func); - - /** - * Apply a given {@link DoubleDoubleVectorFunction} to this vector and the - * other given vector. - * - * @param other the other vector. - * @param func the function to apply on this and the other vector. - * @return a new vector with the result of the function of the two vectors. - */ - @Deprecated - public DoubleVector apply(DoubleVector other, DoubleDoubleVectorFunction func); - - /** - * Apply a given {@link DoubleVectorFunction} to this vector and return a new - * one. - * - * @param func the function to apply. - * @return a new vector with the applied function. - */ public DoubleVector applyToElements(DoubleFunction func); /** @@ -331,18 +310,22 @@ public Iterator iterate(); /** + * Return whether the vector is a sparse vector. * @return true if this instance is a sparse vector. Smarter and faster than * instanceof. */ public boolean isSparse(); /** + * Return whether the vector is a named vector. * @return true if this instance is a named vector.Smarter and faster than * instanceof. */ public boolean isNamed(); /** + * Get the name of the vector. + * * @return If this vector is a named instance, this will return its name. Or * null if this is not a named instance. * Index: commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java =================================================================== --- commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java (revision 1562535) +++ commons/src/main/java/org/apache/hama/commons/math/NamedDoubleVector.java (working copy) @@ -51,18 +51,6 @@ } @Override - @Deprecated - public DoubleVector apply(DoubleVectorFunction func) { - return vector.apply(func); - } - - @Override - @Deprecated - public DoubleVector apply(DoubleVector other, DoubleDoubleVectorFunction func) { - return vector.apply(other, func); - } - - @Override public DoubleVector applyToElements(DoubleFunction func) { return vector.applyToElements(func); } @@ -238,8 +226,9 @@ return name; } + @Override public String toString() { - return name + ": " + vector.toString(); + return String.format("%s: %s", name, vector.toArray()); } } Index: commons/src/main/java/org/apache/hama/commons/math/SquareVectorFunction.java =================================================================== --- commons/src/main/java/org/apache/hama/commons/math/SquareVectorFunction.java (revision 1562535) +++ commons/src/main/java/org/apache/hama/commons/math/SquareVectorFunction.java (working copy) @@ -17,12 +17,22 @@ */ package org.apache.hama.commons.math; -@SuppressWarnings("deprecation") -public class SquareVectorFunction implements DoubleVectorFunction { +public class SquareVectorFunction extends DoubleFunction { + /* (non-Javadoc) + * @see org.apache.hama.commons.math.DoubleFunction#apply(double) + */ @Override - public double calculate(int index, double value) { - return Math.pow(value, 2); + public double apply(double value) { + return value * value; } + /* (non-Javadoc) + * @see org.apache.hama.commons.math.DoubleFunction#applyDerivative(double) + */ + @Override + public double applyDerivative(double value) { + throw new UnsupportedOperationException(); + } + } Index: ml/src/main/java/org/apache/hama/ml/recommendation/cf/OnlineCF.java =================================================================== --- ml/src/main/java/org/apache/hama/ml/recommendation/cf/OnlineCF.java (revision 1562535) +++ ml/src/main/java/org/apache/hama/ml/recommendation/cf/OnlineCF.java (working copy) @@ -473,7 +473,7 @@ // Euclidean distance return Math.pow( usr1Vector .subtract(usr2Vector) - .apply(new SquareVectorFunction()) + .applyToElements(new SquareVectorFunction()) .sum() , 0.5); } @@ -514,7 +514,7 @@ // Euclidean distance return Math.pow( itm1Vector .subtract(itm2Vector) - .apply(new SquareVectorFunction()) + .applyToElements(new SquareVectorFunction()) .sum() , 0.5); }