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:25:32 UTC
svn commit: r729172 -
/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java
Author: luc
Date: Tue Dec 23 15:25:31 2008
New Revision: 729172
URL: http://svn.apache.org/viewvc?rev=729172&view=rev
Log:
use direct array access where possible
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java?rev=729172&r1=729171&r2=729172&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java Tue Dec 23 15:25:31 2008
@@ -606,28 +606,30 @@
/** {@inheritDoc} */
public RealVector operate(final RealVector v)
throws IllegalArgumentException {
-
- final int nRows = getRowDimension();
- final int nCols = getColumnDimension();
- if (v.getDimension() != nCols) {
- throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
- " got {0} but expected {1}",
- new Object[] {
- v.getDimension(), nCols
- });
- }
-
- final double[] out = new double[nRows];
- for (int row = 0; row < nRows; ++row) {
- double sum = 0;
- for (int i = 0; i < nCols; ++i) {
- sum += getEntry(row, i) * v.getEntry(i);
+ try {
+ return new RealVectorImpl(operate(((RealVectorImpl) v).getDataRef()), false);
+ } catch (ClassCastException cce) {
+ final int nRows = getRowDimension();
+ final int nCols = getColumnDimension();
+ if (v.getDimension() != nCols) {
+ throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
+ " got {0} but expected {1}",
+ new Object[] {
+ v.getDimension(), nCols
+ });
}
- out[row] = sum;
- }
- return new RealVectorImpl(out, false);
+ final double[] out = new double[nRows];
+ for (int row = 0; row < nRows; ++row) {
+ double sum = 0;
+ for (int i = 0; i < nCols; ++i) {
+ sum += getEntry(row, i) * v.getEntry(i);
+ }
+ out[row] = sum;
+ }
+ return new RealVectorImpl(out, false);
+ }
}
/** {@inheritDoc} */
@@ -660,28 +662,32 @@
/** {@inheritDoc} */
public RealVector preMultiply(final RealVector v)
throws IllegalArgumentException {
+ try {
+ return new RealVectorImpl(preMultiply(((RealVectorImpl) v).getDataRef()), false);
+ } catch (ClassCastException cce) {
+
+ final int nRows = getRowDimension();
+ final int nCols = getColumnDimension();
+ if (v.getDimension() != nRows) {
+ throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
+ " got {0} but expected {1}",
+ new Object[] {
+ v.getDimension(), nRows
+ });
+ }
- final int nRows = getRowDimension();
- final int nCols = getColumnDimension();
- if (v.getDimension() != nRows) {
- throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" +
- " got {0} but expected {1}",
- new Object[] {
- v.getDimension(), nRows
- });
- }
-
- final double[] out = new double[nCols];
- for (int col = 0; col < nCols; ++col) {
- double sum = 0;
- for (int i = 0; i < nRows; ++i) {
- sum += getEntry(i, col) * v.getEntry(i);
+ final double[] out = new double[nCols];
+ for (int col = 0; col < nCols; ++col) {
+ double sum = 0;
+ for (int i = 0; i < nRows; ++i) {
+ sum += getEntry(i, col) * v.getEntry(i);
+ }
+ out[col] = sum;
}
- out[col] = sum;
- }
- return new RealVectorImpl(out);
+ return new RealVectorImpl(out);
+ }
}
/** {@inheritDoc} */