Author: tn
Date: Sun Sep 16 16:50:32 2012
New Revision: 1385316
URL: http://svn.apache.org/viewvc?rev=1385316&view=rev
Log:
[MATH-666] make FieldVector#getData() method deprecated in favor of toArray(),
minor formatting, move implementation of SparseFieldVector#getData() to
toArray().
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldVector.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldVector.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldVector.java?rev=1385316&r1=1385315&r2=1385316&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldVector.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/FieldVector.java
Sun Sep 16 16:50:32 2012
@@ -66,8 +66,7 @@ public interface FieldVector<T extends F
* 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 F
* 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 F
/**
* 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 F
* 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 F
* 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 F
/**
* 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)
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java?rev=1385316&r1=1385315&r2=1385316&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/SparseFieldVector.java
Sun Sep 16 16:50:32 2012
@@ -202,7 +202,7 @@ public class SparseFieldVector<T extends
/** {@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
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
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
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
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
/** {@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;
}
/**