fixed dimension error in operate method for RealMatrixImpl and BigMatrixImpl

JIRA: MATH-209

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@668798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-06-17 19:09:36 +00:00
parent 87e066ad31
commit 6f4e48d42a
5 changed files with 32 additions and 2 deletions

View File

@ -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++) {

View File

@ -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;

View File

@ -39,6 +39,10 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="MATH-209" due-to="Thomas Chust">
Fixed dimension error on output vector for the operate method
in RealMatrixImpl and BigMatrixImpl classes.
</action>
<action dev="luc" type="update">
The FirstOrderDifferentialEquations and FirstOrderIntegrator
interfaces now extends Serializable, allowing integrators and

View File

@ -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() {

View File

@ -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() {