diff --git a/src/java/org/apache/commons/math/linear/BigMatrixImpl.java b/src/java/org/apache/commons/math/linear/BigMatrixImpl.java index 7cd61cb2c..919a5bab1 100644 --- a/src/java/org/apache/commons/math/linear/BigMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/BigMatrixImpl.java @@ -988,7 +988,7 @@ public class BigMatrixImpl implements BigMatrix, Serializable { } final int nRows = this.getRowDimension(); final int nCols = this.getColumnDimension(); - final BigDecimal[] out = new BigDecimal[v.length]; + final BigDecimal[] out = new BigDecimal[nRows]; for (int row = 0; row < nRows; row++) { BigDecimal sum = ZERO; for (int i = 0; i < nCols; i++) { diff --git a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java index 791064425..3a717ff83 100644 --- a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -776,7 +776,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable { if (v.length != nCols) { throw new IllegalArgumentException("vector has wrong length"); } - final double[] out = new double[v.length]; + final double[] out = new double[nRows]; for (int row = 0; row < nRows; row++) { final double[] dataRow = data[row]; double sum = 0; diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 7b76af9ad..3a61b1d7b 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,10 @@ The type attribute can be add,update,fix,remove. + + Fixed dimension error on output vector for the operate method + in RealMatrixImpl and BigMatrixImpl classes. + The FirstOrderDifferentialEquations and FirstOrderIntegrator interfaces now extends Serializable, allowing integrators and diff --git a/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java b/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java index f30e04b9c..2f52c3508 100644 --- a/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java +++ b/src/test/org/apache/commons/math/linear/BigMatrixImplTest.java @@ -435,6 +435,20 @@ public final class BigMatrixImplTest extends TestCase { ; } } + + /** test issue MATH-209 */ + public void testMath209() { + BigMatrix a = new BigMatrixImpl(new BigDecimal[][] { + { new BigDecimal(1), new BigDecimal(2) }, + { new BigDecimal(3), new BigDecimal(4) }, + { new BigDecimal(5), new BigDecimal(6) } + }, false); + BigDecimal[] b = a.operate(new BigDecimal[] { new BigDecimal(1), new BigDecimal(1) }); + assertEquals(a.getRowDimension(), b.length); + assertEquals( 3.0, b[0].doubleValue(), 1.0e-12); + assertEquals( 7.0, b[1].doubleValue(), 1.0e-12); + assertEquals(11.0, b[2].doubleValue(), 1.0e-12); + } /** test transpose */ public void testTranspose() { diff --git a/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java b/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java index 7553f3675..383a9598e 100644 --- a/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java +++ b/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java @@ -342,6 +342,18 @@ public final class RealMatrixImplTest extends TestCase { ; } } + + /** test issue MATH-209 */ + public void testMath209() { + RealMatrix a = new RealMatrixImpl(new double[][] { + { 1, 2 }, { 3, 4 }, { 5, 6 } + }, false); + double[] b = a.operate(new double[] { 1, 1 }); + assertEquals(a.getRowDimension(), b.length); + assertEquals( 3.0, b[0], 1.0e-12); + assertEquals( 7.0, b[1], 1.0e-12); + assertEquals(11.0, b[2], 1.0e-12); + } /** test transpose */ public void testTranspose() {