commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1360668 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/RealVector.java
Date Thu, 12 Jul 2012 13:31:46 GMT
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;
-
     }
 
     /**



Mime
View raw message