fixed a number of warnings identified by findbugs eclipse plugin version 1.3.9

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@790243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-07-01 16:03:28 +00:00
parent 1a5345519c
commit 63d0a79ce2
34 changed files with 250 additions and 267 deletions

View File

@ -43,6 +43,23 @@
</Or> </Or>
<Bug pattern="FE_FLOATING_POINT_EQUALITY" /> <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
</Match> </Match>
<Match>
<Class name="org.apache.commons.math.linear.EigenDecompositionImpl" />
<Method name="computeShiftIncrement" params="int,int,int" returns="void" />
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
</Match>
<!-- The following equality test is intentional and needed for semantic purposes -->
<Match>
<Class name="org.apache.commons.math.geometry.Vector3D" />
<Method name="equals" params="java.lang.Object" returns="boolean" />
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
</Match>
<Match>
<Class name="org.apache.commons.math.optimization.linear.LinearConstraint" />
<Method name="equals" params="java.lang.Object" returns="boolean" />
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
</Match>
<!-- The following equality test is intentional and needed for rounding purposes --> <!-- The following equality test is intentional and needed for rounding purposes -->
<Match> <Match>

View File

@ -148,7 +148,7 @@ public abstract class RandomKey<T> extends AbstractListChromosome<Double> implem
@Override @Override
protected boolean isSame(Chromosome another) { protected boolean isSame(Chromosome another) {
// type check // type check
if (! (another instanceof RandomKey)) if (! (another instanceof RandomKey<?>))
return false; return false;
RandomKey<?> anotherRk = (RandomKey<?>) another; RandomKey<?> anotherRk = (RandomKey<?>) another;
// size check // size check

View File

@ -37,7 +37,7 @@ public class RandomKeyMutation implements MutationPolicy {
* {@link RandomKey} instance * {@link RandomKey} instance
*/ */
public Chromosome mutate(Chromosome original) { public Chromosome mutate(Chromosome original) {
if (!(original instanceof RandomKey)) { if (!(original instanceof RandomKey<?>)) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"RandomKeyMutation works only with RandomKeys, got " + "RandomKeyMutation works only with RandomKeys, got " +
original.getClass().getSimpleName()); original.getClass().getSimpleName());

View File

@ -181,7 +181,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */ /** {@inheritDoc} */
public FieldVector<T> append(FieldVector<T> v) { public FieldVector<T> append(FieldVector<T> v) {
if (v instanceof SparseFieldVector) { if (v instanceof SparseFieldVector<?>) {
return append((SparseFieldVector<T>) v); return append((SparseFieldVector<T>) v);
} else { } else {
return append(v.toArray()); return append(v.toArray());
@ -438,7 +438,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */ /** {@inheritDoc} */
public FieldMatrix<T> outerProduct(FieldVector<T> v) public FieldMatrix<T> outerProduct(FieldVector<T> v)
throws IllegalArgumentException { throws IllegalArgumentException {
if(v instanceof SparseFieldVector) if(v instanceof SparseFieldVector<?>)
return outerProduct((SparseFieldVector<T>)v); return outerProduct((SparseFieldVector<T>)v);
else else
return outerProduct(v.toArray()); return outerProduct(v.toArray());
@ -513,7 +513,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */ /** {@inheritDoc} */
public FieldVector<T> subtract(FieldVector<T> v) public FieldVector<T> subtract(FieldVector<T> v)
throws IllegalArgumentException { throws IllegalArgumentException {
if(v instanceof SparseFieldVector) if(v instanceof SparseFieldVector<?>)
return subtract((SparseFieldVector<T>)v); return subtract((SparseFieldVector<T>)v);
else else
return subtract(v.toArray()); return subtract(v.toArray());
@ -573,7 +573,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */ /** {@inheritDoc} */
public FieldVector<T> add(FieldVector<T> v) throws IllegalArgumentException { public FieldVector<T> add(FieldVector<T> v) throws IllegalArgumentException {
if (v instanceof SparseFieldVector) { if (v instanceof SparseFieldVector<?>) {
return add((SparseFieldVector<T>)v); return add((SparseFieldVector<T>)v);
} else { } else {
return add(v.toArray()); return add(v.toArray());

View File

@ -613,11 +613,8 @@ public class FastFourierTransformer implements Serializable {
* http://jcp.org/en/jsr/detail?id=83 * http://jcp.org/en/jsr/detail?id=83
* may require additional exception throws for other basic requirements. * may require additional exception throws for other basic requirements.
*/ */
private class MultiDimensionalComplexMatrix private static class MultiDimensionalComplexMatrix
implements Serializable, Cloneable { implements Cloneable {
/** Serializable version identifier. */
private static final long serialVersionUID = 0x564FCD47EBA8169BL;
/** Size in all dimensions. */ /** Size in all dimensions. */
protected int[] dimensionSize; protected int[] dimensionSize;

View File

@ -338,20 +338,20 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
* expansionCriteria * expansionCriteria
* *
* @param expansionFactor factor to be checked * @param expansionFactor factor to be checked
* @param contractionCritera criteria to be checked * @param contractionCriteria criteria to be checked
* @throws IllegalArgumentException if the contractionCriteria is less than * @throws IllegalArgumentException if the contractionCriteria is less than
* the expansionCriteria. * the expansionCriteria.
*/ */
protected void checkContractExpand( protected void checkContractExpand(
float contractionCritera, float contractionCriteria,
float expansionFactor) { float expansionFactor) {
if (contractionCritera < expansionFactor) { if (contractionCriteria < expansionFactor) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"contraction criteria ({0}) smaller than the expansion factor ({1}). This would " + "contraction criteria ({0}) smaller than the expansion factor ({1}). This would " +
"lead to a never ending loop of expansion and contraction as a newly expanded " + "lead to a never ending loop of expansion and contraction as a newly expanded " +
"internal storage array would immediately satisfy the criteria for contraction", "internal storage array would immediately satisfy the criteria for contraction",
contractionCritera, expansionFactor); contractionCriteria, expansionFactor);
} }
if (contractionCriteria <= 1.0) { if (contractionCriteria <= 1.0) {
@ -365,7 +365,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
if (expansionFactor <= 1.0) { if (expansionFactor <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"expansion factor smaller than one ({0})", "expansion factor smaller than one ({0})",
contractionCriteria); expansionFactor);
} }
} }
@ -648,7 +648,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
public void setContractionCriteria(float contractionCriteria) { public void setContractionCriteria(float contractionCriteria) {
checkContractExpand(contractionCriteria, getExpansionFactor()); checkContractExpand(contractionCriteria, getExpansionFactor());
this.contractionCriteria = contractionCriteria; synchronized(this) {
this.contractionCriteria = contractionCriteria;
}
} }
@ -693,7 +695,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
public void setExpansionFactor(float expansionFactor) { public void setExpansionFactor(float expansionFactor) {
checkContractExpand(getContractionCriteria(), expansionFactor); checkContractExpand(getContractionCriteria(), expansionFactor);
// The check above verifies that the expansion factor is > 1.0; // The check above verifies that the expansion factor is > 1.0;
this.expansionFactor = expansionFactor; synchronized(this) {
this.expansionFactor = expansionFactor;
}
} }
/** /**
@ -711,7 +715,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE",
ADDITIVE_MODE, "ADDITIVE_MODE"); ADDITIVE_MODE, "ADDITIVE_MODE");
} }
this.expansionMode = expansionMode; synchronized(this) {
this.expansionMode = expansionMode;
}
} }
/** /**
@ -876,17 +882,15 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
* @since 2.0 * @since 2.0
*/ */
@Override @Override
public int hashCode() { public synchronized int hashCode() {
int[] hashData = new int[7]; int[] hashData = new int[7];
hashData[0] = new Float(expansionFactor).hashCode(); hashData[0] = new Float(expansionFactor).hashCode();
hashData[1] = new Float(contractionCriteria).hashCode(); hashData[1] = new Float(contractionCriteria).hashCode();
hashData[2] = expansionMode; hashData[2] = expansionMode;
synchronized(this) {
hashData[3] = Arrays.hashCode(internalArray); hashData[3] = Arrays.hashCode(internalArray);
hashData[4] = initialCapacity; hashData[4] = initialCapacity;
hashData[5] = numElements; hashData[5] = numElements;
hashData[6] = startIndex; hashData[6] = startIndex;
}
return Arrays.hashCode(hashData); return Arrays.hashCode(hashData);
} }

View File

@ -793,18 +793,6 @@ public class LevenbergMarquardtEstimatorTest
addMeasurement(new LocalMeasurement(x, y, w)); addMeasurement(new LocalMeasurement(x, y, w));
} }
public double getA() {
return a.getEstimate();
}
public double getB() {
return b.getEstimate();
}
public double getC() {
return c.getEstimate();
}
public double theoreticalValue(double x) { public double theoreticalValue(double x) {
return ( (a.getEstimate() * x + b.getEstimate() ) * x + c.getEstimate()); return ( (a.getEstimate() * x + b.getEstimate() ) * x + c.getEstimate());
} }

View File

@ -28,14 +28,12 @@ public class RandomKeyTest {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testConstructor1() { public void testConstructor1() {
@SuppressWarnings("unused") new DummyRandomKey(new Double[] {0.2, 0.3, 1.2});
DummyRandomKey drk = new DummyRandomKey(new Double[] {0.2, 0.3, 1.2});
} }
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testConstructor2() { public void testConstructor2() {
@SuppressWarnings("unused") new DummyRandomKey(new Double[] {0.2, 0.3, -0.2});
DummyRandomKey drk = new DummyRandomKey(new Double[] {0.2, 0.3, -0.2});
} }
@Test @Test

View File

@ -549,50 +549,50 @@ public final class BlockFieldMatrixTest extends TestCase {
// test submatrix accessors // test submatrix accessors
public void testGetSubMatrix() { public void testGetSubMatrix() {
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData); FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0);
checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3);
checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3);
checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, -1, 1, 2, 2, true); checkGetSubMatrix(m, null, -1, 1, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 2, true); checkGetSubMatrix(m, null, 1, 0, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 });
checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
FieldMatrix<Fraction> sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); FieldMatrix<Fraction> sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
assertEquals(new BlockFieldMatrix<Fraction>(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new BlockFieldMatrix<Fraction>(reference), sub);
} else {
fail("Expecting MatrixIndexException"); fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
FieldMatrix<Fraction> sub = m.getSubMatrix(selectedRows, selectedColumns); FieldMatrix<Fraction> sub = m.getSubMatrix(selectedRows, selectedColumns);
assertEquals(new BlockFieldMatrix<Fraction>(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new BlockFieldMatrix<Fraction>(reference), sub);
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
@ -621,57 +621,57 @@ public final class BlockFieldMatrixTest extends TestCase {
public void testCopySubMatrix() { public void testCopySubMatrix() {
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData); FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0);
checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3);
checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3);
checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, -1, 1, 2, 2, true); checkCopy(m, null, -1, 1, 2, 2);
checkCopy(m, null, 1, 0, 2, 2, true); checkCopy(m, null, 1, 0, 2, 2);
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, new int[] {}, new int[] { 0 }, true); checkCopy(m, null, new int[] {}, new int[] { 0 });
checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); checkCopy(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
Fraction[][] sub = (reference == null) ? Fraction[][] sub = (reference == null) ?
new Fraction[1][1] : new Fraction[1][1] :
new Fraction[reference.length][reference[0].length]; new Fraction[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub)); if (reference != null) {
if (mustFail) { assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
Fraction[][] sub = (reference == null) ? Fraction[][] sub = (reference == null) ?
new Fraction[1][1] : new Fraction[1][1] :
new Fraction[reference.length][reference[0].length]; new Fraction[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub); m.copySubMatrix(selectedRows, selectedColumns, sub);
assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub)); if (reference != null) {
if (mustFail) { assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }

View File

@ -476,50 +476,50 @@ public final class BlockRealMatrixTest extends TestCase {
// test submatrix accessors // test submatrix accessors
public void testGetSubMatrix() { public void testGetSubMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData); RealMatrix m = new BlockRealMatrix(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0);
checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3);
checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3);
checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, -1, 1, 2, 2, true); checkGetSubMatrix(m, null, -1, 1, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 2, true); checkGetSubMatrix(m, null, 1, 0, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 });
checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkGetSubMatrix(RealMatrix m, double[][] reference, private void checkGetSubMatrix(RealMatrix m, double[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
assertEquals(new BlockRealMatrix(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new BlockRealMatrix(reference), sub);
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkGetSubMatrix(RealMatrix m, double[][] reference, private void checkGetSubMatrix(RealMatrix m, double[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns); RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
assertEquals(new BlockRealMatrix(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new BlockRealMatrix(reference), sub);
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
@ -546,57 +546,57 @@ public final class BlockRealMatrixTest extends TestCase {
public void testCopySubMatrix() { public void testCopySubMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData); RealMatrix m = new BlockRealMatrix(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0);
checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3);
checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3);
checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, -1, 1, 2, 2, true); checkCopy(m, null, -1, 1, 2, 2);
checkCopy(m, null, 1, 0, 2, 2, true); checkCopy(m, null, 1, 0, 2, 2);
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, new int[] {}, new int[] { 0 }, true); checkCopy(m, null, new int[] {}, new int[] { 0 });
checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); checkCopy(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkCopy(RealMatrix m, double[][] reference, private void checkCopy(RealMatrix m, double[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
double[][] sub = (reference == null) ? double[][] sub = (reference == null) ?
new double[1][1] : new double[1][1] :
new double[reference.length][reference[0].length]; new double[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); if (reference != null) {
if (mustFail) { assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkCopy(RealMatrix m, double[][] reference, private void checkCopy(RealMatrix m, double[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
double[][] sub = (reference == null) ? double[][] sub = (reference == null) ?
new double[1][1] : new double[1][1] :
new double[reference.length][reference[0].length]; new double[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub); m.copySubMatrix(selectedRows, selectedColumns, sub);
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); if (reference != null) {
if (mustFail) { assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }

View File

@ -293,13 +293,13 @@ public class EigenDecompositionImplTest extends TestCase {
boolean found = false; boolean found = false;
int i = 0; int i = 0;
while (!found && i < searchMatrix.getColumnDimension()) { while (!found && i < searchMatrix.getColumnDimension()) {
double multiplier = 1d; double multiplier = 1.0;
boolean matching = true; boolean matching = true;
int j = 0; int j = 0;
while (matching && j < searchMatrix.getRowDimension()) { while (matching && j < searchMatrix.getRowDimension()) {
double colEntry = searchMatrix.getEntry(j, i); double colEntry = searchMatrix.getEntry(j, i);
// Use the first entry where both are non-zero as scalar // Use the first entry where both are non-zero as scalar
if (multiplier == 1d && Math.abs(colEntry) > 1E-14 if (Math.abs(multiplier - 1.0) <= Math.ulp(1.0) && Math.abs(colEntry) > 1E-14
&& Math.abs(column[j]) > 1e-14) { && Math.abs(column[j]) > 1e-14) {
multiplier = colEntry / column[j]; multiplier = colEntry / column[j];
} }

View File

@ -363,50 +363,50 @@ public final class FieldMatrixImplTest extends TestCase {
// test submatrix accessors // test submatrix accessors
public void testGetSubMatrix() { public void testGetSubMatrix() {
FieldMatrix<Fraction> m = new Array2DRowFieldMatrix<Fraction>(subTestData); FieldMatrix<Fraction> m = new Array2DRowFieldMatrix<Fraction>(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0);
checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3);
checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3);
checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, -1, 1, 2, 2, true); checkGetSubMatrix(m, null, -1, 1, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 2, true); checkGetSubMatrix(m, null, 1, 0, 2, 2);
checkGetSubMatrix(m, null, 1, 0, 2, 4, true); checkGetSubMatrix(m, null, 1, 0, 2, 4);
checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 });
checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
FieldMatrix<Fraction> sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); FieldMatrix<Fraction> sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), sub);
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkGetSubMatrix(FieldMatrix<Fraction> m, Fraction[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
FieldMatrix<Fraction> sub = m.getSubMatrix(selectedRows, selectedColumns); FieldMatrix<Fraction> sub = m.getSubMatrix(selectedRows, selectedColumns);
assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), sub); if (reference != null) {
if (mustFail) { assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), sub);
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
@ -414,57 +414,57 @@ public final class FieldMatrixImplTest extends TestCase {
public void testCopySubMatrix() { public void testCopySubMatrix() {
FieldMatrix<Fraction> m = new Array2DRowFieldMatrix<Fraction>(subTestData); FieldMatrix<Fraction> m = new Array2DRowFieldMatrix<Fraction>(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0);
checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3);
checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3);
checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 });
checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 });
checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 });
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, -1, 1, 2, 2, true); checkCopy(m, null, -1, 1, 2, 2);
checkCopy(m, null, 1, 0, 2, 2, true); checkCopy(m, null, 1, 0, 2, 2);
checkCopy(m, null, 1, 0, 2, 4, true); checkCopy(m, null, 1, 0, 2, 4);
checkCopy(m, null, new int[] {}, new int[] { 0 }, true); checkCopy(m, null, new int[] {}, new int[] { 0 });
checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); checkCopy(m, null, new int[] { 0 }, new int[] { 4 });
} }
private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference,
int startRow, int endRow, int startColumn, int endColumn, int startRow, int endRow, int startColumn, int endColumn) {
boolean mustFail) {
try { try {
Fraction[][] sub = (reference == null) ? Fraction[][] sub = (reference == null) ?
new Fraction[1][1] : new Fraction[1][1] :
new Fraction[reference.length][reference[0].length]; new Fraction[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), new Array2DRowFieldMatrix<Fraction>(sub)); if (reference != null) {
if (mustFail) { assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), new Array2DRowFieldMatrix<Fraction>(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }
} }
private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference, private void checkCopy(FieldMatrix<Fraction> m, Fraction[][] reference,
int[] selectedRows, int[] selectedColumns, int[] selectedRows, int[] selectedColumns) {
boolean mustFail) {
try { try {
Fraction[][] sub = (reference == null) ? Fraction[][] sub = (reference == null) ?
new Fraction[1][1] : new Fraction[1][1] :
new Fraction[reference.length][reference[0].length]; new Fraction[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub); m.copySubMatrix(selectedRows, selectedColumns, sub);
assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), new Array2DRowFieldMatrix<Fraction>(sub)); if (reference != null) {
if (mustFail) { assertEquals(new Array2DRowFieldMatrix<Fraction>(reference), new Array2DRowFieldMatrix<Fraction>(sub));
fail("Expecting MatrixIndexException"); } else {
fail("Expecting MatrixIndexException");
} }
} catch (MatrixIndexException e) { } catch (MatrixIndexException e) {
if (!mustFail) { if (reference != null) {
throw e; throw e;
} }
} }

View File

@ -149,11 +149,11 @@ public class SparseFieldMatrixTest extends TestCase {
public void testCopyFunctions() { public void testCopyFunctions() {
SparseFieldMatrix<Fraction> m1 = createSparseMatrix(testData); SparseFieldMatrix<Fraction> m1 = createSparseMatrix(testData);
FieldMatrix<Fraction> m2 = m1.copy(); FieldMatrix<Fraction> m2 = m1.copy();
assertTrue(m2 instanceof SparseFieldMatrix); assertEquals(m1.getClass(), m2.getClass());
assertEquals((m2), m1); assertEquals((m2), m1);
SparseFieldMatrix<Fraction> m3 = createSparseMatrix(testData); SparseFieldMatrix<Fraction> m3 = createSparseMatrix(testData);
FieldMatrix<Fraction> m4 = m3.copy(); FieldMatrix<Fraction> m4 = m3.copy();
assertTrue(m4 instanceof SparseFieldMatrix); assertEquals(m3.getClass(), m4.getClass());
assertEquals((m4), m3); assertEquals((m4), m3);
} }

View File

@ -130,11 +130,11 @@ public final class SparseRealMatrixTest extends TestCase {
public void testCopyFunctions() { public void testCopyFunctions() {
OpenMapRealMatrix m1 = createSparseMatrix(testData); OpenMapRealMatrix m1 = createSparseMatrix(testData);
RealMatrix m2 = m1.copy(); RealMatrix m2 = m1.copy();
assertTrue(m2 instanceof OpenMapRealMatrix); assertEquals(m1.getClass(), m2.getClass());
assertEquals((m2), m1); assertEquals((m2), m1);
OpenMapRealMatrix m3 = createSparseMatrix(testData); OpenMapRealMatrix m3 = createSparseMatrix(testData);
RealMatrix m4 = m3.copy(); RealMatrix m4 = m3.copy();
assertTrue(m4 instanceof OpenMapRealMatrix); assertEquals(m3.getClass(), m4.getClass());
assertEquals((m4), m3); assertEquals((m4), m3);
} }

View File

@ -62,12 +62,8 @@ public class TestProblem1
y = problem.y.clone(); y = problem.y.clone();
} }
/** /** {@inheritDoc} */
* Clone operation. public TestProblem1 copy() {
* @return a copy of the instance
*/
@Override
public Object clone() {
return new TestProblem1(this); return new TestProblem1(this);
} }

View File

@ -63,12 +63,8 @@ public class TestProblem2
y = problem.y.clone(); y = problem.y.clone();
} }
/** /** {@inheritDoc} */
* Clone operation. public TestProblem2 copy() {
* @return a copy of the instance
*/
@Override
public Object clone() {
return new TestProblem2(this); return new TestProblem2(this);
} }

View File

@ -78,12 +78,8 @@ public class TestProblem3
y = problem.y.clone(); y = problem.y.clone();
} }
/** /** {@inheritDoc} */
* Clone operation. public TestProblem3 copy() {
* @return a copy of the instance
*/
@Override
public Object clone() {
return new TestProblem3(this); return new TestProblem3(this);
} }

View File

@ -68,12 +68,8 @@ public class TestProblem4
y = problem.y.clone(); y = problem.y.clone();
} }
/** /** {@inheritDoc} */
* Clone operation. public TestProblem4 copy() {
* @return a copy of the instance
*/
@Override
public Object clone() {
return new TestProblem4(this); return new TestProblem4(this);
} }

View File

@ -36,4 +36,8 @@ public class TestProblem5
setFinalConditions(2 * t0 - t1); setFinalConditions(2 * t0 - t1);
} }
/** {@inheritDoc} */
public TestProblem5 copy() {
return new TestProblem5();
}
} }

View File

@ -63,13 +63,9 @@ public class TestProblem6
y = problem.y.clone(); y = problem.y.clone();
} }
/** /** {@inheritDoc} */
* Clone operation. public TestProblem6 copy() {
* @return a copy of the instance return new TestProblem6(this);
*/
@Override
public Object clone() {
return new TestProblem6(this);
} }
@Override @Override

View File

@ -25,7 +25,7 @@ import org.apache.commons.math.ode.events.EventHandler;
* integrated during the junit tests for the ODE integrators. * integrated during the junit tests for the ODE integrators.
*/ */
public abstract class TestProblemAbstract public abstract class TestProblemAbstract
implements FirstOrderDifferentialEquations, Cloneable { implements FirstOrderDifferentialEquations {
/** Serializable version identifier. */ /** Serializable version identifier. */
private static final long serialVersionUID = -8521928974502839379L; private static final long serialVersionUID = -8521928974502839379L;
@ -82,11 +82,10 @@ public abstract class TestProblemAbstract
} }
/** /**
* Clone operation. * Copy operation.
* @return a copy of the instance * @return a copy of the instance
*/ */
@Override public abstract TestProblemAbstract copy();
public abstract Object clone();
/** /**
* Set the initial conditions * Set the initial conditions

View File

@ -83,7 +83,7 @@ public class ClassicalRungeKuttaIntegratorTest
double previousError = Double.NaN; double previousError = Double.NaN;
for (int i = 4; i < 10; ++i) { for (int i = 4; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); TestProblemAbstract pb = problems[k].copy();
double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);

View File

@ -230,7 +230,7 @@ public class DormandPrince853IntegratorTest
public void testNoDenseOutput() public void testNoDenseOutput()
throws DerivativeException, IntegratorException { throws DerivativeException, IntegratorException {
TestProblem1 pb1 = new TestProblem1(); TestProblem1 pb1 = new TestProblem1();
TestProblem1 pb2 = (TestProblem1) pb1.clone(); TestProblem1 pb2 = pb1.copy();
double minStep = 0.1 * (pb1.getFinalTime() - pb1.getInitialTime()); double minStep = 0.1 * (pb1.getFinalTime() - pb1.getInitialTime());
double maxStep = pb1.getFinalTime() - pb1.getInitialTime(); double maxStep = pb1.getFinalTime() - pb1.getInitialTime();
double scalAbsoluteTolerance = 1.0e-4; double scalAbsoluteTolerance = 1.0e-4;

View File

@ -62,7 +62,7 @@ public class EulerIntegratorTest
double previousError = Double.NaN; double previousError = Double.NaN;
for (int i = 4; i < 10; ++i) { for (int i = 4; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); TestProblemAbstract pb = problems[k].copy();
double step = (pb.getFinalTime() - pb.getInitialTime()) double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -i); * Math.pow(2.0, -i);

View File

@ -63,7 +63,7 @@ public class GillIntegratorTest
double previousError = Double.NaN; double previousError = Double.NaN;
for (int i = 5; i < 10; ++i) { for (int i = 5; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); TestProblemAbstract pb = problems[k].copy();
double step = (pb.getFinalTime() - pb.getInitialTime()) double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -i); * Math.pow(2.0, -i);

View File

@ -62,7 +62,7 @@ public class MidpointIntegratorTest
double previousError = Double.NaN; double previousError = Double.NaN;
for (int i = 4; i < 10; ++i) { for (int i = 4; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); TestProblemAbstract pb = problems[k].copy();
double step = (pb.getFinalTime() - pb.getInitialTime()) double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new MidpointIntegrator(step); FirstOrderIntegrator integ = new MidpointIntegrator(step);

View File

@ -63,7 +63,7 @@ public class ThreeEighthesIntegratorTest
double previousError = Double.NaN; double previousError = Double.NaN;
for (int i = 4; i < 10; ++i) { for (int i = 4; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); TestProblemAbstract pb = problems[k].copy();
double step = (pb.getFinalTime() - pb.getInitialTime()) double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -i); * Math.pow(2.0, -i);

View File

@ -128,15 +128,15 @@ public class DummyStepInterpolatorTest {
} }
private static class BadStepInterpolator extends DummyStepInterpolator { private static class BadStepInterpolator extends DummyStepInterpolator {
public BadStepInterpolator() { @SuppressWarnings("unused")
super(); public BadStepInterpolator() {
} }
public BadStepInterpolator(double[] y, boolean forward) { public BadStepInterpolator(double[] y, boolean forward) {
super(y, forward); super(y, forward);
} }
@Override @Override
protected void doFinalize() protected void doFinalize()
throws DerivativeException { throws DerivativeException {
throw new DerivativeException(null); throw new DerivativeException(null);
} }
} }

View File

@ -59,7 +59,7 @@ public class MultiStartMultivariateRealOptimizerTest {
} }
private class Rosenbrock implements MultivariateRealFunction { private static class Rosenbrock implements MultivariateRealFunction {
private int count; private int count;

View File

@ -204,7 +204,7 @@ public class NelderMeadTest {
} }
} }
private class Rosenbrock implements MultivariateRealFunction { private static class Rosenbrock implements MultivariateRealFunction {
private int count; private int count;
@ -225,7 +225,7 @@ public class NelderMeadTest {
} }
private class Powell implements MultivariateRealFunction { private static class Powell implements MultivariateRealFunction {
private int count; private int count;

View File

@ -434,8 +434,7 @@ public class LevenbergMarquardtOptimizerTest
Arrays.fill(target, 0.0); Arrays.fill(target, 0.0);
double[] weights = new double[circle.getN()]; double[] weights = new double[circle.getN()];
Arrays.fill(weights, 2.0); Arrays.fill(weights, 2.0);
optimum = optimizer.optimize(circle, target, weights, new double[] { 98.680, 47.345 });
optimizer.optimize(circle, target, weights, new double[] { 98.680, 47.345 });
cov = optimizer.getCovariances(); cov = optimizer.getCovariances();
assertEquals(0.0016, cov[0][0], 0.001); assertEquals(0.0016, cov[0][0], 0.001);
assertEquals(3.2e-7, cov[0][1], 1.0e-9); assertEquals(3.2e-7, cov[0][1], 1.0e-9);

View File

@ -429,10 +429,6 @@ extends TestCase {
points.add(new Point2D.Double(px, py)); points.add(new Point2D.Double(px, py));
} }
public int getN() {
return points.size();
}
public double getRadius(Point2D.Double center) { public double getRadius(Point2D.Double center) {
double r = 0; double r = 0;
for (Point2D.Double point : points) { for (Point2D.Double point : points) {

View File

@ -199,5 +199,6 @@ public class NaturalRankingTest extends TestCase {
ranking = new NaturalRanking(NaNStrategy.MINIMAL); ranking = new NaturalRanking(NaNStrategy.MINIMAL);
ranks = ranking.rank(data); ranks = ranking.rank(data);
correctRanks = new double[] { 3, 4, 1.5, 1.5 }; correctRanks = new double[] { 3, 4, 1.5, 1.5 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
} }
} }

View File

@ -52,7 +52,7 @@ public final class MathUtilsTest extends TestCase {
*/ */
private long binomialCoefficient(int n, int k) throws ArithmeticException { private long binomialCoefficient(int n, int k) throws ArithmeticException {
if (binomialCache.size() > n) { if (binomialCache.size() > n) {
Long cachedResult = binomialCache.get(n).get(new Integer(k)); Long cachedResult = binomialCache.get(n).get(Integer.valueOf(k));
if (cachedResult != null) { if (cachedResult != null) {
return cachedResult.longValue(); return cachedResult.longValue();
} }
@ -80,7 +80,7 @@ public final class MathUtilsTest extends TestCase {
for (int i = binomialCache.size(); i < n + 1; i++) { for (int i = binomialCache.size(); i < n + 1; i++) {
binomialCache.add(new HashMap<Integer, Long>()); binomialCache.add(new HashMap<Integer, Long>());
} }
binomialCache.get(n).put(new Integer(k), new Long(result)); binomialCache.get(n).put(Integer.valueOf(k), Long.valueOf(result));
return result; return result;
} }