MATH-653
Renamed "AbstracRealVector" to "RealVector" (getting rid of the "interface"). Changed "SparseRealVector" from "interface" to "abstract" class. Modified subclasses ("extends" instead of "implements") and unit test name ("RealVectorTest" instead of "AbstractRealVectorTest") accordingly. Slightly modified "UnmodifiableRealVectorAbstractTest" to exclude methods that are now inherited from "Object". Changed unmodifiable vector view from a static inner class to an anonymous class. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1162511 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2570afd5f
commit
760078b411
File diff suppressed because it is too large
Load Diff
|
@ -34,7 +34,7 @@ import org.apache.commons.math.util.FastMath;
|
|||
* @version $Id$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ArrayRealVector extends AbstractRealVector implements Serializable {
|
||||
public class ArrayRealVector extends RealVector implements Serializable {
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -1097961340710804027L;
|
||||
/** Default format. */
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.apache.commons.math.util.FastMath;
|
|||
* @version $Id$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class OpenMapRealVector extends AbstractRealVector
|
||||
implements SparseRealVector, Serializable {
|
||||
public class OpenMapRealVector extends SparseRealVector
|
||||
implements Serializable {
|
||||
/** Default Tolerance for having a value considered zero. */
|
||||
public static final double DEFAULT_ZERO_TOLERANCE = 1.0e-12;
|
||||
/** Serializable version identifier. */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,11 +17,9 @@
|
|||
package org.apache.commons.math.linear;
|
||||
|
||||
/**
|
||||
* Marker interface for RealVectors that require sparse backing storage
|
||||
* Marker class for RealVectors that require sparse backing storage
|
||||
* @version $Id$
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public interface SparseRealVector extends RealVector {
|
||||
|
||||
}
|
||||
public abstract class SparseRealVector extends RealVector {}
|
||||
|
|
|
@ -52,6 +52,13 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
If the output is not quite correct, check for invisible trailing spaces!
|
||||
-->
|
||||
<release version="3.0" date="TBD" description="TBD">
|
||||
<action dev="erans" type="fix" issue="MATH-653">
|
||||
Renamed "AbstractRealVector" to "RealVector". The interface was removed
|
||||
in favour of its unique (abstract) implementation.
|
||||
</action>
|
||||
<action dev="erans" type="add" issue="MATH-646" due-to="Sébastien Brisard">
|
||||
Unmodifiable view of a "RealVector".
|
||||
</action>
|
||||
<action dev="luc" type="fix" issue="MATH-501" >
|
||||
Refactored integration API for consistency with solvers API. Now the main convergence
|
||||
parameters are set in the constructor and remain fixed.
|
||||
|
|
|
@ -78,7 +78,8 @@ public class ArrayRealVectorTest {
|
|||
|
||||
// Testclass to test the RealVector interface
|
||||
// only with enough content to support the test
|
||||
public static class RealVectorTestImpl implements RealVector, Serializable {
|
||||
public static class RealVectorTestImpl extends RealVector
|
||||
implements Serializable {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 4715341047369582908L;
|
||||
|
|
|
@ -26,13 +26,13 @@ import java.util.Iterator;
|
|||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tests for {@link RealVector}.
|
||||
*/
|
||||
public class AbstractRealVectorTest {
|
||||
public class RealVectorTest {
|
||||
private double[] vec1 = { 1d, 2d, 3d, 4d, 5d };
|
||||
private double[] vec2 = { -3d, 0d, 0d, 2d, 1d };
|
||||
|
||||
private static class TestVectorImpl extends AbstractRealVector {
|
||||
private static class TestVectorImpl extends RealVector {
|
||||
private double[] values;
|
||||
|
||||
TestVectorImpl(double[] values) {
|
||||
|
@ -43,11 +43,10 @@ public class AbstractRealVectorTest {
|
|||
public double[] getData() { return values; }
|
||||
|
||||
@Override
|
||||
public AbstractRealVector copy() {
|
||||
public RealVector copy() {
|
||||
return new TestVectorImpl(values.clone());
|
||||
}
|
||||
|
||||
|
||||
UnsupportedOperationException unsupported() {
|
||||
return new UnsupportedOperationException("Test implementation only supports methods necessary for testing");
|
||||
}
|
||||
|
@ -156,6 +155,13 @@ public class AbstractRealVectorTest {
|
|||
throw unsupported();
|
||||
}
|
||||
|
||||
public void setSubVector(int index, double[] v) {
|
||||
throw unsupported();
|
||||
}
|
||||
public void setSubVector(int index, RealVector v) {
|
||||
throw unsupported();
|
||||
}
|
||||
|
||||
public boolean isNaN() {
|
||||
throw unsupported();
|
||||
}
|
|
@ -76,7 +76,7 @@ public class SparseRealVectorTest {
|
|||
|
||||
// Testclass to test the RealVector interface
|
||||
// only with enough content to support the test
|
||||
public static class SparseRealVectorTestImpl extends AbstractRealVector implements Serializable {
|
||||
public static class SparseRealVectorTestImpl extends RealVector implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6251371752518113791L;
|
||||
/** Entries of the vector. */
|
||||
|
@ -106,7 +106,7 @@ public class SparseRealVectorTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractRealVector copy() {
|
||||
public RealVector copy() {
|
||||
return new SparseRealVectorTestImpl(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ package org.apache.commons.math.linear;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -31,10 +32,12 @@ import org.apache.commons.math.linear.RealVector.Entry;
|
|||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This is an abstract test of the {@link AbstractRealVector.UnmodifiableVector}
|
||||
* This is an abstract test of the {@link
|
||||
* RealVector#unmodifiableRealVector(RealVector) unmodifiable vector}
|
||||
* implementation. These unmodifiable vectors decorate a (modifiable)
|
||||
* {@link RealVector}; therefore, a new implementation of this abstract test
|
||||
* should be considered for each implementation of {@link RealVector}.
|
||||
* {@link RealVector}; therefore, a new implementation of this abstract
|
||||
* test should be considered for each implementation of
|
||||
* {@link RealVector}.
|
||||
*
|
||||
* @version $Id$
|
||||
*
|
||||
|
@ -48,18 +51,22 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
* The list of methods which are excluded from the general test
|
||||
* {@link #testAllButExcluded()}.
|
||||
*/
|
||||
protected static final ArrayList<String> EXCLUDE;
|
||||
protected static final Set<String> EXCLUDE = new HashSet<String>();
|
||||
/** The random number generator (always initialized with the same seed. */
|
||||
protected static final Random RANDOM;
|
||||
|
||||
static {
|
||||
EXCLUDE = new ArrayList<String>();
|
||||
EXCLUDE.add("getEntry");
|
||||
EXCLUDE.add("setEntry");
|
||||
EXCLUDE.add("getSubVector");
|
||||
EXCLUDE.add("setSubVector");
|
||||
EXCLUDE.add("iterator");
|
||||
EXCLUDE.add("sparseIterator");
|
||||
|
||||
// Excluded because they are inherited from "Object".
|
||||
for (Method m : Object.class.getMethods()) {
|
||||
EXCLUDE.add(m.getName());
|
||||
}
|
||||
RANDOM = new Random(20110813);
|
||||
}
|
||||
|
||||
|
@ -234,7 +241,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
|
||||
/**
|
||||
* Creates a new random vector of a specified type. This vector is then to
|
||||
* be wrapped in a {@link AbstractRealVector.UnmodifiableVector}.
|
||||
* be wrapped in an unmodifiable vector.
|
||||
*
|
||||
* @return a new random vector.
|
||||
*/
|
||||
|
@ -243,11 +250,10 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
/**
|
||||
* Creates a new random object of the specified type.
|
||||
*
|
||||
* @param c
|
||||
* the class of the object to be created.
|
||||
* @param c Class of the object to be created.
|
||||
* @return a new random object.
|
||||
* @throws IllegalArgumentException
|
||||
* if the specified class is not recognized by this method.
|
||||
* @throws IllegalArgumentException if the specified class is not
|
||||
* recognized by this method.
|
||||
*/
|
||||
public Object createParameter(final Class<?> c) {
|
||||
if (c == Integer.TYPE) {
|
||||
|
@ -270,8 +276,9 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* This is the general test of most methods in
|
||||
* {@link AbstractRealVector.UnmodifiableVector}. It works as follows.
|
||||
* This is the general test of most methods in the
|
||||
* {@link RealVector#unmodifiableRealVector(RealVector) unmodifiable vector}.
|
||||
* It works as follows.
|
||||
* First, an unmodifiable view of a copy of the specified random vector
|
||||
* {@code u} is created: this defines {@code v}. Then the <em>same</em>
|
||||
* method {@code m} is invoked on {@code u} and {@code v}, with randomly
|
||||
|
@ -288,19 +295,21 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
*constructed.
|
||||
* @param args Arguments to be passed to method {@code m}.
|
||||
*/
|
||||
private void callMethod(final Method m, final RealVector u,
|
||||
final Object... args) throws IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException {
|
||||
private void callMethod(final Method m,
|
||||
final RealVector u,
|
||||
final Object... args)
|
||||
throws IllegalAccessException,
|
||||
IllegalArgumentException,
|
||||
InvocationTargetException {
|
||||
final RealVector uu = u.copy();
|
||||
final RealVector v = AbstractRealVector
|
||||
.unmodifiableRealVector(u.copy());
|
||||
final RealVector v = RealVector.unmodifiableRealVector(u.copy());
|
||||
Object exp = m.invoke(u, args);
|
||||
if (equals(uu, u)) {
|
||||
Object act = m.invoke(v, args);
|
||||
Assert.assertTrue(m.toGenericString()
|
||||
+ ", unmodifiable vector has changed", equals(uu, v));
|
||||
Assert.assertTrue(m.toGenericString() + ", unmodifiable vector has changed",
|
||||
equals(uu, v));
|
||||
Assert.assertTrue(m.toGenericString() + ", wrong result",
|
||||
equals(exp, act));
|
||||
equals(exp, act));
|
||||
|
||||
} else {
|
||||
boolean flag = false;
|
||||
|
@ -322,8 +331,10 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
* {@link #EXCLUDE}), they must be handled by separate tests.
|
||||
*/
|
||||
@Test
|
||||
public void testAllButExcluded() throws IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException {
|
||||
public void testAllButExcluded()
|
||||
throws IllegalAccessException,
|
||||
IllegalArgumentException,
|
||||
InvocationTargetException {
|
||||
Method[] method = RealVector.class.getMethods();
|
||||
for (int i = 0; i < method.length; i++) {
|
||||
Method m = method[i];
|
||||
|
@ -342,7 +353,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
@Test
|
||||
public void testGetEntry() {
|
||||
RealVector u = createVector();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u);
|
||||
RealVector v = RealVector.unmodifiableRealVector(u);
|
||||
for (int i = 0; i < DIM; i++) {
|
||||
Assert.assertTrue(equals(u.getEntry(i), v.getEntry(i)));
|
||||
}
|
||||
|
@ -351,7 +362,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
@Test(expected = MathUnsupportedOperationException.class)
|
||||
public void testSetEntry() {
|
||||
RealVector u = createVector();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u);
|
||||
RealVector v = RealVector.unmodifiableRealVector(u);
|
||||
for (int i = 0; i < DIM; i++) {
|
||||
v.setEntry(i, 0d);
|
||||
}
|
||||
|
@ -360,7 +371,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
@Test
|
||||
public void testGetSubVector() {
|
||||
RealVector u = createVector();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u);
|
||||
RealVector v = RealVector.unmodifiableRealVector(u);
|
||||
for (int i = 0; i < DIM; i++) {
|
||||
for (int n = 1; n < DIM - i; n++) {
|
||||
RealVector exp = u.getSubVector(i, n);
|
||||
|
@ -373,7 +384,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
@Test(expected = MathUnsupportedOperationException.class)
|
||||
public void testSetSubVector() {
|
||||
RealVector u = createVector();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u);
|
||||
RealVector v = RealVector.unmodifiableRealVector(u);
|
||||
v.setSubVector(0, new ArrayRealVector());
|
||||
}
|
||||
|
||||
|
@ -381,7 +392,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
public void testIterator() {
|
||||
RealVector u = createVector();
|
||||
Iterator<Entry> i = u.iterator();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u.copy());
|
||||
RealVector v = RealVector.unmodifiableRealVector(u.copy());
|
||||
Iterator<Entry> j = v.iterator();
|
||||
boolean flag;
|
||||
while (i.hasNext()) {
|
||||
|
@ -407,7 +418,7 @@ public abstract class UnmodifiableRealVectorAbstractTest {
|
|||
public void testSparseIterator() {
|
||||
RealVector u = createVector();
|
||||
Iterator<Entry> i = u.sparseIterator();
|
||||
RealVector v = AbstractRealVector.unmodifiableRealVector(u.copy());
|
||||
RealVector v = RealVector.unmodifiableRealVector(u.copy());
|
||||
Iterator<Entry> j = v.sparseIterator();
|
||||
boolean flag;
|
||||
while (i.hasNext()) {
|
||||
|
|
Loading…
Reference in New Issue