mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject svn commit: r687769 - in /lucene/mahout/trunk/core/src: main/java/org/apache/mahout/matrix/ test/java/org/apache/mahout/clustering/canopy/ test/java/org/apache/mahout/matrix/
Date Thu, 21 Aug 2008 14:23:51 GMT
Author: kalle
Date: Thu Aug 21 07:23:50 2008
New Revision: 687769

URL: http://svn.apache.org/viewvc?rev=687769&view=rev
Log:
MAHOUT-75
asFormatString related test failures fixed by intermediate sorting of hash bound entry collections.

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseMatrix.java
    lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseVector.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java?rev=687769&r1=687768&r2=687769&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java Thu
Aug 21 07:23:50 2008
@@ -18,6 +18,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Arrays;
 
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparable;
@@ -81,8 +82,10 @@
   public String asFormatString() {
     StringBuilder out = new StringBuilder();
     out.append("[s").append(cardinality[ROW]).append(", ");
-    for (Integer row : rows.keySet())
-      out.append(rows.get(row).asWritableComparable());
+    Integer[] rows = this.rows.keySet().toArray(new Integer[this.rows.size()]);
+    Arrays.sort(rows);
+    for (Integer row : rows)
+      out.append(this.rows.get(row).asWritableComparable());
     out.append("] ");
     return out.toString();
   }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java?rev=687769&r1=687768&r2=687769&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java Thu
Aug 21 07:23:50 2008
@@ -18,6 +18,8 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Arrays;
+import java.util.Comparator;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.DataInput;
@@ -97,7 +99,13 @@
   public String asFormatString() {
     StringBuilder out = new StringBuilder();
     out.append("[s").append(cardinality).append(", ");
-    for (Map.Entry<Integer, Double> entry : values.entrySet()) {
+    Map.Entry<Integer, Double>[] entries = values.entrySet().toArray(new Map.Entry[values.size()]);
+    Arrays.sort(entries, new Comparator<Map.Entry<Integer, Double>>(){
+      public int compare(Map.Entry<Integer, Double> e1, Map.Entry<Integer, Double>
e2) {
+        return e1.getKey().compareTo(e2.getKey());
+      }
+    });
+    for (Map.Entry<Integer, Double> entry : entries) {
       out.append(entry.getKey()).append(':').append(entry.getValue()).append(", ");
     }
     out.append("] ");

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java?rev=687769&r1=687768&r2=687769&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/canopy/TestCanopyCreation.java
Thu Aug 21 07:23:50 2008
@@ -483,10 +483,10 @@
     Text value = new Text();
     assertTrue("more to come", reader.next(key, value));
     assertEquals("1st key", "C0", key.toString());
-    assertEquals("1st value", "C0: [s2, 1:1.5, 0:1.5, ] ", value.toString());
+    assertEquals("1st value", "C0: [s2, 0:1.5, 1:1.5, ] ", value.toString());
     assertTrue("more to come", reader.next(key, value));
     assertEquals("2nd key", "C1", key.toString());
-    assertEquals("2nd value", "C1: [s2, 1:4.333333333333334, 0:4.333333333333334, ] ",
+    assertEquals("2nd value", "C1: [s2, 0:4.333333333333334, 1:4.333333333333334, ] ",
         value.toString());
     assertFalse("more to come", reader.next(key, value));
     reader.close();
@@ -519,10 +519,10 @@
     Text value = new Text();
     assertTrue("more to come", reader.next(key, value));
     assertEquals("1st key", "C0", key.toString());
-    assertEquals("1st value", "C0: [s2, 1:1.8, 0:1.8, ] ", value.toString());
+    assertEquals("1st value", "C0: [s2, 0:1.8, 1:1.8, ] ", value.toString());
     assertTrue("more to come", reader.next(key, value));
     assertEquals("2nd key", "C1", key.toString());
-    assertEquals("2nd value", "C1: [s2, 1:4.433333333333334, 0:4.433333333333334, ] ",
+    assertEquals("2nd value", "C1: [s2, 0:4.433333333333334, 1:4.433333333333334, ] ",
         value.toString());
     assertFalse("more to come", reader.next(key, value));
     reader.close();
@@ -810,10 +810,10 @@
     Text value = new Text();
     assertTrue("more to come", reader.next(key, value));
     assertEquals("1st key", "C0", key.toString());
-    assertEquals("1st value", "C0: [s2, 1:1.5, 0:1.5, ] ", value.toString());
+    assertEquals("1st value", "C0: [s2, 0:1.5, 1:1.5, ] ", value.toString());
     assertTrue("more to come", reader.next(key, value));
     assertEquals("2nd key", "C1", key.toString());
-    assertEquals("2nd value", "C1: [s2, 1:4.333333333333334, 0:4.333333333333334, ] ",
+    assertEquals("2nd value", "C1: [s2, 0:4.333333333333334, 1:4.333333333333334, ] ",
         value.toString());
     assertFalse("more to come", reader.next(key, value));
     reader.close();

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseMatrix.java?rev=687769&r1=687768&r2=687769&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseMatrix.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseMatrix.java
Thu Aug 21 07:23:50 2008
@@ -38,7 +38,7 @@
   public void testAsFormatString() {
     assertEquals(
             "format",
-            "[s3, [s2, 1:6.6, 0:5.5, ] [s2, 1:4.4, 0:3.3, ] [s2, 1:2.2, 0:1.1, ] ] ",
+            "[s3, [s2, 0:1.1, 1:2.2, ] [s2, 0:3.3, 1:4.4, ] [s2, 0:5.5, 1:6.6, ] ] ",
             test.asWritableComparable().toString());
   }
 

Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseVector.java?rev=687769&r1=687768&r2=687769&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseVector.java
(original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/matrix/TestSparseVector.java
Thu Aug 21 07:23:50 2008
@@ -37,7 +37,7 @@
 
   public void testAsFormatString() {
     String formatString = test.asWritableComparable().toString();
-    assertEquals("format", "[s5, 2:2.2, 1:1.1, 3:3.3, ] ", formatString);
+    assertEquals("format", "[s5, 1:1.1, 2:2.2, 3:3.3, ] ", formatString);
   }
 
   public void testCardinality() {



Mime
View raw message