From aa0b1cc78838bda5c371a568abc8b13a3760f1e4 Mon Sep 17 00:00:00 2001 From: Sebastien Brisard Date: Thu, 13 Sep 2012 19:00:51 +0000 Subject: [PATCH] MATH-854: in FieldVector and ArrayFieldVector, reverted to r1383770. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1384471 13f79535-47bb-0310-9956-ffa450edef68 --- .../math3/linear/ArrayFieldVector.java | 162 ++++---------- .../commons/math3/linear/FieldVector.java | 201 +++++++----------- 2 files changed, 115 insertions(+), 248 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java b/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java index 9557be77b..28b9d738a 100644 --- a/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java +++ b/src/main/java/org/apache/commons/math3/linear/ArrayFieldVector.java @@ -97,7 +97,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[]) */ public ArrayFieldVector(T[] d) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (d == null) { throw new NullArgumentException(); } @@ -118,7 +118,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[]) */ public ArrayFieldVector(Field field, T[] d) - throws NullArgumentException { + throws NullArgumentException { if (d == null) { throw new NullArgumentException(); } @@ -148,7 +148,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[], boolean) */ public ArrayFieldVector(T[] d, boolean copyArray) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (d == null) { throw new NullArgumentException(); } @@ -175,7 +175,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[], boolean) */ public ArrayFieldVector(Field field, T[] d, boolean copyArray) - throws NullArgumentException { + throws NullArgumentException { if (d == null) { throw new NullArgumentException(); } @@ -194,7 +194,7 @@ public class ArrayFieldVector> implements FieldVector< * than {@code pos + size}. */ public ArrayFieldVector(T[] d, int pos, int size) - throws NullArgumentException, NumberIsTooLargeException { + throws NullArgumentException, NumberIsTooLargeException { if (d == null) { throw new NullArgumentException(); } @@ -218,7 +218,7 @@ public class ArrayFieldVector> implements FieldVector< * than {@code pos + size}. */ public ArrayFieldVector(Field field, T[] d, int pos, int size) - throws NullArgumentException, NumberIsTooLargeException { + throws NullArgumentException, NumberIsTooLargeException { if (d == null) { throw new NullArgumentException(); } @@ -237,7 +237,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(FieldVector v) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -255,7 +255,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector v) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -272,7 +272,7 @@ public class ArrayFieldVector> implements FieldVector< * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayFieldVector(ArrayFieldVector v, boolean deep) - throws NullArgumentException { + throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } @@ -289,7 +289,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(ArrayFieldVector v1, ArrayFieldVector v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -308,7 +308,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(ArrayFieldVector v1, T[] v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -327,7 +327,7 @@ public class ArrayFieldVector> implements FieldVector< * {@code null}. */ public ArrayFieldVector(T[] v1, ArrayFieldVector v2) - throws NullArgumentException { + throws NullArgumentException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -353,7 +353,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(Field, FieldElement[], FieldElement[]) */ public ArrayFieldVector(T[] v1, T[] v2) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -378,7 +378,7 @@ public class ArrayFieldVector> implements FieldVector< * @see #ArrayFieldVector(FieldElement[], FieldElement[]) */ public ArrayFieldVector(Field field, T[] v1, T[] v2) - throws NullArgumentException, ZeroException { + throws NullArgumentException, ZeroException { if (v1 == null || v2 == null) { throw new NullArgumentException(); } @@ -412,12 +412,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(this, true); } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - */ + /** {@inheritDoc} */ public FieldVector add(FieldVector v) throws DimensionMismatchException { try { @@ -449,12 +444,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - */ + /** {@inheritDoc} */ public FieldVector subtract(FieldVector v) throws DimensionMismatchException { try { @@ -486,12 +476,8 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapAdd(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapAdd(T d) { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].add(d); @@ -499,24 +485,16 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapAddToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapAddToSelf(T d) { for (int i = 0; i < data.length; i++) { data[i] = data[i].add(d); } return this; } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapSubtract(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapSubtract(T d) { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].subtract(d); @@ -524,24 +502,16 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapSubtractToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapSubtractToSelf(T d) { for (int i = 0; i < data.length; i++) { data[i] = data[i].subtract(d); } return this; } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapMultiply(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapMultiply(T d) { T[] out = buildArray(data.length); for (int i = 0; i < data.length; i++) { out[i] = data[i].multiply(d); @@ -549,24 +519,15 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - */ - public FieldVector mapMultiplyToSelf(T d) throws NullArgumentException { + /** {@inheritDoc} */ + public FieldVector mapMultiplyToSelf(T d) { for (int i = 0; i < data.length; i++) { data[i] = data[i].multiply(d); } return this; } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - * @throws MathArithmeticException if {@code d} is zero. - */ + /** {@inheritDoc} */ public FieldVector mapDivide(T d) throws NullArgumentException, MathArithmeticException { if (d == null) { @@ -579,12 +540,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws NullArgumentException if {@code d} is {@code null}. - * @throws MathArithmeticException if {@code d} is zero. - */ + /** {@inheritDoc} */ public FieldVector mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException { if (d == null) { @@ -596,11 +552,7 @@ public class ArrayFieldVector> implements FieldVector< return this; } - /** - * {@inheritDoc} - * - * @throws MathArithmeticException if {@code d} is zero. - */ + /** {@inheritDoc} */ public FieldVector mapInv() throws MathArithmeticException { T[] out = buildArray(data.length); final T one = field.getOne(); @@ -614,11 +566,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws MathArithmeticException if {@code d} is zero. - */ + /** {@inheritDoc} */ public FieldVector mapInvToSelf() throws MathArithmeticException { final T one = field.getOne(); for (int i = 0; i < data.length; i++) { @@ -631,12 +579,7 @@ public class ArrayFieldVector> implements FieldVector< return this; } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - */ + /** {@inheritDoc} */ public FieldVector ebeMultiply(FieldVector v) throws DimensionMismatchException { try { @@ -668,13 +611,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - * @throws MathArithmeticException if one entry of {@code v} is zero. - */ + /** {@inheritDoc} */ public FieldVector ebeDivide(FieldVector v) throws DimensionMismatchException, MathArithmeticException { try { @@ -729,13 +666,9 @@ public class ArrayFieldVector> implements FieldVector< return data; } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - */ - public T dotProduct(FieldVector v) throws DimensionMismatchException { + /** {@inheritDoc} */ + public T dotProduct(FieldVector v) + throws DimensionMismatchException { try { return dotProduct((ArrayFieldVector) v); } catch (ClassCastException cce) { @@ -765,13 +698,7 @@ public class ArrayFieldVector> implements FieldVector< return dot; } - /** - * {@inheritDoc} - * - * @throws DimensionMismatchException if {@code v} is not the same size as - * {@code this}. - * @throws MathArithmeticException if {@code v} is the null vector. - */ + /** {@inheritDoc} */ public FieldVector projection(FieldVector v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); @@ -859,12 +786,7 @@ public class ArrayFieldVector> implements FieldVector< return new ArrayFieldVector(field, out, false); } - /** - * {@inheritDoc} - * - * @throws OutOfRangeException if the index is not valid. - * @throws NotPositiveException if the number of elements is not positive. - */ + /** {@inheritDoc} */ public FieldVector getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { @@ -889,11 +811,7 @@ public class ArrayFieldVector> implements FieldVector< } } - /** - * {@inheritDoc} - * - * @throws OutOfRangeException if the index is not valid. - */ + /** {@inheritDoc} */ public void setSubVector(int index, FieldVector v) throws OutOfRangeException { try { try { 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 8b6e4f23f..befabcbef 100644 --- a/src/main/java/org/apache/commons/math3/linear/FieldVector.java +++ b/src/main/java/org/apache/commons/math3/linear/FieldVector.java @@ -18,6 +18,11 @@ package org.apache.commons.math3.linear; import org.apache.commons.math3.Field; import org.apache.commons.math3.FieldElement; +import org.apache.commons.math3.exception.DimensionMismatchException; +import org.apache.commons.math3.exception.MathArithmeticException; +import org.apache.commons.math3.exception.NotPositiveException; +import org.apache.commons.math3.exception.NullArgumentException; +import org.apache.commons.math3.exception.OutOfRangeException; /** * Interface defining a field-valued vector with basic algebraic operations. @@ -58,161 +63,125 @@ public interface FieldVector> { FieldVector copy(); /** - * Compute the sum of {@code this} and {@code v}. Implementations should throw - * {@link org.apache.commons.math3.exception.DimensionMismatchException} if - * {@code v} is not the same size as {@code this}. - * + * 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} */ - FieldVector add(FieldVector v); + FieldVector add(FieldVector v) throws DimensionMismatchException; /** - * Compute {@code this} minus {@code v}. Implementations should throw - * {@link org.apache.commons.math3.exception.DimensionMismatchException} if - * {@code v} is not the same size as {@code this} - * + * 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} */ - FieldVector subtract(FieldVector v); + FieldVector subtract(FieldVector v) throws DimensionMismatchException; /** - * Map an addition operation to each entry. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map an addition operation to each entry. * @param d value to be added to each entry * @return {@code this + d} */ FieldVector mapAdd(T d); /** - * Map an addition operation to each entry. The instance is - * changed by this method. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map an addition operation to each entry. + *

The instance is changed by this method.

* @param d value to be added to each entry * @return for convenience, return {@code this} */ FieldVector mapAddToSelf(T d); /** - * Map a subtraction operation to each entry. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map a subtraction operation to each entry. * @param d value to be subtracted to each entry * @return {@code this - d} */ FieldVector mapSubtract(T d); /** - * Map a subtraction operation to each entry. The instance - * is changed by this method. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map a subtraction operation to each entry. + *

The instance is changed by this method.

* @param d value to be subtracted to each entry * @return for convenience, return {@code this} */ FieldVector mapSubtractToSelf(T d); /** - * Map a multiplication operation to each entry. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map a multiplication operation to each entry. * @param d value to multiply all entries by * @return {@code this * d} */ FieldVector mapMultiply(T d); /** - * Map a multiplication operation to each entry. The instance - * is changed by this method. Implementations should throw - * {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null}. - * + * Map a multiplication operation to each entry. + *

The instance is changed by this method.

* @param d value to multiply all entries by * @return for convenience, return {@code this} */ FieldVector mapMultiplyToSelf(T d); /** - * Map a division operation to each entry. Implementations should throw - *
    - *
  • {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null},
  • - *
  • {@link org.apache.commons.math3.exception.MathArithmeticException} if - * {@code d} is zero.
  • - *
- * + * Map a division operation to each entry. * @param d value to divide all entries by * @return {@code this / d} + * @throws NullArgumentException if {@code d} is {@code null}. + * @throws MathArithmeticException if {@code d} is zero. */ - FieldVector mapDivide(T d); + FieldVector mapDivide(T d) + throws NullArgumentException, MathArithmeticException; /** - * Map a division operation to each entry. The instance is - * changed by this method. - *
    - *
  • {@link org.apache.commons.math3.exception.NullArgumentException} if - * {@code d} is {@code null},
  • - *
  • {@link org.apache.commons.math3.exception.MathArithmeticException} if - * {@code d} is zero.
  • - *
- * + * Map a division operation to each entry. + *

The instance is changed by this method.

* @param d value to divide all entries by * @return for convenience, return {@code this} + * @throws NullArgumentException if {@code d} is {@code null}. + * @throws MathArithmeticException if {@code d} is zero. */ - FieldVector mapDivideToSelf(T d); + FieldVector mapDivideToSelf(T d) + throws NullArgumentException, MathArithmeticException; /** - * Map the 1/x function to each entry. Implementations should throw - * {@link org.apache.commons.math3.exception.MathArithmeticException} if - * one of the entries is zero. - * + * Map the 1/x 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(); + FieldVector mapInv() throws MathArithmeticException; /** - * Map the 1/x function to each entry. The instance is - * changed by this method. Implementations should throw - * {@link org.apache.commons.math3.exception.MathArithmeticException} if - * one of the entries is zero. - * + * Map the 1/x function to each entry. + *

The instance is changed by this method.

* @return for convenience, return {@code this} + * @throws MathArithmeticException if one of the entries is zero. */ - FieldVector mapInvToSelf(); + FieldVector mapInvToSelf() throws MathArithmeticException; /** - * Element-by-element multiplication. Implementations should throw - * {@link org.apache.commons.math3.exception.DimensionMismatchException} if - * {@code v} is not the same size as {@code this}. - * + * 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} */ - FieldVector ebeMultiply(FieldVector v); + FieldVector ebeMultiply(FieldVector v) + throws DimensionMismatchException; /** - * Element-by-element division. Implementations should throw - *
    - *
  • {@link org.apache.commons.math3.exception.DimensionMismatchException} - * if {@code v} is not the same size as {@code this},
  • - *
  • {@link org.apache.commons.math3.exception.MathArithmeticException} - * if one entry of {@code v} is zero. - *
  • - *
- * + * 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 MathArithmeticException if one entry of {@code v} is zero. */ - FieldVector ebeDivide(FieldVector v); + FieldVector ebeDivide(FieldVector v) + throws DimensionMismatchException, MathArithmeticException; /** * Returns vector entries as a T array. @@ -221,30 +190,23 @@ public interface FieldVector> { T[] getData(); /** - * Compute the dot product. Implementations should throw - * {@link org.apache.commons.math3.exception.DimensionMismatchException} if - * {@code v} is not the same size as {@code this}. - * + * 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} */ - T dotProduct(FieldVector v); + T dotProduct(FieldVector v) throws DimensionMismatchException; - /** - * Find the orthogonal projection of this vector onto another vector. - * Implementations should throw - *
    - *
  • {@link org.apache.commons.math3.exception.DimensionMismatchException} - * if {@code v} is not the same size as {@code this},
  • - *
  • {@link org.apache.commons.math3.exception.MathArithmeticException} - * if {@code v} is the null 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 MathArithmeticException if {@code v} is the null vector. */ - FieldVector projection(FieldVector v); + FieldVector projection(FieldVector v) + throws DimensionMismatchException, MathArithmeticException; /** * Compute the outer product. @@ -254,30 +216,23 @@ public interface FieldVector> { FieldMatrix outerProduct(FieldVector v); /** - * Returns the entry in the specified index. Implementations should throw - * {@link org.apache.commons.math3.exception.OutOfRangeException} if the - * index is not valid. + * Returns the entry in the specified index. * * @param index Index location of entry to be fetched. * @return the vector entry at {@code index}. + * @throws OutOfRangeException if the index is not valid. * @see #setEntry(int, FieldElement) */ - T getEntry(int index); + T getEntry(int index) throws OutOfRangeException; /** - * Set a single element. Implementations should throw - *
    - *
  • {@link org.apache.commons.math3.exception.OutOfRangeException} if the - * index is not valid,
  • - *
  • {@link org.apache.commons.math3.exception.NullArgumentException} if - * the value is {@code null}.
  • - *
- * + * Set a single element. * @param index element index. * @param value new value for the element. + * @throws OutOfRangeException if the index is not valid. * @see #getEntry(int) */ - void setEntry(int index, T value); + void setEntry(int index, T value) throws OutOfRangeException; /** * Returns the size of the vector. @@ -300,29 +255,23 @@ public interface FieldVector> { FieldVector append(T d); /** - * Get a subvector from consecutive elements. Implementations should throw - *
    - *
  • {@link org.apache.commons.math3.exception.OutOfRangeException} if the - * index is not valid,
  • - *
  • {@link org.apache.commons.math3.exception.NotPositiveException} if - * the number of elements is not positive.
  • - *
- * + * Get a subvector from consecutive elements. * @param index index of first element. * @param n number of elements to be retrieved. * @return a vector containing n elements. + * @throws OutOfRangeException if the index is not valid. + * @throws NotPositiveException if the number of elements if not positive. */ - FieldVector getSubVector(int index, int n); + FieldVector getSubVector(int index, int n) + throws OutOfRangeException, NotPositiveException; /** - * Set a set of consecutive elements. Implementations should throw - * {@link org.apache.commons.math3.exception.OutOfRangeException} if the - * index is not valid. - * + * Set a set of consecutive elements. * @param index index of first element to be set. * @param v vector containing the values to set. + * @throws OutOfRangeException if the index is not valid. */ - void setSubVector(int index, FieldVector v); + void setSubVector(int index, FieldVector v) throws OutOfRangeException; /** * Set all elements to a single value.