You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/12/24 00:27:52 UTC

svn commit: r729173 - /commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java

Author: luc
Date: Tue Dec 23 15:27:52 2008
New Revision: 729173

URL: http://svn.apache.org/viewvc?rev=729173&view=rev
Log:
added a specialized implementation of premultiply
removed unneeded signatures with RelVectorImpl already handled efficiently by base class

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java?rev=729173&r1=729172&r2=729173&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java Tue Dec 23 15:27:52 2008
@@ -414,7 +414,11 @@
         final int nRows = this.getRowDimension();
         final int nCols = this.getColumnDimension();
         if (v.length != nCols) {
-            throw new IllegalArgumentException("vector has wrong length");
+            throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
+                                                                      " got {0} but expected {1}",
+                                                                      new Object[] {
+                                                                          v.length, nCols
+                                                                      });
         }
         final double[] out = new double[nRows];
         for (int row = 0; row < nRows; row++) {
@@ -429,25 +433,30 @@
     }
 
     /** {@inheritDoc} */
-    public RealVector operate(final RealVector v)
+    public double[] preMultiply(final double[] v)
         throws IllegalArgumentException {
-        try {
-            return operate((RealVectorImpl) v);
-        } catch (ClassCastException cce) {
-            return super.operate(v);
+
+        final int nRows = getRowDimension();
+        final int nCols = getColumnDimension();
+        if (v.length != nRows) {
+            throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
+                                                                      " got {0} but expected {1}",
+                                                                      new Object[] {
+                                                                          v.length, nRows
+                                                                      });
         }
-    }
 
-    /**
-     * Returns the result of multiplying this by the vector <code>v</code>.
-     *
-     * @param v the vector to operate on
-     * @return this*v
-     * @throws IllegalArgumentException if columnDimension != v.size()
-     */
-    public RealVectorImpl operate(final RealVectorImpl v)
-        throws IllegalArgumentException {
-        return new RealVectorImpl(operate(v.getDataRef()), false);
+        final double[] out = new double[nCols];
+        for (int col = 0; col < nCols; ++col) {
+            double sum = 0;
+            for (int i = 0; i < nRows; ++i) {
+                sum += data[i][col] * v[i];
+            }
+            out[col] = sum;
+        }
+
+        return out;
+
     }
 
     /**