diff --git a/src/main/java/org/apache/commons/math3/linear/FieldVector.java b/src/main/java/org/apache/commons/math3/linear/FieldVector.java index 9d64c2504..428629ee4 100644 --- a/src/main/java/org/apache/commons/math3/linear/FieldVector.java +++ b/src/main/java/org/apache/commons/math3/linear/FieldVector.java @@ -66,8 +66,7 @@ public interface FieldVector> { * Compute the sum of {@code this} and {@code v}. * @param v vector to be added * @return {@code this + v} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} */ FieldVector add(FieldVector v) throws DimensionMismatchException; @@ -75,8 +74,7 @@ public interface FieldVector> { * Compute {@code this} minus {@code v}. * @param v vector to be subtracted * @return {@code this - v} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} */ FieldVector subtract(FieldVector v) throws DimensionMismatchException; @@ -154,8 +152,7 @@ public interface FieldVector> { /** * Map the 1/x function to each entry. - * @return a vector containing the result of applying the function to each - * entry. + * @return a vector containing the result of applying the function to each entry. * @throws MathArithmeticException if one of the entries is zero. */ FieldVector mapInv() throws MathArithmeticException; @@ -172,8 +169,7 @@ public interface FieldVector> { * Element-by-element multiplication. * @param v vector by which instance elements must be multiplied * @return a vector containing {@code this[i] * v[i]} for all {@code i} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} */ FieldVector ebeMultiply(FieldVector v) throws DimensionMismatchException; @@ -182,8 +178,7 @@ public interface FieldVector> { * Element-by-element division. * @param v vector by which instance elements must be divided * @return a vector containing {@code this[i] / v[i]} for all {@code i} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} * @throws MathArithmeticException if one entry of {@code v} is zero. */ FieldVector ebeDivide(FieldVector v) @@ -192,23 +187,24 @@ public interface FieldVector> { /** * Returns vector entries as a T array. * @return T array of entries + * @deprecated as of 3.1, to be removed in 4.0. Please use the {@link #toArray()} method instead. */ - T[] getData(); + @Deprecated + T[] getData(); /** * Compute the dot product. * @param v vector with which dot product should be computed * @return the scalar dot product of {@code this} and {@code v} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} */ T dotProduct(FieldVector v) throws DimensionMismatchException; - /** Find the orthogonal projection of this vector onto another vector. + /** + * Find the orthogonal projection of this vector onto another vector. * @param v vector onto which {@code this} must be projected * @return projection of {@code this} onto {@code v} - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this} + * @throws DimensionMismatchException if {@code v} is not the same size as {@code this} * @throws MathArithmeticException if {@code v} is the null vector. */ FieldVector projection(FieldVector v) diff --git a/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java b/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java index e300766fc..c323ebc3e 100644 --- a/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java +++ b/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java @@ -202,7 +202,7 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public FieldVector copy() { return new SparseFieldVector(this); - } + } /** {@inheritDoc} */ public T dotProduct(FieldVector v) throws DimensionMismatchException { @@ -242,34 +242,33 @@ public class SparseFieldVector> implements FieldVector return res; } - /** {@inheritDoc} */ - public T[] getData() { - T[] res = buildArray(virtualSize); - OpenIntToFieldHashMap.Iterator iter = entries.iterator(); - while (iter.hasNext()) { - iter.advance(); - res[iter.key()] = iter.value(); - } - return res; - } + /** + * {@inheritDoc} + * + * @deprecated as of 3.1, to be removed in 4.0. Please use the {@link #toArray()} method instead. + */ + @Deprecated + public T[] getData() { + return toArray(); + } - /** {@inheritDoc} */ - public int getDimension() { + /** {@inheritDoc} */ + public int getDimension() { return virtualSize; } - /** {@inheritDoc} */ - public T getEntry(int index) throws OutOfRangeException { + /** {@inheritDoc} */ + public T getEntry(int index) throws OutOfRangeException { checkIndex(index); return entries.get(index); } - /** {@inheritDoc} */ - public Field getField() { + /** {@inheritDoc} */ + public Field getField() { return field; } - /** {@inheritDoc} */ + /** {@inheritDoc} */ public FieldVector getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { @@ -290,26 +289,26 @@ public class SparseFieldVector> implements FieldVector return res; } - /** {@inheritDoc} */ - public FieldVector mapAdd(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapAdd(T d) throws NullArgumentException { return copy().mapAddToSelf(d); - } + } - /** {@inheritDoc} */ - public FieldVector mapAddToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapAddToSelf(T d) throws NullArgumentException { for (int i = 0; i < virtualSize; i++) { setEntry(i, getEntry(i).add(d)); } return this; } - /** {@inheritDoc} */ + /** {@inheritDoc} */ public FieldVector mapDivide(T d) throws NullArgumentException, MathArithmeticException { return copy().mapDivideToSelf(d); } - /** {@inheritDoc} */ + /** {@inheritDoc} */ public FieldVector mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException { OpenIntToFieldHashMap.Iterator iter = entries.iterator(); @@ -318,43 +317,43 @@ public class SparseFieldVector> implements FieldVector entries.put(iter.key(), iter.value().divide(d)); } return this; - } + } - /** {@inheritDoc} */ - public FieldVector mapInv() throws MathArithmeticException { + /** {@inheritDoc} */ + public FieldVector mapInv() throws MathArithmeticException { return copy().mapInvToSelf(); - } + } - /** {@inheritDoc} */ - public FieldVector mapInvToSelf() throws MathArithmeticException { + /** {@inheritDoc} */ + public FieldVector mapInvToSelf() throws MathArithmeticException { for (int i = 0; i < virtualSize; i++) { setEntry(i, field.getOne().divide(getEntry(i))); } return this; - } + } - /** {@inheritDoc} */ - public FieldVector mapMultiply(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapMultiply(T d) throws NullArgumentException { return copy().mapMultiplyToSelf(d); } - /** {@inheritDoc} */ - public FieldVector mapMultiplyToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapMultiplyToSelf(T d) throws NullArgumentException { OpenIntToFieldHashMap.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); entries.put(iter.key(), iter.value().multiply(d)); } return this; - } + } - /** {@inheritDoc} */ - public FieldVector mapSubtract(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapSubtract(T d) throws NullArgumentException { return copy().mapSubtractToSelf(d); } - /** {@inheritDoc} */ - public FieldVector mapSubtractToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapSubtractToSelf(T d) throws NullArgumentException { return mapAddToSelf(field.getZero().subtract(d)); } @@ -416,7 +415,7 @@ public class SparseFieldVector> implements FieldVector public void setEntry(int index, T value) throws OutOfRangeException { checkIndex(index); entries.put(index, value); - } + } /** {@inheritDoc} */ public void setSubVector(int index, FieldVector v) @@ -475,7 +474,13 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public T[] toArray() { - return getData(); + T[] res = buildArray(virtualSize); + OpenIntToFieldHashMap.Iterator iter = entries.iterator(); + while (iter.hasNext()) { + iter.advance(); + res[iter.key()] = iter.value(); + } + return res; } /**