[ 
https://issues.apache.org/jira/browse/MAHOUT-67?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12611772#action_12611772
 ] 

Karl Wettin commented on MAHOUT-67:
-----------------------------------

You say you need to modify the cardinality. I'm not sure about what has been 
said about the constraints of Vector modifiers, but the code seems rather 
static about Vectors being compatible from the start.

Is this also about making use of the sparseness? Then how about something like 
this in AbstractVector:

{code:java}
===================================================================
--- core/src/main/java/org/apache/mahout/matrix/AbstractVector.java     
(revision 674908)
+++ core/src/main/java/org/apache/mahout/matrix/AbstractVector.java     
(working copy)
@@ -230,15 +230,16 @@
 
   /*
    * (non-Javadoc)
    *
    * @see org.apache.mahout.matrix.Vector#plus(org.apache.mahout.matrix.Vector)
    */
   public Vector plus(Vector x) throws CardinalityException {
     if (cardinality() != x.cardinality())
       throw new CardinalityException();
     Vector result = copy();
-    for (int i = 0; i < result.cardinality(); i++)
-      result.setQuick(i, getQuick(i) + x.getQuick(i));
+    for (Vector.Element e : x) {
+      result.setQuick(e.index(), e.get());
+    }
     return result;
   }
{code}



> plus method in AbstractVector doesn't work for SparseVectors
> ------------------------------------------------------------
>
>                 Key: MAHOUT-67
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-67
>             Project: Mahout
>          Issue Type: Bug
>          Components: Matrix
>            Reporter: Pallavi Palleti
>            Priority: Minor
>         Attachments: MAHOUT-67.patch
>
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to