mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r931513 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model: BooleanItemPreferenceArray.java BooleanUserPreferenceArray.java GenericItemPreferenceArray.java GenericUserPreferenceArray.java
Date Wed, 07 Apr 2010 12:08:35 GMT
Author: srowen
Date: Wed Apr  7 12:08:35 2010
New Revision: 931513

URL: http://svn.apache.org/viewvc?rev=931513&view=rev
Log:
MAHOUT-367 allow a zero-length pref array

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java?rev=931513&r1=931512&r2=931513&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java
Wed Apr  7 12:08:35 2010
@@ -41,19 +41,20 @@ public final class BooleanItemPreference
   private long id;
   
   public BooleanItemPreferenceArray(int size) {
-    if (size < 1) {
-      throw new IllegalArgumentException("size is less than 1");
-    }
     this.IDs = new long[size];
+    this.id = Long.MIN_VALUE; // as a sort of 'unspecified' value
   }
   
   public BooleanItemPreferenceArray(List<Preference> prefs, boolean forOneUser) {
     this(prefs.size());
-    for (int i = 0; i < prefs.size(); i++) {
+    int size = prefs.size();
+    for (int i = 0; i < size; i++) {
       Preference pref = prefs.get(i);
       IDs[i] = forOneUser ? pref.getItemID() : pref.getUserID();
     }
-    id = forOneUser ? prefs.get(0).getUserID() : prefs.get(0).getItemID();
+    if (size > 0) {
+      id = forOneUser ? prefs.get(0).getUserID() : prefs.get(0).getItemID();
+    }
   }
   
   /**

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java?rev=931513&r1=931512&r2=931513&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java
Wed Apr  7 12:08:35 2010
@@ -41,19 +41,20 @@ public final class BooleanUserPreference
   private long id;
   
   public BooleanUserPreferenceArray(int size) {
-    if (size < 1) {
-      throw new IllegalArgumentException("size is less than 1");
-    }
     this.IDs = new long[size];
+    this.id = Long.MIN_VALUE; // as a sort of 'unspecified' value
   }
   
   public BooleanUserPreferenceArray(List<Preference> prefs) {
     this(prefs.size());
-    for (int i = 0; i < prefs.size(); i++) {
+    int size = prefs.size();
+    for (int i = 0; i < size; i++) {
       Preference pref = prefs.get(i);
       IDs[i] = pref.getItemID();
     }
-    id = prefs.get(0).getUserID();
+    if (size > 0) {
+      id = prefs.get(0).getUserID();
+    }
   }
   
   /**

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java?rev=931513&r1=931512&r2=931513&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java
Wed Apr  7 12:08:35 2010
@@ -45,21 +45,22 @@ public final class GenericItemPreference
   private final float[] values;
   
   public GenericItemPreferenceArray(int size) {
-    if (size < 1) {
-      throw new IllegalArgumentException("size is less than 1");
-    }
     this.IDs = new long[size];
     values = new float[size];
+    this.id = Long.MIN_VALUE; // as a sort of 'unspecified' value
   }
   
   public GenericItemPreferenceArray(List<Preference> prefs) {
     this(prefs.size());
-    for (int i = 0; i < prefs.size(); i++) {
+    int size = prefs.size();
+    for (int i = 0; i < size; i++) {
       Preference pref = prefs.get(i);
       IDs[i] = pref.getUserID();
       values[i] = pref.getValue();
     }
-    id = prefs.get(0).getItemID();
+    if (size > 0) {
+      id = prefs.get(0).getItemID();
+    }
   }
   
   /**

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java?rev=931513&r1=931512&r2=931513&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java
Wed Apr  7 12:08:35 2010
@@ -46,21 +46,22 @@ public final class GenericUserPreference
   private final float[] values;
   
   public GenericUserPreferenceArray(int size) {
-    if (size < 1) {
-      throw new IllegalArgumentException("size is less than 1");
-    }
     this.IDs = new long[size];
     values = new float[size];
+    this.id = Long.MIN_VALUE; // as a sort of 'unspecified' value
   }
   
   public GenericUserPreferenceArray(List<Preference> prefs) {
     this(prefs.size());
-    for (int i = 0; i < prefs.size(); i++) {
+    int size = prefs.size();
+    for (int i = 0; i < size; i++) {
       Preference pref = prefs.get(i);
       IDs[i] = pref.getItemID();
       values[i] = pref.getValue();
     }
-    id = prefs.get(0).getUserID();
+    if (size > 0) {
+      id = prefs.get(0).getUserID();
+    }
   }
   
   /**



Mime
View raw message