[MATH-666] make FieldVector#getData() method deprecated in favor of toArray(), minor formatting, move implementation of SparseFieldVector#getData() to toArray().

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1385316 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-09-16 16:50:32 +00:00
parent 1f914f9917
commit 79f99111d5
2 changed files with 60 additions and 59 deletions

View File

@ -66,8 +66,7 @@ public interface FieldVector<T extends FieldElement<T>> {
* 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<T> add(FieldVector<T> v) throws DimensionMismatchException;
@ -75,8 +74,7 @@ public interface FieldVector<T extends FieldElement<T>> {
* 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<T> subtract(FieldVector<T> v) throws DimensionMismatchException;
@ -154,8 +152,7 @@ public interface FieldVector<T extends FieldElement<T>> {
/**
* 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<T> mapInv() throws MathArithmeticException;
@ -172,8 +169,7 @@ public interface FieldVector<T extends FieldElement<T>> {
* 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<T> ebeMultiply(FieldVector<T> v)
throws DimensionMismatchException;
@ -182,8 +178,7 @@ public interface FieldVector<T extends FieldElement<T>> {
* 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<T> ebeDivide(FieldVector<T> v)
@ -192,23 +187,24 @@ public interface FieldVector<T extends FieldElement<T>> {
/**
* 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<T> 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<T> projection(FieldVector<T> v)

View File

@ -202,7 +202,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */
public FieldVector<T> copy() {
return new SparseFieldVector<T>(this);
}
}
/** {@inheritDoc} */
public T dotProduct(FieldVector<T> v) throws DimensionMismatchException {
@ -242,34 +242,33 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
return res;
}
/** {@inheritDoc} */
public T[] getData() {
T[] res = buildArray(virtualSize);
OpenIntToFieldHashMap<T>.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<T> getField() {
/** {@inheritDoc} */
public Field<T> getField() {
return field;
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public FieldVector<T> getSubVector(int index, int n)
throws OutOfRangeException, NotPositiveException {
if (n < 0) {
@ -290,26 +289,26 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
return res;
}
/** {@inheritDoc} */
public FieldVector<T> mapAdd(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapAdd(T d) throws NullArgumentException {
return copy().mapAddToSelf(d);
}
}
/** {@inheritDoc} */
public FieldVector<T> mapAddToSelf(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapAddToSelf(T d) throws NullArgumentException {
for (int i = 0; i < virtualSize; i++) {
setEntry(i, getEntry(i).add(d));
}
return this;
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public FieldVector<T> mapDivide(T d)
throws NullArgumentException, MathArithmeticException {
return copy().mapDivideToSelf(d);
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public FieldVector<T> mapDivideToSelf(T d)
throws NullArgumentException, MathArithmeticException {
OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator();
@ -318,43 +317,43 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
entries.put(iter.key(), iter.value().divide(d));
}
return this;
}
}
/** {@inheritDoc} */
public FieldVector<T> mapInv() throws MathArithmeticException {
/** {@inheritDoc} */
public FieldVector<T> mapInv() throws MathArithmeticException {
return copy().mapInvToSelf();
}
}
/** {@inheritDoc} */
public FieldVector<T> mapInvToSelf() throws MathArithmeticException {
/** {@inheritDoc} */
public FieldVector<T> mapInvToSelf() throws MathArithmeticException {
for (int i = 0; i < virtualSize; i++) {
setEntry(i, field.getOne().divide(getEntry(i)));
}
return this;
}
}
/** {@inheritDoc} */
public FieldVector<T> mapMultiply(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapMultiply(T d) throws NullArgumentException {
return copy().mapMultiplyToSelf(d);
}
/** {@inheritDoc} */
public FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException {
OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
entries.put(iter.key(), iter.value().multiply(d));
}
return this;
}
}
/** {@inheritDoc} */
public FieldVector<T> mapSubtract(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapSubtract(T d) throws NullArgumentException {
return copy().mapSubtractToSelf(d);
}
/** {@inheritDoc} */
public FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException {
/** {@inheritDoc} */
public FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException {
return mapAddToSelf(field.getZero().subtract(d));
}
@ -416,7 +415,7 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
public void setEntry(int index, T value) throws OutOfRangeException {
checkIndex(index);
entries.put(index, value);
}
}
/** {@inheritDoc} */
public void setSubVector(int index, FieldVector<T> v)
@ -475,7 +474,13 @@ public class SparseFieldVector<T extends FieldElement<T>> implements FieldVector
/** {@inheritDoc} */
public T[] toArray() {
return getData();
T[] res = buildArray(virtualSize);
OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
res[iter.key()] = iter.value();
}
return res;
}
/**