You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by md...@apache.org on 2003/06/27 22:58:28 UTC

cvs commit: jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat StoreUnivariateImpl.java

mdiggory    2003/06/27 13:58:28

  Modified:    math/src/test/org/apache/commons/math/util
                        ExpandableDoubleArrayTest.java
                        FixedDoubleArrayTest.java
                        DoubleArrayAbstractTest.java
               math/src/java/org/apache/commons/math/util
                        ExpandableDoubleArray.java FixedDoubleArray.java
                        DoubleArray.java
               math/src/java/org/apache/commons/math/stat
                        StoreUnivariateImpl.java
  Log:
  Removal of statistical (min/max) and deleteFrontElements methods from DoubleArray interface (per our previous discussion)
  
  Adjusted dependent Test and StoreUnivariateImpl classes accordingly to accomidate changes.
  
  Added new constructor to FixedDoubleArray for double[].
  
  Revision  Changes    Path
  1.2       +3 -3      jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java
  
  Index: ExpandableDoubleArrayTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/ExpandableDoubleArrayTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExpandableDoubleArrayTest.java	22 Jun 2003 03:57:55 -0000	1.1
  +++ ExpandableDoubleArrayTest.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -198,17 +198,17 @@
   		da.addElement(2.0);
   		assertEquals( "Number of elements should be 11", 11, da.getNumElements());
   		
  -		da.discardFrontElements(5);
  +		((ExpandableDoubleArray)da).discardFrontElements(5);
   		assertEquals( "Number of elements should be 6", 6, da.getNumElements());
   		
   		try {
  -			da.discardFrontElements(-1);
  +            ((ExpandableDoubleArray)da).discardFrontElements(-1);
   			fail( "Trying to discard a negative number of element is not allowed");
   		} catch( Exception e ){
   		}
   		
   		try {
  -			da.discardFrontElements( 10000 );
  +            ((ExpandableDoubleArray)da).discardFrontElements( 10000 );
   			fail( "You can't discard more elements than the array contains");
   		} catch( Exception e ){
   		}
  
  
  
  1.2       +0 -7      jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/FixedDoubleArrayTest.java
  
  Index: FixedDoubleArrayTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/FixedDoubleArrayTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixedDoubleArrayTest.java	22 Jun 2003 03:57:55 -0000	1.1
  +++ FixedDoubleArrayTest.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -171,12 +171,5 @@
   				
   	}
   	
  -	public void testDiscardFront() {
  -		try {
  -			da.discardFrontElements( 2 );
  -			fail( "Discard front elements should throw an exception");
  -		} catch( Exception e ) {
  -		}
  -	}
   		
   }
  
  
  
  1.2       +6 -4      jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/DoubleArrayAbstractTest.java
  
  Index: DoubleArrayAbstractTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/util/DoubleArrayAbstractTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DoubleArrayAbstractTest.java	22 Jun 2003 03:57:55 -0000	1.1
  +++ DoubleArrayAbstractTest.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -53,6 +53,8 @@
    */
   package org.apache.commons.math.util;
   
  +import org.apache.commons.math.stat.StatUtils;
  +
   import junit.framework.TestCase;
   
   /**
  @@ -126,12 +128,12 @@
   		assertEquals(
   			"The max element should be 2.0",
   			2.0,
  -			ra.getMax(),
  +            StatUtils.max(ra.getElements()),
   			Double.MIN_VALUE);
   		assertEquals(
   			"The min element should be 1.0",
   			1.0,
  -			ra.getMin(),
  +            StatUtils.min(ra.getElements()),
   			Double.MIN_VALUE);
   
   		for (int i = 0; i < 1024; i++) {
  @@ -156,11 +158,11 @@
   		da.addElement(122.0);
   		da.addElement(1212.0);
   
  -		assertEquals("Min should be -2.0", -2.0, da.getMin(), Double.MIN_VALUE);
  +		assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE);
   		assertEquals(
   			"Max should be 1212.0",
   			1212.0,
  -			da.getMax(),
  +            StatUtils.max(da.getElements()),
   			Double.MIN_VALUE);
   	}
   
  
  
  
  1.2       +0 -29     jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java
  
  Index: ExpandableDoubleArray.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExpandableDoubleArray.java	22 Jun 2003 03:57:57 -0000	1.1
  +++ ExpandableDoubleArray.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -408,33 +408,4 @@
           return elementArray;
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.commons.math.DoubleArray#getMax()
  -     */
  -    public double getMax() {
  -        double max = internalArray[startIndex];
  -		
  -        for (int i = startIndex + 1; i < (numElements + startIndex); i++) {
  -            if (internalArray[i] > max) {
  -                max = internalArray[i];
  -            }
  -        }
  -
  -        return max;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.commons.math.DoubleArray#getMin()
  -     */
  -    public double getMin() {
  -        double min = internalArray[startIndex];
  -
  -        for (int i = startIndex + 1; i < (numElements + startIndex); i++) {
  -            if (internalArray[i] < min) {
  -                min = internalArray[i];
  -            }
  -        }
  -
  -        return min;
  -    }
   }
  
  
  
  1.2       +16 -33    jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java
  
  Index: FixedDoubleArray.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixedDoubleArray.java	22 Jun 2003 03:57:57 -0000	1.1
  +++ FixedDoubleArray.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -121,6 +121,22 @@
       }
   
       /**
  +     * Create a fixed array backed by the provided double[] implementation. 
  +     * the array should have all the elements occupied. the size and maxElements
  +     * are drawn from the array's length.
  +     * 
  +     * This implementation of DoubleArray was created to provide a more 
  +     * "performance-oriented" in-place rolling mechanism for calculations 
  +     * which need to operate on a rolling window of values.
  +     * @param array the backing array
  +     */
  +    public FixedDoubleArray(double[] array) {
  +        this.maxElements = array.length;
  +        this.size = array.length;
  +        internalArray = array;
  +    }
  +    
  +    /**
        * Retrieves the current size of the array.
        * @see org.apache.commons.math.DoubleArray#getNumElements()
        */
  @@ -324,37 +340,4 @@
           throw new RuntimeException(msg);
       }
   
  -    /**
  -     * Retrieves the minimum double value contained in this array.
  -     *
  -     * @return The number less than all other numbers in this 
  -     *         array.
  -     * @see org.apache.commons.math.DoubleArray#getMin()
  -     */
  -    public double getMin() {
  -        double min = internalArray[0];
  -        for (int i = 1; i < size; i++) {
  -            if (internalArray[i] < min) {
  -                min = internalArray[i];
  -            }
  -        }
  -        return min;
  -    }
  -
  -    /**
  -     * Retrieves the maximum double value contained in this array.
  -     * 
  -     * @return The number greater than all other numbers in this
  -     *         array.
  -     * @see org.apache.commons.math.DoubleArray#getMax()
  -     */
  -    public double getMax() {
  -        double max = internalArray[0];
  -        for (int i = 1; i < size; i++) {
  -            if (internalArray[i] > max) {
  -                max = internalArray[i];
  -            }
  -        }
  -        return max;
  -    }
   }
  
  
  
  1.2       +0 -21     jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/DoubleArray.java
  
  Index: DoubleArray.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/DoubleArray.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DoubleArray.java	22 Jun 2003 03:57:57 -0000	1.1
  +++ DoubleArray.java	27 Jun 2003 20:58:27 -0000	1.2
  @@ -123,25 +123,4 @@
        */
       void clear();
   
  -    /**
  -     * Discards values from the front of the list.  This function removes n 
  -     * elements from the front of the array.
  -     * 
  -     *@param i number of elements to discard from the front of the array.
  -     */
  -    void discardFrontElements(int i);
  -
  -    /**
  -     * Returns the minimum value stored in this array
  -     *
  -     * @return minimum value contained in this array
  -     */
  -    double getMin();
  -
  -    /**
  -     * Returns the maximum value stored in this array
  -     *
  -     * @return maximum value contained in this array
  -     */
  -    double getMax();
   }
  
  
  
  1.3       +1 -2      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java
  
  Index: StoreUnivariateImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StoreUnivariateImpl.java	22 Jun 2003 03:57:55 -0000	1.2
  +++ StoreUnivariateImpl.java	27 Jun 2003 20:58:28 -0000	1.3
  @@ -54,7 +54,6 @@
   package org.apache.commons.math.stat;
   
   import org.apache.commons.math.util.ContractableDoubleArray;
  -import org.apache.commons.math.util.DoubleArray;
   
   /**
    * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
  @@ -62,7 +61,7 @@
   public class StoreUnivariateImpl extends AbstractStoreUnivariate {
   
       // Use an internal double array
  -    DoubleArray eDA;
  +    ContractableDoubleArray eDA;
   
       // Store the windowSize
       private int windowSize = Univariate.INFINITE_WINDOW;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org