You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2012/07/12 15:31:46 UTC

svn commit: r1360668 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java

Author: celestin
Date: Thu Jul 12 13:31:45 2012
New Revision: 1360668

URL: http://svn.apache.org/viewvc?rev=1360668&view=rev
Log:
MATH-812: fixed a bug in RealVector.outerProduct(RealVector). Now loops through *all* entries of the vectors.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java?rev=1360668&r1=1360667&r2=1360668&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java Thu Jul 12 13:31:45 2012
@@ -642,27 +642,20 @@ public abstract class RealVector {
      * @return the matrix outer product between this instance and {@code v}.
      */
     public RealMatrix outerProduct(RealVector v) {
-        RealMatrix product;
+        final int m = this.getDimension();
+        final int n = v.getDimension();
+        final RealMatrix product;
         if (v instanceof SparseRealVector || this instanceof SparseRealVector) {
-            product = new OpenMapRealMatrix(this.getDimension(),
-                                            v.getDimension());
+            product = new OpenMapRealMatrix(m, n);
         } else {
-            product = new Array2DRowRealMatrix(this.getDimension(),
-                                               v.getDimension());
+            product = new Array2DRowRealMatrix(m, n);
         }
-        Iterator<Entry> thisIt = sparseIterator();
-        while (thisIt.hasNext()) {
-            final Entry thisE = thisIt.next();
-            Iterator<Entry> otherIt = v.sparseIterator();
-            while (otherIt.hasNext()) {
-                final Entry otherE = otherIt.next();
-                product.setEntry(thisE.getIndex(), otherE.getIndex(),
-                                 thisE.getValue() * otherE.getValue());
+        for (int i = 0; i < m; i++) {
+            for (int j = 0; j < n; j++) {
+                product.setEntry(i, j, this.getEntry(i) * v.getEntry(j));
             }
         }
-
         return product;
-
     }
 
     /**