mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jman...@apache.org
Subject svn commit: r1486122 [1/2] - in /mahout/trunk: core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ core/src/main/java/org...
Date Fri, 24 May 2013 17:11:23 GMT
Author: jmannix
Date: Fri May 24 17:11:20 2013
New Revision: 1486122

URL: http://svn.apache.org/r1486122
Log:
Removes Iterable and iterateNonZero() from Vector interface, replaces with two Iterable-returning methods fixes MAHOUT-1227

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ALS.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/PredictionMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorSplitterMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ToItemVectorsMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/discriminative/WinnowTrainer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/AbstractNaiveBayesClassifier.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/test/TestNaiveBayesDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/ComplementaryThetaTrainer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/StandardThetaTrainer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/AbstractOnlineLogisticRegression.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelDissector.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/CIMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/ClusterIterator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/cvb/TopicModel.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/minhash/MinHashMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/UnitVectorizerJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorMatrixMultiplicationJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsAffinityCutsJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsDriver.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedEuclideanDistanceMeasure.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedManhattanDistanceMeasure.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/mapreduce/TransposeMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/VectorWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TransposeJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/RowSimilarityJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/Vectors.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/EuclideanDistanceSimilarity.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/PearsonCorrelationSimilarity.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtDenseOutJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/Omega.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangular.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/YtYJob.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/qr/QRFirstStep.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/neighborhood/HashedVector.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/stats/GlobalOnlineAuc.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/pruner/WordsPrunerReducer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TermDocumentCountMapper.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFPartialVectorReducer.java
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJobTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/ALSWRFactorizerTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/naivebayes/NaiveBayesTestBase.java
    mahout/trunk/core/src/test/java/org/apache/mahout/classifier/sgd/AdaptiveLogisticRegressionTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/minhash/TestMinHashClustering.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/spectral/common/TestAffinityMatrixInputJob.java
    mahout/trunk/core/src/test/java/org/apache/mahout/clustering/spectral/eigencuts/TestEigencutsAffinityCutsJob.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/MathHelper.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverDenseTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/stochasticsvd/LocalSSVDSolverSparseSequentialTest.java
    mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/encoders/WordLikeValueEncoderTest.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/minhash/LastfmClusterEvaluator.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/cdbw/CDbwEvaluator.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/evaluation/ClusterEvaluator.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/AbstractClusterWriter.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorHelper.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/DelegatingVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/NamedVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/PermutedVectorView.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/Vector.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorBinaryAggregate.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorBinaryAssign.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/VectorView.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/WeightedVectorComparator.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/als/AlternatingLeastSquaresSolver.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractVectorTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/solver/EigenDecompositionTest.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ALS.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ALS.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ALS.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ALS.java Fri May 24 17:11:20 2013
@@ -116,9 +116,8 @@ final class ALS {
     Vector ratings = ratingsWritable.get();
 
     List<Vector> featureVectors = Lists.newArrayListWithCapacity(ratings.getNumNondefaultElements());
-    Iterator<Vector.Element> interactions = ratings.iterateNonZero();
-    while (interactions.hasNext()) {
-      int index = interactions.next().index();
+    for (Vector.Element e : ratings.nonZeroes()) {
+      int index = e.index();
       featureVectors.add(uOrM.get(index));
     }
 

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/ParallelALSFactorizationJob.java Fri May 24 17:11:20 2013
@@ -50,12 +50,10 @@ import org.apache.mahout.math.RandomAcce
 import org.apache.mahout.math.SequentialAccessSparseVector;
 import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.VectorWritable;
-import org.apache.mahout.math.function.Functions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
@@ -206,9 +204,7 @@ public class ParallelALSFactorizationJob
       IntWritable index = new IntWritable();
       VectorWritable featureVector = new VectorWritable();
 
-      Iterator<Vector.Element> averages = averageRatings.iterateNonZero();
-      while (averages.hasNext()) {
-        Vector.Element e = averages.next();
+      for (Vector.Element e : averageRatings.nonZeroes()) {
         Vector row = new DenseVector(numFeatures);
         row.setQuick(0, e.get());
         for (int m = 1; m < numFeatures; m++) {
@@ -345,9 +341,8 @@ public class ParallelALSFactorizationJob
     @Override
     protected void map(IntWritable r, VectorWritable v, Context ctx) throws IOException, InterruptedException {
       RunningAverage avg = new FullRunningAverage();
-      Iterator<Vector.Element> elements = v.get().iterateNonZero();
-      while (elements.hasNext()) {
-        avg.addDatum(elements.next().get());
+      for (Vector.Element e : v.get().nonZeroes()) {
+        avg.addDatum(e.get());
       }
 
       featureVector.setQuick(r.get(), avg.getAverage());

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/PredictionMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/PredictionMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/PredictionMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/als/PredictionMapper.java Fri May 24 17:11:20 2013
@@ -31,7 +31,6 @@ import org.apache.mahout.math.map.OpenIn
 import org.apache.mahout.math.set.OpenIntHashSet;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -76,9 +75,8 @@ public class PredictionMapper extends Sh
     final int userID = userIDWritable.get();
     final OpenIntHashSet alreadyRatedItems = new OpenIntHashSet(ratings.getNumNondefaultElements());
 
-    Iterator<Vector.Element> ratingsIterator = ratings.iterateNonZero();
-    while (ratingsIterator.hasNext()) {
-      alreadyRatedItems.add(ratingsIterator.next().index());
+    for (Vector.Element e : ratings.nonZeroes()) {
+      alreadyRatedItems.add(e.index());
     }
 
     final TopItemsQueue topItemsQueue = new TopItemsQueue(recommendationsPerUser);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java Fri May 24 17:11:20 2013
@@ -31,6 +31,7 @@ import org.apache.mahout.common.iterator
 import org.apache.mahout.math.RandomAccessSparseVector;
 import org.apache.mahout.math.VarLongWritable;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.map.OpenIntLongHashMap;
 
@@ -129,9 +130,8 @@ public final class AggregateAndRecommend
       Vector simColumn = prefAndSimilarityColumn.getSimilarityColumn();
       float prefValue = prefAndSimilarityColumn.getPrefValue();
       /* count the number of items used for each prediction */
-      Iterator<Vector.Element> usedItemsIterator = simColumn.iterateNonZero();
-      while (usedItemsIterator.hasNext()) {
-        int itemIDIndex = usedItemsIterator.next().index();
+      for (Element e : simColumn.nonZeroes()) {
+        int itemIDIndex = e.index();
         numberOfSimilarItemsUsed.setQuick(itemIDIndex, numberOfSimilarItemsUsed.getQuick(itemIDIndex) + 1);
       }
 
@@ -160,9 +160,7 @@ public final class AggregateAndRecommend
     }
 
     Vector recommendationVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
-    Iterator<Vector.Element> iterator = numerators.iterateNonZero();
-    while (iterator.hasNext()) {
-      Vector.Element element = iterator.next();
+    for (Element element : numerators.nonZeroes()) {
       int itemIDIndex = element.index();
       /* preference estimations must be based on at least 2 datapoints */
       if (numberOfSimilarItemsUsed.getQuick(itemIDIndex) > 1) {
@@ -182,9 +180,7 @@ public final class AggregateAndRecommend
 
     TopItemsQueue topKItems = new TopItemsQueue(recommendationsPerUser);
 
-    Iterator<Vector.Element> recommendationVectorIterator = recommendationVector.iterateNonZero();
-    while (recommendationVectorIterator.hasNext()) {
-      Vector.Element element = recommendationVectorIterator.next();
+    for (Element element : recommendationVector.nonZeroes()) {
       int index = element.index();
       long itemID;
       if (indexItemIDMap != null && !indexItemIDMap.isEmpty()) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorSplitterMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorSplitterMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorSplitterMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorSplitterMapper.java Fri May 24 17:11:20 2013
@@ -29,10 +29,10 @@ import org.apache.mahout.common.iterator
 import org.apache.mahout.math.VarIntWritable;
 import org.apache.mahout.math.VarLongWritable;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -84,11 +84,9 @@ public final class UserVectorSplitterMap
       return;
     }
     Vector userVector = maybePruneUserVector(value.get());
-    Iterator<Vector.Element> it = userVector.iterateNonZero();
     VarIntWritable itemIndexWritable = new VarIntWritable();
     VectorOrPrefWritable vectorOrPref = new VectorOrPrefWritable();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : userVector.nonZeroes()) {
       itemIndexWritable.set(e.index());
       vectorOrPref.set(userID, (float) e.get());
       context.write(itemIndexWritable, vectorOrPref);
@@ -105,9 +103,7 @@ public final class UserVectorSplitterMap
     // "Blank out" small-sized prefs to reduce the amount of partial products
     // generated later. They're not zeroed, but NaN-ed, so they come through
     // and can be used to exclude these items from prefs.
-    Iterator<Vector.Element> it = userVector.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : userVector.nonZeroes()) {
       float absValue = Math.abs((float) e.get());
       if (absValue < smallestLargeValue) {
         e.set(Float.NaN);
@@ -126,9 +122,8 @@ public final class UserVectorSplitterMap
       }
     };
 
-    Iterator<Vector.Element> it = userVector.iterateNonZero();
-    while (it.hasNext()) {
-      float absValue = Math.abs((float) it.next().get());
+    for (Element e : userVector.nonZeroes()) {
+      float absValue = Math.abs((float) e.get());
       topPrefValues.insertWithOverflow(absValue);
     }
     return topPrefValues.top();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ToItemVectorsMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ToItemVectorsMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ToItemVectorsMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/preparation/ToItemVectorsMapper.java Fri May 24 17:11:20 2013
@@ -27,7 +27,6 @@ import org.apache.mahout.math.VectorWrit
 import org.apache.mahout.math.hadoop.similarity.cooccurrence.Vectors;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 public class ToItemVectorsMapper
     extends Mapper<VarLongWritable,VectorWritable,IntWritable,VectorWritable> {
@@ -58,9 +57,7 @@ public class ToItemVectorsMapper
     VectorWritable itemVector = new VectorWritable(new RandomAccessSparseVector(Integer.MAX_VALUE, 1));
     itemVector.setWritesLaxPrecision(true);
 
-    Iterator<Vector.Element> iterator = userRatings.iterateNonZero();
-    while (iterator.hasNext()) {
-      Vector.Element elem = iterator.next();
+    for (Vector.Element elem : userRatings.nonZeroes()) {
       itemVector.get().setQuick(column, elem.get());
       ctx.write(new IntWritable(elem.index()), itemVector);
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java Fri May 24 17:11:20 2013
@@ -18,7 +18,6 @@
 package org.apache.mahout.cf.taste.hadoop.similarity.item;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -198,10 +197,7 @@ public final class ItemSimilarityJob ext
 
       TopSimilarItemsQueue topKMostSimilarItems = new TopSimilarItemsQueue(maxSimilarItemsPerItem);
 
-      Iterator<Vector.Element> similarityVectorIterator = similarityVector.get().iterateNonZero();
-
-      while (similarityVectorIterator.hasNext()) {
-        Vector.Element element = similarityVectorIterator.next();
+      for (Vector.Element element : similarityVector.get().nonZeroes()) {
         SimilarItem top = topKMostSimilarItems.top();
         double candidateSimilarity = element.get();
         if (candidateSimilarity > top.getSimilarity()) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/discriminative/WinnowTrainer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/discriminative/WinnowTrainer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/discriminative/WinnowTrainer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/discriminative/WinnowTrainer.java Fri May 24 17:11:20 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.mahout.classifier.discriminative;
 
-import java.util.Iterator;
-
 import org.apache.mahout.math.Vector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,13 +52,15 @@ public class WinnowTrainer extends Linea
   /**
    * {@inheritDoc} Winnow update works such that in case the predicted label
    * does not match the real label, the weight vector is updated as follows: In
-   * case the prediction was positiv but should have been negative, all entries
+   * case the prediction was positive but should have been negative, all entries
    * in the weight vector that correspond to non null features in the example
    * are doubled.
    * 
    * In case the prediction was negative but should have been positive, all
    * entries in the weight vector that correspond to non null features in the
-   * example are halfed.
+   * example are halved.
+   *
+   * NOTE: case 1 and case 2 below look _exactly_ the same.  Is this broken?
    */
   @Override
   protected void update(double label, Vector dataPoint, LinearModel model) {
@@ -68,9 +68,7 @@ public class WinnowTrainer extends Linea
       // case one
       Vector updateVector = dataPoint.times(1 / this.promotionStep);
       log.info("Winnow update positive: {}", updateVector);
-      Iterator<Vector.Element> iter = updateVector.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element element = iter.next();
+      for (Vector.Element element : updateVector.nonZeroes()) {
         if (element.get() != 0) {
           model.timesDelta(element.index(), element.get());
         }
@@ -79,9 +77,7 @@ public class WinnowTrainer extends Linea
       // case two
       Vector updateVector = dataPoint.times(1 / this.promotionStep);
       log.info("Winnow update negative: {}", updateVector);
-      Iterator<Vector.Element> iter = updateVector.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element element = iter.next();
+      for (Vector.Element element : updateVector.nonZeroes()) {
         if (element.get() != 0) {
           model.timesDelta(element.index(), element.get());
         }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/AbstractNaiveBayesClassifier.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/AbstractNaiveBayesClassifier.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/AbstractNaiveBayesClassifier.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/AbstractNaiveBayesClassifier.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.classifier.naivebayes;
 
-import java.util.Iterator;
-
 import org.apache.mahout.classifier.AbstractVectorClassifier;
 import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.Vector.Element;
@@ -46,9 +44,7 @@ public abstract class AbstractNaiveBayes
 
   protected double getScoreForLabelInstance(int label, Vector instance) {
     double result = 0.0;
-    Iterator<Element> elements = instance.iterateNonZero();
-    while (elements.hasNext()) {
-      Element e = elements.next();
+    for (Element e : instance.nonZeroes()) {
       result += e.get() * getScoreForLabelFeature(label, e.index());
     }
     return result;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/test/TestNaiveBayesDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/test/TestNaiveBayesDriver.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/test/TestNaiveBayesDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/test/TestNaiveBayesDriver.java Fri May 24 17:11:20 2013
@@ -147,7 +147,7 @@ public class TestNaiveBayesDriver extend
     for (Pair<Text, VectorWritable> pair : dirIterable) {
       int bestIdx = Integer.MIN_VALUE;
       double bestScore = Long.MIN_VALUE;
-      for (Vector.Element element : pair.getSecond().get()) {
+      for (Vector.Element element : pair.getSecond().get().all()) {
         if (element.get() > bestScore) {
           bestScore = element.get();
           bestIdx = element.index();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/ComplementaryThetaTrainer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/ComplementaryThetaTrainer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/ComplementaryThetaTrainer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/ComplementaryThetaTrainer.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.classifier.naivebayes.training;
 
-import java.util.Iterator;
-
 import org.apache.mahout.classifier.naivebayes.ComplementaryNaiveBayesClassifier;
 import org.apache.mahout.math.Vector;
 
@@ -31,9 +29,7 @@ public class ComplementaryThetaTrainer e
   @Override
   public void train(int label, Vector perLabelWeight) {
     double labelWeight = labelWeight(label);
-    Iterator<Vector.Element> it = perLabelWeight.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Vector.Element e : perLabelWeight.nonZeroes()) {
       updatePerLabelThetaNormalizer(label,
           ComplementaryNaiveBayesClassifier.computeWeight(featureWeight(e.index()), e.get(),
               totalWeightSum(), labelWeight, alphaI(), numFeatures()));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/StandardThetaTrainer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/StandardThetaTrainer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/StandardThetaTrainer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/training/StandardThetaTrainer.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.classifier.naivebayes.training;
 
-import java.util.Iterator;
-
 import org.apache.mahout.classifier.naivebayes.StandardNaiveBayesClassifier;
 import org.apache.mahout.math.Vector;
 
@@ -31,9 +29,7 @@ public class StandardThetaTrainer extend
   @Override
   public void train(int label, Vector perLabelWeight) {
     double labelWeight = labelWeight(label);
-    Iterator<Vector.Element> it = perLabelWeight.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Vector.Element e : perLabelWeight.nonZeroes()) {
       updatePerLabelThetaNormalizer(label,
           StandardNaiveBayesClassifier.computeWeight(e.get(), labelWeight, alphaI(), numFeatures()));
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/AbstractOnlineLogisticRegression.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/AbstractOnlineLogisticRegression.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/AbstractOnlineLogisticRegression.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/AbstractOnlineLogisticRegression.java Fri May 24 17:11:20 2013
@@ -17,13 +17,12 @@
 
 package org.apache.mahout.classifier.sgd;
 
-import java.util.Iterator;
-
 import org.apache.mahout.classifier.AbstractVectorClassifier;
 import org.apache.mahout.classifier.OnlineLearner;
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Matrix;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.function.DoubleFunction;
 import org.apache.mahout.math.function.Functions;
 
@@ -170,9 +169,7 @@ public abstract class AbstractOnlineLogi
       double gradientBase = gradient.get(i);
 
       // then we apply the gradientBase to the resulting element.
-      Iterator<Vector.Element> nonZeros = instance.iterateNonZero();
-      while (nonZeros.hasNext()) {
-        Vector.Element updateLocation = nonZeros.next();
+      for (Element updateLocation : instance.nonZeroes()) {
         int j = updateLocation.index();
 
         double newValue = beta.getQuick(i, j) + gradientBase * learningRate * perTermLearningRate(j) * instance.get(j);
@@ -181,9 +178,7 @@ public abstract class AbstractOnlineLogi
     }
 
     // remember that these elements got updated
-    Iterator<Vector.Element> i = instance.iterateNonZero();
-    while (i.hasNext()) {
-      Vector.Element element = i.next();
+    for (Element element : instance.nonZeroes()) {
       int j = element.index();
       updateSteps.setQuick(j, getStep());
       updateCounts.incrementQuick(j, 1);
@@ -212,9 +207,7 @@ public abstract class AbstractOnlineLogi
 
     // here we lazily apply the prior to make up for our neglect
     for (int i = 0; i < numCategories - 1; i++) {
-      Iterator<Vector.Element> nonZeros = instance.iterateNonZero();
-      while (nonZeros.hasNext()) {
-        Vector.Element updateLocation = nonZeros.next();
+      for (Element updateLocation : instance.nonZeroes()) {
         int j = updateLocation.index();
         double missingUpdates = getStep() - updateSteps.get(j);
         if (missingUpdates > 0) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelDissector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelDissector.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelDissector.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sgd/ModelDissector.java Fri May 24 17:11:20 2013
@@ -171,7 +171,7 @@ public class ModelDissector {
       this.feature = feature;
       // pick out the weight with the largest abs value, but don't forget the sign
       Queue<Category> biggest = new PriorityQueue<Category>(n + 1, Ordering.natural());
-      for (Vector.Element element : weights) {
+      for (Vector.Element element : weights.all()) {
         biggest.add(new Category(element.index(), element.get()));
         while (biggest.size() > n) {
           biggest.poll();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/AbstractCluster.java Fri May 24 17:11:20 2013
@@ -22,7 +22,6 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.Locale;
 
 import org.apache.hadoop.conf.Configuration;
@@ -31,6 +30,7 @@ import org.apache.mahout.math.NamedVecto
 import org.apache.mahout.math.RandomAccessSparseVector;
 import org.apache.mahout.math.SequentialAccessSparseVector;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.SquareRootFunction;
@@ -325,9 +325,7 @@ public abstract class AbstractCluster im
     Vector provider = v.isSequentialAccess() ? v : new SequentialAccessSparseVector(v);
 
     buffer.append('[');
-    Iterator<Vector.Element> elements = provider.iterateNonZero();
-    while (elements.hasNext()) {
-      Vector.Element elem = elements.next();
+    for (Element elem : provider.nonZeroes()) {
 
       if (hasBindings && bindings.length >= elem.index() + 1 && bindings[elem.index()] != null) {
         buffer.append(bindings[elem.index()]).append(':');

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationDriver.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationDriver.java Fri May 24 17:11:20 2013
@@ -216,9 +216,7 @@ public final class ClusterClassification
   
   private static void writeAllAboveThreshold(List<Cluster> clusterModels, Double clusterClassificationThreshold,
       SequenceFile.Writer writer, VectorWritable vw, Vector pdfPerCluster) throws IOException {
-    Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
-    while (iterateNonZero.hasNext()) {
-      Element pdf = iterateNonZero.next();
+    for (Element pdf : pdfPerCluster.nonZeroes()) {
       if (pdf.get() >= clusterClassificationThreshold) {
         WeightedVectorWritable wvw = new WeightedVectorWritable(pdf.get(), vw.get());
         int clusterIndex = pdf.index();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/classify/ClusterClassificationMapper.java Fri May 24 17:11:20 2013
@@ -94,9 +94,7 @@ public class ClusterClassificationMapper
   
   private void writeAllAboveThreshold(VectorWritable vw, Context context,
       Vector pdfPerCluster) throws IOException, InterruptedException {
-    Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
-    while (iterateNonZero.hasNext()) {
-      Element pdf = iterateNonZero.next();
+    for (Element pdf : pdfPerCluster.nonZeroes()) {
       if (pdf.get() >= threshold) {
         int clusterIndex = pdf.index();
         write(vw, context, clusterIndex, pdf.get());

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/dirichlet/models/GaussianCluster.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.clustering.dirichlet.models;
 
-import java.util.Iterator;
-
 import org.apache.mahout.clustering.AbstractCluster;
 import org.apache.mahout.clustering.Model;
 import org.apache.mahout.clustering.dirichlet.UncommonDistributions;
@@ -63,8 +61,7 @@ public class GaussianCluster extends Abs
    */
   private void computeProd2piR() {
     zProd2piR = 1.0;
-    for (Iterator<Element> it = getRadius().iterateNonZero(); it.hasNext();) {
-      Element radius = it.next();
+    for (Element radius : getRadius().nonZeroes()) {
       zProd2piR *= radius.get() * UncommonDistributions.SQRT2PI;
     }
   }
@@ -81,8 +78,7 @@ public class GaussianCluster extends Abs
    */
   private double sumXminusCdivRsquared(Vector x) {
     double result = 0;
-    for (Iterator<Element> it = getRadius().iterateNonZero(); it.hasNext();) {
-      Element radiusElem = it.next();
+    for (Element radiusElem : getRadius().nonZeroes()) {
       int index = radiusElem.index();
       double quotient = (x.get(index) - getCenter().get(index))
           / radiusElem.get();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/CIMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/CIMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/CIMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/CIMapper.java Fri May 24 17:11:20 2013
@@ -1,7 +1,6 @@
 package org.apache.mahout.clustering.iterator;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
@@ -36,8 +35,7 @@ public class CIMapper extends Mapper<Wri
       InterruptedException {
     Vector probabilities = classifier.classify(value.get());
     Vector selections = policy.select(probabilities);
-    for (Iterator<Element> it = selections.iterateNonZero(); it.hasNext();) {
-      Element el = it.next();
+    for (Element el : selections.nonZeroes()) {
       classifier.train(el.index(), value.get(), el.get());
     }
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/ClusterIterator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/ClusterIterator.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/ClusterIterator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/iterator/ClusterIterator.java Fri May 24 17:11:20 2013
@@ -17,7 +17,6 @@
 package org.apache.mahout.clustering.iterator;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
@@ -76,8 +75,8 @@ public final class ClusterIterator {
         // policy selects weights for models given those probabilities
         Vector weights = policy.select(probabilities);
         // training causes all models to observe data
-        for (Iterator<Vector.Element> it = weights.iterateNonZero(); it.hasNext();) {
-          int index = it.next().index();
+        for (Vector.Element e : weights.nonZeroes()) {
+          int index = e.index();
           classifier.train(index, vector, weights.get(index));
         }
       }
@@ -117,8 +116,8 @@ public final class ClusterIterator {
         // policy selects weights for models given those probabilities
         Vector weights = classifier.getPolicy().select(probabilities);
         // training causes all models to observe data
-        for (Iterator<Vector.Element> it = weights.iterateNonZero(); it.hasNext();) {
-          int index = it.next().index();
+        for (Vector.Element e : weights.nonZeroes()) {
+          int index = e.index();
           classifier.train(index, vector, weights.get(index));
         }
       }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/cvb/TopicModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/cvb/TopicModel.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/cvb/TopicModel.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/cvb/TopicModel.java Fri May 24 17:11:20 2013
@@ -32,6 +32,7 @@ import org.apache.mahout.math.Matrix;
 import org.apache.mahout.math.MatrixSlice;
 import org.apache.mahout.math.SequentialAccessSparseVector;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.stats.Sampler;
@@ -268,9 +269,7 @@ public class TopicModel implements Confi
     normalizeByTopic(docTopicModel);
     // now multiply, term-by-term, by the document, to get the weighted distribution of
     // term-topic pairs from this document.
-    Iterator<Vector.Element> it = original.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : original.nonZeroes()) {
       for (int x = 0; x < numTopics; x++) {
         Vector docTopicModelRow = docTopicModel.viewRow(x);
         docTopicModelRow.setQuick(e.index(), docTopicModelRow.getQuick(e.index()) * e.get());
@@ -287,9 +286,7 @@ public class TopicModel implements Confi
 
   public Vector infer(Vector original, Vector docTopics) {
     Vector pTerm = original.like();
-    Iterator<Vector.Element> it = original.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : original.nonZeroes()) {
       int term = e.index();
       // p(a) = sum_x (p(a|x) * p(x|i))
       double pA = 0;
@@ -351,9 +348,7 @@ public class TopicModel implements Confi
       Vector termTopicRow = termTopicDist.viewRow(x);
 
       // for each term a in document i with non-zero weight
-      Iterator<Vector.Element> it = document.iterateNonZero();
-      while (it.hasNext()) {
-        Vector.Element e = it.next();
+      for (Element e : document.nonZeroes()) {
         int termIndex = e.index();
 
         // calc un-normalized p(topic x | term a, document i)
@@ -370,9 +365,7 @@ public class TopicModel implements Confi
   public double perplexity(Vector document, Vector docTopics) {
     double perplexity = 0;
     double norm = docTopics.norm(1) + (docTopics.size() * alpha);
-    Iterator<Vector.Element> it = document.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : document.nonZeroes()) {
       int term = e.index();
       double prob = 0;
       for (int x = 0; x < numTopics; x++) {
@@ -387,10 +380,8 @@ public class TopicModel implements Confi
   }
 
   private void normalizeByTopic(Matrix perTopicSparseDistributions) {
-    Iterator<Vector.Element> it = perTopicSparseDistributions.viewRow(0).iterateNonZero();
     // then make sure that each of these is properly normalized by topic: sum_x(p(x|t,d)) = 1
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : perTopicSparseDistributions.viewRow(0).nonZeroes()) {
       int a = e.index();
       double sum = 0;
       for (int x = 0; x < numTopics; x++) {
@@ -405,9 +396,7 @@ public class TopicModel implements Confi
 
   public static String vectorToSortedString(Vector vector, String[] dictionary) {
     List<Pair<String,Double>> vectorValues = Lists.newArrayListWithCapacity(vector.getNumNondefaultElements());
-    Iterator<Vector.Element> it = vector.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Element e : vector.nonZeroes()) {
       vectorValues.add(Pair.of(dictionary != null ? dictionary[e.index()] : String.valueOf(e.index()),
                                e.get()));
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/minhash/MinHashMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/minhash/MinHashMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/minhash/MinHashMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/minhash/MinHashMapper.java Fri May 24 17:11:20 2013
@@ -82,7 +82,7 @@ public class MinHashMapper extends Mappe
     }
 
     for (int i = 0; i < numHashFunctions; i++) {
-      for (Vector.Element ele : featureVector) {
+      for (Vector.Element ele : featureVector.nonZeroes()) {
         int value = (int) ele.get();
         bytesToHash[0] = (byte) (value >> 24);
         bytesToHash[1] = (byte) (value >> 16);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/UnitVectorizerJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/UnitVectorizerJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/UnitVectorizerJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/UnitVectorizerJob.java Fri May 24 17:11:20 2013
@@ -28,10 +28,7 @@ import org.apache.hadoop.mapreduce.lib.i
 import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
-import org.apache.mahout.math.RandomAccessSparseVector;
-import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.VectorWritable;
-import org.apache.mahout.math.function.Functions;
 
 /**
  * <p>Given a DistributedRowMatrix, this job normalizes each row to unit
@@ -75,28 +72,8 @@ public final class UnitVectorizerJob {
     @Override
     protected void map(IntWritable row, VectorWritable vector, Context context) 
       throws IOException, InterruptedException {
-      
-      // set up the return value and perform the computations
-      double norm = vectorNorm(vector.get());
-      Vector w = vector.get().assign(Functions.div(norm));
-      RandomAccessSparseVector out = new RandomAccessSparseVector(w);
-      
-      // finally write the output
-      context.write(row, new VectorWritable(out));
-    }
-    
-    /**
-     * Sums the squares of all elements together, then takes the square root
-     * of that sum.
-     * @param u
-     * @return
-     */
-    private static double vectorNorm(Iterable<Vector.Element> u) {
-      double retval = 0.0;
-      for (Vector.Element e : u) {
-        retval += Functions.POW.apply(e.get(), 2);
-      }
-      return Functions.SQRT.apply(retval);
+      context.write(row, new VectorWritable(vector.get().normalize(2)));
     }
+
   }
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorMatrixMultiplicationJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorMatrixMultiplicationJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorMatrixMultiplicationJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/common/VectorMatrixMultiplicationJob.java Fri May 24 17:11:20 2013
@@ -120,7 +120,7 @@ public final class VectorMatrixMultiplic
     protected void map(IntWritable key, VectorWritable row, Context ctx) 
       throws IOException, InterruptedException {
       
-      for (Vector.Element e : row.get()) {
+      for (Vector.Element e : row.get().all()) {
         double dii = Functions.SQRT.apply(diagonal.get(key.get()));
         double djj = Functions.SQRT.apply(diagonal.get(e.index()));
         double mij = e.get();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsAffinityCutsJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsAffinityCutsJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsAffinityCutsJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsAffinityCutsJob.java Fri May 24 17:11:20 2013
@@ -101,7 +101,7 @@ public final class EigencutsAffinityCuts
       // and (3, 3) (which, incidentally, will also not be grouped together)
       String type = context.getWorkingDirectory().getName();
       Vector vector = row.get();
-      for (Vector.Element e : vector) {
+      for (Vector.Element e : vector.all()) {
         String newkey = Math.max(key.get(), e.index()) + "_" + Math.min(key.get(), e.index());
         context.write(new Text(newkey), new VertexWritable(key.get(), e.index(), e.get(), type));
       }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsDriver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsDriver.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsDriver.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/spectral/eigencuts/EigencutsDriver.java Fri May 24 17:11:20 2013
@@ -203,7 +203,7 @@ public class EigencutsDriver extends Abs
     if (v.size() < 100) {
       return v.zSum() / v.size();
     }
-    for (Vector.Element e : v) {
+    for (Vector.Element e : v.all()) {
       med.add(e.get());
     }
     return med.getMedian();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedEuclideanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedEuclideanDistanceMeasure.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedEuclideanDistanceMeasure.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedEuclideanDistanceMeasure.java Fri May 24 17:11:20 2013
@@ -17,9 +17,9 @@
 
 package org.apache.mahout.common.distance;
 
-import java.util.Iterator;
 
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 
 /**
  * This class implements a Euclidean distance metric by summing the square root of the squared differences
@@ -33,15 +33,11 @@ public class WeightedEuclideanDistanceMe
     Vector res = p2.minus(p1);
     Vector theWeights = getWeights();
     if (theWeights == null) {
-      Iterator<Vector.Element> iter = res.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element elt = iter.next();
+      for (Element elt : res.nonZeroes()) {
         result += elt.get() * elt.get();
       }
     } else {
-      Iterator<Vector.Element> iter = res.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element elt = iter.next();
+      for (Element elt : res.nonZeroes()) {
         result += elt.get() * elt.get() * theWeights.get(elt.index());
       }
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedManhattanDistanceMeasure.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedManhattanDistanceMeasure.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedManhattanDistanceMeasure.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/distance/WeightedManhattanDistanceMeasure.java Fri May 24 17:11:20 2013
@@ -17,9 +17,8 @@
 
 package org.apache.mahout.common.distance;
 
-import java.util.Iterator;
-
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 
 /**
  * This class implements a "Manhattan distance" metric by summing the absolute values of the difference
@@ -33,16 +32,12 @@ public class WeightedManhattanDistanceMe
     
     Vector res = p2.minus(p1);
     if (getWeights() == null) {
-      Iterator<Vector.Element> iter = res.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element elt = iter.next();
+      for (Element elt : res.nonZeroes()) {
         result += Math.abs(elt.get());
       }
       
     } else {
-      Iterator<Vector.Element> iter = res.iterateNonZero();
-      while (iter.hasNext()) {
-        Vector.Element elt = iter.next();
+      for (Element elt : res.nonZeroes()) {
         result += Math.abs(elt.get() * getWeights().get(elt.index()));
       }
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/mapreduce/TransposeMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/mapreduce/TransposeMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/mapreduce/TransposeMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/mapreduce/TransposeMapper.java Fri May 24 17:11:20 2013
@@ -24,16 +24,13 @@ import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.VectorWritable;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 public class TransposeMapper extends Mapper<IntWritable,VectorWritable,IntWritable,VectorWritable> {
 
   @Override
   protected void map(IntWritable r, VectorWritable v, Context ctx) throws IOException, InterruptedException {
     int row = r.get();
-    Iterator<Vector.Element> it = v.get().iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Vector.Element e : v.get().nonZeroes()) {
       RandomAccessSparseVector tmp = new RandomAccessSparseVector(Integer.MAX_VALUE, 1);
       tmp.setQuick(row, e.get());
       r.set(e.index());

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/VectorWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/VectorWritable.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/VectorWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/VectorWritable.java Fri May 24 17:11:20 2013
@@ -27,6 +27,8 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Iterator;
 
+import org.apache.mahout.math.Vector.Element;
+
 public final class VectorWritable extends Configured implements Writable {
 
   public static final int FLAG_DENSE = 0x01;
@@ -147,7 +149,7 @@ public final class VectorWritable extend
 
     Varint.writeUnsignedVarInt(vector.size(), out);
     if (dense) {
-      for (Vector.Element element : vector) {
+      for (Vector.Element element : vector.all()) {
         if (laxPrecision) {
           out.writeFloat((float) element.get());
         } else {
@@ -156,7 +158,7 @@ public final class VectorWritable extend
       }
     } else {
       Varint.writeUnsignedVarInt(vector.getNumNondefaultElements(), out);
-      Iterator<Vector.Element> iter = vector.iterateNonZero();
+      Iterator<Element> iter = vector.nonZeroes().iterator();
       if (sequential) {
         int lastIndex = 0;
         while (iter.hasNext()) {
@@ -200,7 +202,7 @@ public final class VectorWritable extend
     while (vectors.hasNext()) {
       VectorWritable v = vectors.next();
       if (v != null) {
-        Iterator<Vector.Element> nonZeroElements = v.get().iterateNonZero();
+        Iterator<Element> nonZeroElements = v.get().nonZeroes().iterator();
         while (nonZeroElements.hasNext()) {
           Vector.Element nonZeroElement = nonZeroElements.next();
           accumulator.setQuick(nonZeroElement.index(), nonZeroElement.get());

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/MatrixMultiplicationJob.java Fri May 24 17:11:20 2013
@@ -140,9 +140,7 @@ public class MatrixMultiplicationJob ext
       Vector multiplier = firstIsOutFrag ? ((VectorWritable)v.get(1)).get() : ((VectorWritable)v.get(0)).get();
 
       VectorWritable outVector = new VectorWritable();
-      Iterator<Vector.Element> it = multiplier.iterateNonZero();
-      while (it.hasNext()) {
-        Vector.Element e = it.next();
+      for (Vector.Element e : multiplier.nonZeroes()) {
         row.set(e.index());
         outVector.set(outFrag.times(e.get()));
         out.collect(row, outVector);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TransposeJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TransposeJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TransposeJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TransposeJob.java Fri May 24 17:11:20 2013
@@ -120,9 +120,7 @@ public class TransposeJob extends Abstra
     public void map(IntWritable r, VectorWritable v, OutputCollector<IntWritable, VectorWritable> out,
                     Reporter reporter) throws IOException {
       int row = r.get();
-      Iterator<Vector.Element> it = v.get().iterateNonZero();
-      while (it.hasNext()) {
-        Vector.Element e = it.next();
+      for (Vector.Element e : v.get().nonZeroes()) {
         RandomAccessSparseVector tmp = new RandomAccessSparseVector(newNumCols, 1);
         tmp.setQuick(row, e.get());
         r.set(e.index());

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/RowSimilarityJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/RowSimilarityJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/RowSimilarityJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/RowSimilarityJob.java Fri May 24 17:11:20 2013
@@ -33,6 +33,7 @@ import org.apache.mahout.common.commandl
 import org.apache.mahout.common.mapreduce.VectorSumReducer;
 import org.apache.mahout.math.RandomAccessSparseVector;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 import org.apache.mahout.math.hadoop.similarity.cooccurrence.measures.VectorSimilarityMeasures;
 import org.apache.mahout.math.hadoop.similarity.cooccurrence.measures.VectorSimilarityMeasure;
@@ -207,9 +208,7 @@ public class RowSimilarityJob extends Ab
       int numNonZeroEntries = 0;
       double maxValue = Double.MIN_VALUE;
 
-      Iterator<Vector.Element> nonZeroElements = rowVector.iterateNonZero();
-      while (nonZeroElements.hasNext()) {
-        Vector.Element element = nonZeroElements.next();
+      for (Vector.Element element : rowVector.nonZeroes()) {
         RandomAccessSparseVector partialColumnVector = new RandomAccessSparseVector(Integer.MAX_VALUE);
         partialColumnVector.setQuick(row.get(), element.get());
         ctx.write(new IntWritable(element.index()), new VectorWritable(partialColumnVector));
@@ -367,18 +366,14 @@ public class RowSimilarityJob extends Ab
       Vector dots = partialDotsIterator.next().get();
       while (partialDotsIterator.hasNext()) {
         Vector toAdd = partialDotsIterator.next().get();
-        Iterator<Vector.Element> nonZeroElements = toAdd.iterateNonZero();
-        while (nonZeroElements.hasNext()) {
-          Vector.Element nonZeroElement = nonZeroElements.next();
+        for (Element nonZeroElement : toAdd.nonZeroes()) {
           dots.setQuick(nonZeroElement.index(), dots.getQuick(nonZeroElement.index()) + nonZeroElement.get());
         }
       }
 
       Vector similarities = dots.like();
       double normA = norms.getQuick(row.get());
-      Iterator<Vector.Element> dotsWith = dots.iterateNonZero();
-      while (dotsWith.hasNext()) {
-        Vector.Element b = dotsWith.next();
+      for (Element b : dots.nonZeroes()) {
         double similarityValue = similarity.similarity(b.get(), normA, norms.getQuick(b.index()), numberOfColumns);
         if (similarityValue >= treshold) {
           similarities.set(b.index(), similarityValue);
@@ -408,10 +403,7 @@ public class RowSimilarityJob extends Ab
       // For performance, the creation of transposedPartial is moved out of the while loop and it is reused inside
       Vector transposedPartial = new RandomAccessSparseVector(similarities.size(), 1);
       TopElementsQueue topKQueue = new TopElementsQueue(maxSimilaritiesPerRow);
-      Iterator<Vector.Element> nonZeroElements = similarities.iterateNonZero();
-      while (nonZeroElements.hasNext()) {
-        Vector.Element nonZeroElement = nonZeroElements.next();
-
+      for (Element nonZeroElement : similarities.nonZeroes()) {
         MutableElement top = topKQueue.top();
         double candidateValue = nonZeroElement.get();
         if (candidateValue > top.get()) {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/Vectors.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/Vectors.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/Vectors.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/Vectors.java Fri May 24 17:11:20 2013
@@ -28,6 +28,7 @@ import org.apache.mahout.common.iterator
 import org.apache.mahout.math.RandomAccessSparseVector;
 import org.apache.mahout.math.Varint;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 import org.apache.mahout.math.map.OpenIntIntHashMap;
 
@@ -44,10 +45,10 @@ public final class Vectors {
       return original;
     }
     Vector sample = new RandomAccessSparseVector(original.size(), sampleSize);
-    Iterator<Vector.Element> sampledElements =
-        new FixedSizeSamplingIterator<Vector.Element>(sampleSize, original.iterateNonZero());
+    Iterator<Element> sampledElements =
+        new FixedSizeSamplingIterator<Vector.Element>(sampleSize, original.nonZeroes().iterator());
     while (sampledElements.hasNext()) {
-      Vector.Element elem = sampledElements.next();
+      Element elem = sampledElements.next();
       sample.setQuick(elem.index(), elem.get());
     }
     return sample;
@@ -59,10 +60,7 @@ public final class Vectors {
     }
 
     TopElementsQueue topKQueue = new TopElementsQueue(k);
-    Iterator<Vector.Element> nonZeroElements = original.iterateNonZero();
-    while (nonZeroElements.hasNext()) {
-      Vector.Element nonZeroElement = nonZeroElements.next();
-
+    for (Element nonZeroElement : original.nonZeroes()) {
       MutableElement top = topKQueue.top();
       double candidateValue = nonZeroElement.get();
       if (candidateValue > top.get()) {
@@ -85,9 +83,7 @@ public final class Vectors {
     while (vectors.hasNext()) {
       VectorWritable v = vectors.next();
       if (v != null) {
-        Iterator<Vector.Element> nonZeroElements = v.get().iterateNonZero();
-        while (nonZeroElements.hasNext()) {
-          Vector.Element nonZeroElement = nonZeroElements.next();
+        for (Element nonZeroElement : v.get().nonZeroes()) {
           accumulator.setQuick(nonZeroElement.index(), nonZeroElement.get());
         }
       }
@@ -128,9 +124,7 @@ public final class Vectors {
   public static Vector.Element[] toArray(VectorWritable vectorWritable) {
     Vector.Element[] elements = new Vector.Element[vectorWritable.get().getNumNondefaultElements()];
     int k = 0;
-    Iterator<Vector.Element> nonZeroElements = vectorWritable.get().iterateNonZero();
-    while (nonZeroElements.hasNext()) {
-      Vector.Element nonZeroElement = nonZeroElements.next();
+    for (Element nonZeroElement : vectorWritable.get().nonZeroes()) {
       elements[k++] = new TemporaryElement(nonZeroElement.index(), nonZeroElement.get());
     }
     return elements;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/EuclideanDistanceSimilarity.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/EuclideanDistanceSimilarity.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/EuclideanDistanceSimilarity.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/EuclideanDistanceSimilarity.java Fri May 24 17:11:20 2013
@@ -19,8 +19,6 @@ package org.apache.mahout.math.hadoop.si
 
 import org.apache.mahout.math.Vector;
 
-import java.util.Iterator;
-
 public class EuclideanDistanceSimilarity implements VectorSimilarityMeasure {
 
   @Override
@@ -31,9 +29,8 @@ public class EuclideanDistanceSimilarity
   @Override
   public double norm(Vector vector) {
     double norm = 0;
-    Iterator<Vector.Element> nonZeroElements = vector.iterateNonZero();
-    while (nonZeroElements.hasNext()) {
-      double value = nonZeroElements.next().get();
+    for (Vector.Element e : vector.nonZeroes()) {
+      double value = e.get();
       norm += value * value;
     }
     return norm;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/PearsonCorrelationSimilarity.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/PearsonCorrelationSimilarity.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/PearsonCorrelationSimilarity.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/similarity/cooccurrence/measures/PearsonCorrelationSimilarity.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.math.hadoop.similarity.cooccurrence.measures;
 
-import java.util.Iterator;
-
 import org.apache.mahout.math.Vector;
 
 public class PearsonCorrelationSimilarity extends CosineSimilarity {
@@ -31,9 +29,7 @@ public class PearsonCorrelationSimilarit
 
     // center non-zero elements
     double average = vector.norm(1) / vector.getNumNonZeroElements();
-    Iterator<Vector.Element> it = vector.iterateNonZero();
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
+    for (Vector.Element e : vector.nonZeroes()) {
       e.set(e.get() - average);
     }
     return super.normalize(vector);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtDenseOutJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtDenseOutJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtDenseOutJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtDenseOutJob.java Fri May 24 17:11:20 2013
@@ -128,8 +128,7 @@ public final class ABtDenseOutJob {
           aCols[i].setQuick(aRowCount, vec.getQuick(i));
         }
       } else if (vec.size() > 0) {
-        for (Iterator<Vector.Element> vecIter = vec.iterateNonZero(); vecIter.hasNext();) {
-          Vector.Element vecEl = vecIter.next();
+        for (Vector.Element vecEl : vec.nonZeroes()) {
           int i = vecEl.index();
           extendAColIfNeeded(i, aRowCount + 1);
           aCols[i].setQuick(aRowCount, vecEl.get());
@@ -241,8 +240,7 @@ public final class ABtDenseOutJob {
               continue;
             }
             int j = -1;
-            for (Iterator<Vector.Element> aColIter = aCol.iterateNonZero(); aColIter.hasNext();) {
-              Vector.Element aEl = aColIter.next();
+            for (Vector.Element aEl : aCol.nonZeroes()) {
               j = aEl.index();
 
               /*

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/ABtJob.java Fri May 24 17:11:20 2013
@@ -23,7 +23,6 @@ import java.text.NumberFormat;
 import java.util.ArrayDeque;
 import java.util.Arrays;
 import java.util.Deque;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.regex.Matcher;
 
@@ -119,8 +118,7 @@ public final class ABtJob {
           aCols[i].setQuick(aRowCount, vec.getQuick(i));
         }
       } else {
-        for (Iterator<Vector.Element> vecIter = vec.iterateNonZero(); vecIter.hasNext();) {
-          Vector.Element vecEl = vecIter.next();
+        for (Vector.Element vecEl : vec.nonZeroes()) {
           int i = vecEl.index();
           extendAColIfNeeded(i, aRowCount + 1);
           aCols[i].setQuick(aRowCount, vecEl.get());
@@ -160,8 +158,7 @@ public final class ABtJob {
             continue;
           }
           int j = -1;
-          for (Iterator<Vector.Element> aColIter = aCol.iterateNonZero(); aColIter.hasNext();) {
-            Vector.Element aEl = aColIter.next();
+          for (Vector.Element aEl : aCol.nonZeroes()) {
             j = aEl.index();
 
             // outKey.setTaskItemOrdinal(j);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/BtJob.java Fri May 24 17:11:20 2013
@@ -21,7 +21,6 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
-import java.util.Iterator;
 
 import org.apache.commons.lang3.Validate;
 import org.apache.hadoop.conf.Configuration;
@@ -150,8 +149,7 @@ public final class BtJob {
       }
 
       if (!aRow.isDense()) {
-        for (Iterator<Vector.Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
-          Vector.Element el = iter.next();
+        for (Vector.Element el : aRow.nonZeroes()) {
           double mul = el.get();
           for (int j = 0; j < kp; j++) {
             btRow.setQuick(j, mul * qRow.getQuick(j));

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/Omega.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/Omega.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/Omega.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/Omega.java Fri May 24 17:11:20 2013
@@ -18,7 +18,6 @@
 package org.apache.mahout.math.hadoop.stochasticsvd;
 
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.Callable;
@@ -79,8 +78,7 @@ public class Omega {
         accumDots(j, aRow.getQuick(j), yRow);
       }
     } else {
-      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
-        Element el = iter.next();
+      for (Element el : aRow.nonZeroes()) {
         accumDots(el.index(), el.get(), yRow);
       }
     }
@@ -101,8 +99,7 @@ public class Omega {
         accumDots(j, aRow.getQuick(j), yRowOut);
       }
     } else {
-      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
-        Element el = iter.next();
+      for (Element el : aRow.nonZeroes()) {
         accumDots(el.index(), el.get(), yRowOut);
       }
     }
@@ -139,8 +136,7 @@ public class Omega {
               }
 
             } else {
-              for (Iterator<Vector.Element> iter = v.iterateNonZero(); iter.hasNext();) {
-                Vector.Element el = iter.next();
+              for (Element el : v.nonZeroes()) {
                 int k = el.index();
                 result += getQuick(k, index) * el.get();
               }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangular.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangular.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangular.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/UpperTriangular.java Fri May 24 17:11:20 2013
@@ -84,7 +84,7 @@ public class UpperTriangular extends Abs
     if (other.viewPart(column + 1, other.size() - column - 1).norm(1) > 1.0e-14) {
       throw new IllegalArgumentException("Cannot set lower portion of triangular matrix to non-zero");
     }
-    for (Vector.Element element : other.viewPart(0, column)) {
+    for (Vector.Element element : other.viewPart(0, column).all()) {
       setQuick(element.index(), column, element.get());
     }
     return this;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/YtYJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/YtYJob.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/YtYJob.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/YtYJob.java Fri May 24 17:11:20 2013
@@ -17,7 +17,6 @@
 package org.apache.mahout.math.hadoop.stochasticsvd;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 import org.apache.commons.lang3.Validate;
 import org.apache.hadoop.conf.Configuration;
@@ -115,11 +114,9 @@ public final class YtYJob {
          * are creating some short-lived references) here is that we obviously
          * do two times more iterations then necessary if y row is pretty dense.
          */
-        for (Iterator<Vector.Element> iterI = yRow.iterateNonZero(); iterI.hasNext();) {
-          Vector.Element eli = iterI.next();
+        for (Vector.Element eli : yRow.nonZeroes()) {
           int i = eli.index();
-          for (Iterator<Vector.Element> iterJ = yRow.iterateNonZero(); iterJ.hasNext();) {
-            Vector.Element elj = iterJ.next();
+          for (Vector.Element elj : yRow.nonZeroes()) {
             int j = elj.index();
             if (j < i) {
               continue;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/qr/QRFirstStep.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/qr/QRFirstStep.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/qr/QRFirstStep.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/qr/QRFirstStep.java Fri May 24 17:11:20 2013
@@ -21,7 +21,6 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Deque;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
@@ -39,6 +38,7 @@ import org.apache.mahout.common.IOUtils;
 import org.apache.mahout.common.iterator.CopyConstructorIterator;
 import org.apache.mahout.math.DenseVector;
 import org.apache.mahout.math.Vector;
+import org.apache.mahout.math.Vector.Element;
 import org.apache.mahout.math.VectorWritable;
 import org.apache.mahout.math.hadoop.stochasticsvd.DenseBlockWritable;
 import org.apache.mahout.math.hadoop.stochasticsvd.UpperTriangular;
@@ -191,9 +191,7 @@ public class QRFirstStep implements Clos
       }
     } else {
       Arrays.fill(yRow, 0);
-      for (Iterator<Vector.Element> yIter = incomingYRow.iterateNonZero(); yIter
-        .hasNext();) {
-        Vector.Element yEl = yIter.next();
+      for (Element yEl : incomingYRow.nonZeroes()) {
         yRow[yEl.index()] = yEl.get();
       }
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/neighborhood/HashedVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/neighborhood/HashedVector.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/neighborhood/HashedVector.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/neighborhood/HashedVector.java Fri May 24 17:11:20 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.math.neighborhood;
 
-import java.util.Iterator;
-
 import org.apache.mahout.math.Matrix;
 import org.apache.mahout.math.Vector;
 import org.apache.mahout.math.WeightedVector;
@@ -55,10 +53,7 @@ public class HashedVector extends Weight
 
   public static long computeHash64(Vector vector, Matrix projection) {
     long hash = 0;
-    Iterator<Element> iterator = projection.times(vector).iterateNonZero();
-    Element element;
-    while (iterator.hasNext()) {
-      element = iterator.next();
+    for (Element element : projection.times(vector).nonZeroes()) {
       if (element.get() > 0) {
         hash += 1 << element.index();
       }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/stats/GlobalOnlineAuc.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/stats/GlobalOnlineAuc.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/stats/GlobalOnlineAuc.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/stats/GlobalOnlineAuc.java Fri May 24 17:11:20 2013
@@ -106,7 +106,7 @@ public class GlobalOnlineAuc implements 
       Vector row = scores.viewRow(1 - category);
       double m = 0.0;
       double count = 0.0;
-      for (Vector.Element element : row) {
+      for (Vector.Element element : row.all()) {
         double v = element.get();
         if (Double.isNaN(v)) {
           continue;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/pruner/WordsPrunerReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/pruner/WordsPrunerReducer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/pruner/WordsPrunerReducer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/pruner/WordsPrunerReducer.java Fri May 24 17:11:20 2013
@@ -51,9 +51,7 @@ public class WordsPrunerReducer extends
     Vector value = it.next().get();
     Vector vector = value.clone();
     if (maxDf > -1) {
-      Iterator<Vector.Element> it1 = value.iterateNonZero();
-      while (it1.hasNext()) {
-        Vector.Element e = it1.next();
+      for (Vector.Element e : value.nonZeroes()) {
         if (!dictionary.containsKey(e.index())) {
           vector.setQuick(e.index(), 0.0);
           continue;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TermDocumentCountMapper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TermDocumentCountMapper.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TermDocumentCountMapper.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/term/TermDocumentCountMapper.java Fri May 24 17:11:20 2013
@@ -18,7 +18,6 @@
 package org.apache.mahout.vectorizer.term;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
@@ -36,15 +35,15 @@ public class TermDocumentCountMapper ext
 
   private static final IntWritable TOTAL_COUNT = new IntWritable(-1);
 
+  private final IntWritable out = new IntWritable();
+
   @Override
   protected void map(WritableComparable<?> key, VectorWritable value, Context context)
     throws IOException, InterruptedException {
     Vector vector = value.get();
-    Iterator<Vector.Element> it = vector.iterateNonZero();
-
-    while (it.hasNext()) {
-      Vector.Element e = it.next();
-      context.write(new IntWritable(e.index()), ONE);
+    for (Vector.Element e : vector.nonZeroes()) {
+      out.set(e.index());
+      context.write(out, ONE);
     }
     context.write(TOTAL_COUNT, ONE);
   }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFPartialVectorReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFPartialVectorReducer.java?rev=1486122&r1=1486121&r2=1486122&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFPartialVectorReducer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/tfidf/TFIDFPartialVectorReducer.java Fri May 24 17:11:20 2013
@@ -70,10 +70,8 @@ public class TFIDFPartialVectorReducer e
       return;
     }
     Vector value = it.next().get();
-    Iterator<Vector.Element> it1 = value.iterateNonZero();
     Vector vector = new RandomAccessSparseVector((int) featureCount, value.getNumNondefaultElements());
-    while (it1.hasNext()) {
-      Vector.Element e = it1.next();
+    for (Vector.Element e : value.nonZeroes()) {
       if (!dictionary.containsKey(e.index())) {
         continue;
       }



Mime
View raw message