You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/04/05 20:38:33 UTC

svn commit: r762131 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/transform/FastFourierTransformer.java site/xdoc/changes.xml

Author: luc
Date: Sun Apr  5 18:38:32 2009
New Revision: 762131

URL: http://svn.apache.org/viewvc?rev=762131&view=rev
Log:
Fixed inconsistent access to multidimensional array in FastFourierTransformer

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/transform/FastFourierTransformer.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/transform/FastFourierTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/transform/FastFourierTransformer.java?rev=762131&r1=762130&r2=762131&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/transform/FastFourierTransformer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/transform/FastFourierTransformer.java Sun Apr  5 18:38:32 2009
@@ -620,7 +620,7 @@
         private static final long serialVersionUID =  0x564FCD47EBA8169BL;
 
         /** Size in all dimensions. */
-        protected int[] dimensionSize = new int[1];
+        protected int[] dimensionSize;
 
         /** Storage array. */
         protected Object multiDimensionalComplexArray;
@@ -628,32 +628,31 @@
         /** Simple constructor.
          * @param multiDimensionalComplexArray array containing the matrix elements
          */
-        public MultiDimensionalComplexMatrix(Object
-                                             multiDimensionalComplexArray) {
+        public MultiDimensionalComplexMatrix(Object multiDimensionalComplexArray) {
+
             this.multiDimensionalComplexArray = multiDimensionalComplexArray;
+
+            // count dimensions
             int numOfDimensions = 0;
-            
-            Object lastDimension = multiDimensionalComplexArray;
-            while(lastDimension instanceof Object[]) {
+            for (Object lastDimension = multiDimensionalComplexArray;
+                 lastDimension instanceof Object[];) {
+                final Object[] array = (Object[]) lastDimension;
                 numOfDimensions++;
-                //manually implement variable size int[]
-                if (dimensionSize.length < numOfDimensions) {
-                    int[] newDimensionSize = new int[(int) Math.ceil(
-                            dimensionSize.length*1.6)];
-                    System.arraycopy(dimensionSize, 0, newDimensionSize, 0,
-                                     dimensionSize.length);
-                    dimensionSize = newDimensionSize;
-                }
-                dimensionSize[numOfDimensions - 1] = ((Object[])
-                                                      lastDimension).length;
-                lastDimension = ((Object[]) lastDimension)[0];
-            }
-            if (dimensionSize.length > numOfDimensions) {
-                int[] newDimensionSize = new int[numOfDimensions];
-                System.arraycopy(dimensionSize, 0, newDimensionSize, 0,
-                                 numOfDimensions);
-                dimensionSize = newDimensionSize;
+                lastDimension = array[0];
             }
+
+            // allocate array with exact count
+            dimensionSize = new int[numOfDimensions];
+
+            // fill array
+            numOfDimensions = 0;
+            for (Object lastDimension = multiDimensionalComplexArray;
+                 lastDimension instanceof Object[];) {
+                final Object[] array = (Object[]) lastDimension;
+                dimensionSize[numOfDimensions++] = array.length;
+                lastDimension = array[0];
+            }
+
         }
 
         /**
@@ -664,12 +663,15 @@
          */
         public Complex get(int... vector)
             throws IllegalArgumentException {
-            if (vector == null && dimensionSize.length > 1) {
-                throw MathRuntimeException.createIllegalArgumentException(
-                        "some dimensions don't match: {0} != {1}",
-                        0, dimensionSize.length);
+            if (vector == null) {
+                if (dimensionSize.length > 0) {
+                    throw MathRuntimeException.createIllegalArgumentException(
+                            "some dimensions don't match: {0} != {1}",
+                            0, dimensionSize.length);
+                }
+                return null;
             }
-            if (vector != null && vector.length != dimensionSize.length) {
+            if (vector.length != dimensionSize.length) {
                 throw MathRuntimeException.createIllegalArgumentException(
                         "some dimensions don't match: {0} != {1}",
                         vector.length, dimensionSize.length);
@@ -693,7 +695,7 @@
         public Complex set(Complex magnitude, int... vector)
             throws IllegalArgumentException {
             if (vector == null) {
-                if (dimensionSize.length > 1) {
+                if (dimensionSize.length > 0) {
                     throw MathRuntimeException.createIllegalArgumentException(
                             "some dimensions don't match: {0} != {1}",
                             0, dimensionSize.length);

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=762131&r1=762130&r2=762131&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Apr  5 18:38:32 2009
@@ -39,6 +39,9 @@
   </properties>
   <body>
     <release version="2.0" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-257" due-to="Sebb">
+        Fixed inconsistent access to multidimensional array in FastFourierTransformer
+      </action>
       <action dev="luc" type="fix" issue="MATH-248" >
         Greatly improved multiplication speed for sparse matrices
       </action>