Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A6D5D109CA for ; Tue, 15 Oct 2013 17:57:40 +0000 (UTC) Received: (qmail 87993 invoked by uid 500); 15 Oct 2013 17:57:36 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 87954 invoked by uid 500); 15 Oct 2013 17:57:36 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 87690 invoked by uid 99); 15 Oct 2013 17:57:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Oct 2013 17:57:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Oct 2013 17:57:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id EF2E823889BB; Tue, 15 Oct 2013 17:57:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1532459 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java main/java/org/apache/commons/math3/util/MathArrays.java Date: Tue, 15 Oct 2013 17:57:08 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131015175708.EF2E823889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Tue Oct 15 17:57:08 2013 New Revision: 1532459 URL: http://svn.apache.org/r1532459 Log: MATH-1002 AbstractUnivariateStatistic.test(double[] values, int begin, int length, boolean allowEmpty) has uses outside subclasses Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1532459&r1=1532458&r2=1532459&view=diff ============================================================================== --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Tue Oct 15 17:57:08 2013 @@ -51,6 +51,10 @@ If the output is not quite correct, chec + + AbstractUnivariateStatistic.test(double[] values, int begin, int length, boolean allowEmpty) + has uses outside subclasses; implementation moved to MathArrays. + The "KalmanFilter" wrongly enforced a column dimension of 1 for the provided control and measurement noise matrix. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java?rev=1532459&r1=1532458&r2=1532459&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/AbstractUnivariateStatistic.java Tue Oct 15 17:57:08 2013 @@ -22,6 +22,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.NumberIsTooLargeException; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.util.LocalizedFormats; +import org.apache.commons.math3.util.MathArrays; /** * Abstract base class for all implementations of the @@ -151,12 +152,14 @@ public abstract class AbstractUnivariate * @param length the number of elements to include * @return true if the parameters are valid and designate a subarray of positive length * @throws MathIllegalArgumentException if the indices are invalid or the array is null + * @deprecated 3.3 Use {@link MathArrays#test(double[], int, int)} instead */ + @Deprecated protected boolean test( final double[] values, final int begin, final int length) throws MathIllegalArgumentException { - return test(values, begin, length, false); + return MathArrays.test(values, begin, length, false); } /** @@ -179,33 +182,12 @@ public abstract class AbstractUnivariate * @return true if the parameters are valid * @throws MathIllegalArgumentException if the indices are invalid or the array is null * @since 3.0 + * @deprecated 3.3 Use {@link MathArrays#test(double[], int, int, boolean)} instead */ + @Deprecated protected boolean test(final double[] values, final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException { - - if (values == null) { - throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); - } - - if (begin < 0) { - throw new NotPositiveException(LocalizedFormats.START_POSITION, begin); - } - - if (length < 0) { - throw new NotPositiveException(LocalizedFormats.LENGTH, length); - } - - if (begin + length > values.length) { - throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END, - begin + length, values.length, true); - } - - if (length == 0 && !allowEmpty) { - return false; - } - - return true; - + return MathArrays.test(values, begin, length, allowEmpty); } /** @@ -236,13 +218,15 @@ public abstract class AbstractUnivariate * @return true if the parameters are valid and designate a subarray of positive length * @throws MathIllegalArgumentException if the indices are invalid or the array is null * @since 2.1 + * @deprecated 3.3 Use {@link MathArrays#test(double[], double[], int, int)} instead */ + @Deprecated protected boolean test( final double[] values, final double[] weights, final int begin, final int length) throws MathIllegalArgumentException { - return test(values, weights, begin, length, false); + return MathArrays.test(values, weights, begin, length, false); } /** @@ -277,39 +261,13 @@ public abstract class AbstractUnivariate * the weights array contains NaN, infinite or negative elements, or there * are no positive weights. * @since 3.0 + * @deprecated 3.3 Use {@link MathArrays#test(double[], double[], int, int, boolean)} instead */ + @Deprecated protected boolean test(final double[] values, final double[] weights, final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException { - if (weights == null || values == null) { - throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); - } - - if (weights.length != values.length) { - throw new DimensionMismatchException(weights.length, values.length); - } - - boolean containsPositiveWeight = false; - for (int i = begin; i < begin + length; i++) { - if (Double.isNaN(weights[i])) { - throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, i); - } - if (Double.isInfinite(weights[i])) { - throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, weights[i], i); - } - if (weights[i] < 0) { - throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, i, weights[i]); - } - if (!containsPositiveWeight && weights[i] > 0.0) { - containsPositiveWeight = true; - } - } - - if (!containsPositiveWeight) { - throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO); - } - - return test(values, begin, length, allowEmpty); + return MathArrays.test(values, weights, begin, length, allowEmpty); } } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1532459&r1=1532458&r2=1532459&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java Tue Oct 15 17:57:08 2013 @@ -37,6 +37,7 @@ import org.apache.commons.math3.exceptio import org.apache.commons.math3.exception.NotPositiveException; import org.apache.commons.math3.exception.NotStrictlyPositiveException; import org.apache.commons.math3.exception.NullArgumentException; +import org.apache.commons.math3.exception.NumberIsTooLargeException; import org.apache.commons.math3.exception.util.LocalizedFormats; /** @@ -1547,4 +1548,184 @@ public class MathArrays { } return a; } + /** + * This method is used + * to verify that the input parameters designate a subarray of positive length. + *

+ *

    + *
  • returns true iff the parameters designate a subarray of + * positive length
  • + *
  • throws MathIllegalArgumentException if the array is null or + * or the indices are invalid
  • + *
  • returns false
  • if the array is non-null, but + * length is 0. + *

+ * + * @param values the input array + * @param begin index of the first array element to include + * @param length the number of elements to include + * @return true if the parameters are valid and designate a subarray of positive length + * @throws MathIllegalArgumentException if the indices are invalid or the array is null + * @since 3.3 + */ + public static boolean test( + final double[] values, + final int begin, + final int length) throws MathIllegalArgumentException { + return test(values, begin, length, false); + } + + /** + * This method is used + * to verify that the input parameters designate a subarray of positive length. + *

+ *

    + *
  • returns true iff the parameters designate a subarray of + * non-negative length
  • + *
  • throws IllegalArgumentException if the array is null or + * or the indices are invalid
  • + *
  • returns false
  • if the array is non-null, but + * length is 0 unless allowEmpty is true + *

+ * + * @param values the input array + * @param begin index of the first array element to include + * @param length the number of elements to include + * @param allowEmpty if true then zero length arrays are allowed + * @return true if the parameters are valid + * @throws MathIllegalArgumentException if the indices are invalid or the array is null + * @since 3.3 + */ + public static boolean test(final double[] values, final int begin, + final int length, final boolean allowEmpty) throws MathIllegalArgumentException { + + if (values == null) { + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); + } + + if (begin < 0) { + throw new NotPositiveException(LocalizedFormats.START_POSITION, Integer.valueOf(begin)); + } + + if (length < 0) { + throw new NotPositiveException(LocalizedFormats.LENGTH, Integer.valueOf(length)); + } + + if (begin + length > values.length) { + throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END, + Integer.valueOf(begin + length), Integer.valueOf(values.length), true); + } + + if (length == 0 && !allowEmpty) { + return false; + } + + return true; + + } + + /** + * This method is used + * to verify that the begin and length parameters designate a subarray of positive length + * and the weights are all non-negative, non-NaN, finite, and not all zero. + *

+ *

    + *
  • returns true iff the parameters designate a subarray of + * positive length and the weights array contains legitimate values.
  • + *
  • throws IllegalArgumentException if any of the following are true: + *
    • the values array is null
    • + *
    • the weights array is null
    • + *
    • the weights array does not have the same length as the values array
    • + *
    • the weights array contains one or more infinite values
    • + *
    • the weights array contains one or more NaN values
    • + *
    • the weights array contains negative values
    • + *
    • the start and length arguments do not determine a valid array
    + *
  • + *
  • returns false
  • if the array is non-null, but + * length is 0. + *

+ * + * @param values the input array + * @param weights the weights array + * @param begin index of the first array element to include + * @param length the number of elements to include + * @return true if the parameters are valid and designate a subarray of positive length + * @throws MathIllegalArgumentException if the indices are invalid or the array is null + * @since 3.3 + */ + public static boolean test( + final double[] values, + final double[] weights, + final int begin, + final int length) throws MathIllegalArgumentException { + return test(values, weights, begin, length, false); + } + + /** + * This method is used + * to verify that the begin and length parameters designate a subarray of positive length + * and the weights are all non-negative, non-NaN, finite, and not all zero. + *

+ *

    + *
  • returns true iff the parameters designate a subarray of + * non-negative length and the weights array contains legitimate values.
  • + *
  • throws MathIllegalArgumentException if any of the following are true: + *
    • the values array is null
    • + *
    • the weights array is null
    • + *
    • the weights array does not have the same length as the values array
    • + *
    • the weights array contains one or more infinite values
    • + *
    • the weights array contains one or more NaN values
    • + *
    • the weights array contains negative values
    • + *
    • the start and length arguments do not determine a valid array
    + *
  • + *
  • returns false
  • if the array is non-null, but + * length is 0 unless allowEmpty is true. + *

+ * + * @param values the input array. + * @param weights the weights array. + * @param begin index of the first array element to include. + * @param length the number of elements to include. + * @param allowEmpty if {@code true} than allow zero length arrays to pass. + * @return {@code true} if the parameters are valid. + * @throws NullArgumentException if either of the arrays are null + * @throws MathIllegalArgumentException if the array indices are not valid, + * the weights array contains NaN, infinite or negative elements, or there + * are no positive weights. + * @since 3.3 + */ + public static boolean test(final double[] values, final double[] weights, + final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException { + + if (weights == null || values == null) { + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); + } + + if (weights.length != values.length) { + throw new DimensionMismatchException(weights.length, values.length); + } + + boolean containsPositiveWeight = false; + for (int i = begin; i < begin + length; i++) { + final double weight = weights[i]; + if (Double.isNaN(weight)) { + throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, Integer.valueOf(i)); + } + if (Double.isInfinite(weight)) { + throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, Double.valueOf(weight), Integer.valueOf(i)); + } + if (weight < 0) { + throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, Integer.valueOf(i), Double.valueOf(weight)); + } + if (!containsPositiveWeight && weight > 0.0) { + containsPositiveWeight = true; + } + } + + if (!containsPositiveWeight) { + throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO); + } + + return test(values, begin, length, allowEmpty); + } }