commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1232767 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/transform/FastFourierTransformer.java test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java
Date Wed, 18 Jan 2012 07:17:49 GMT
Author: celestin
Date: Wed Jan 18 07:17:48 2012
New Revision: 1232767

URL: http://svn.apache.org/viewvc?rev=1232767&view=rev
Log:
Widened the scope of tests for transform.FastFourierTransformer (MATH-677).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java?rev=1232767&r1=1232766&r2=1232767&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java Wed Jan 18 07:17:48 2012
@@ -25,8 +25,6 @@ import org.apache.commons.math.complex.C
 import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.MathIllegalStateException;
-import org.apache.commons.math.exception.NonMonotonicSequenceException;
-import org.apache.commons.math.exception.NotStrictlyPositiveException;
 import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.exception.ZeroException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -149,9 +147,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    public Complex[] transform(double[] f)
-            throws MathIllegalArgumentException {
-
+    public Complex[] transform(double[] f) {
         if (unitary) {
             final double s = 1.0 / FastMath.sqrt(f.length);
             return TransformUtils.scaleArray(fft(f, false), s);
@@ -168,18 +164,15 @@ public class FastFourierTransformer impl
      * @param max the (exclusive) upper bound for the interval
      * @param n the number of sample points
      * @return the complex transformed array
-     * @throws NonMonotonicSequenceException if the lower bound is greater
-     * than, or equal to the upper bound
-     * @throws NotStrictlyPositiveException if the number of sample points
-     * {@code n} is negative
+     * @throws org.apache.commons.math.exception.NumberIsTooLargeException
+     * if the lower bound is greater than, or equal to the upper bound
+     * @throws org.apache.commons.math.exception.NotStrictlyPositiveException
+     * if the number of sample points {@code n} is negative
      * @throws MathIllegalArgumentException if the number of sample points
      * {@code n} is not a power of two
      */
     public Complex[] transform(UnivariateFunction f,
-            double min, double max, int n) throws
-            NonMonotonicSequenceException,
-            NotStrictlyPositiveException,
-            MathIllegalArgumentException {
+            double min, double max, int n) {
 
         final double[] data = FunctionUtils.sample(f, min, max, n);
         if (unitary) {
@@ -197,9 +190,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    public Complex[] transform(Complex[] f)
-            throws MathIllegalArgumentException {
-
+    public Complex[] transform(Complex[] f) {
         // TODO Is this necessary?
         roots.computeOmega(f.length);
         if (unitary) {
@@ -217,9 +208,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    public Complex[] inverseTransform(double[] f)
-            throws MathIllegalArgumentException {
-
+    public Complex[] inverseTransform(double[] f) {
         final double s = 1.0 / (unitary ? FastMath.sqrt(f.length) : f.length);
         return TransformUtils.scaleArray(fft(f, true), s);
     }
@@ -233,19 +222,15 @@ public class FastFourierTransformer impl
      * @param max the (exclusive) upper bound for the interval
      * @param n the number of sample points
      * @return the complex inversely transformed array
-     * @throws NonMonotonicSequenceException if the lower bound is greater
-     * than, or equal to the upper bound
-     * @throws NotStrictlyPositiveException if the number of sample points
-     * {@code n} is negative
+     * @throws org.apache.commons.math.exception.NumberIsTooLargeException
+     * if the lower bound is greater than, or equal to the upper bound
+     * @throws org.apache.commons.math.exception.NotStrictlyPositiveException
+     * if the number of sample points {@code n} is negative
      * @throws MathIllegalArgumentException if the number of sample points
      * {@code n} is not a power of two
      */
     public Complex[] inverseTransform(UnivariateFunction f,
-            double min, double max, int n) throws
-            NonMonotonicSequenceException,
-            NotStrictlyPositiveException,
-            MathIllegalArgumentException {
-
+            double min, double max, int n) {
         final double[] data = FunctionUtils.sample(f, min, max, n);
         final double s = 1.0 / (unitary ? FastMath.sqrt(n) : n);
         return TransformUtils.scaleArray(fft(data, true), s);
@@ -259,9 +244,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    public Complex[] inverseTransform(Complex[] f)
-            throws MathIllegalArgumentException {
-
+    public Complex[] inverseTransform(Complex[] f) {
         roots.computeOmega(-f.length);    // pass negative argument
         final double s = 1.0 / (unitary ? FastMath.sqrt(f.length) : f.length);
         return TransformUtils.scaleArray(fft(f), s);
@@ -277,8 +260,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    protected Complex[] fft(double[] f, boolean isInverse)
-            throws MathIllegalArgumentException {
+    protected Complex[] fft(double[] f, boolean isInverse) {
 
         if (!ArithmeticUtils.isPowerOfTwo(f.length)) {
             throw new MathIllegalArgumentException(
@@ -328,8 +310,7 @@ public class FastFourierTransformer impl
      * @throws MathIllegalArgumentException if the length of the data array is
      * not a power of two
      */
-    protected Complex[] fft(Complex[] data)
-            throws MathIllegalArgumentException {
+    protected Complex[] fft(Complex[] data) {
 
         if (!ArithmeticUtils.isPowerOfTwo(data.length)) {
             throw new MathIllegalArgumentException(
@@ -418,9 +399,7 @@ public class FastFourierTransformer impl
      * id est {@code Complex[][][][]}
      * @throws IllegalArgumentException if any dimension is not a power of two
      */
-    public Object mdfft(Object mdca, boolean forward)
-        throws IllegalArgumentException {
-
+    public Object mdfft(Object mdca, boolean forward) {
         MultiDimensionalComplexMatrix mdcm = (MultiDimensionalComplexMatrix)
                 new MultiDimensionalComplexMatrix(mdca).clone();
         int[] dimensionSize = mdcm.getDimensionSizes();
@@ -442,8 +421,7 @@ public class FastFourierTransformer impl
      * @throws IllegalArgumentException if any dimension is not a power of two
      */
     private void mdfft(MultiDimensionalComplexMatrix mdcm,
-            boolean forward, int d, int[] subVector) throws
-            IllegalArgumentException {
+            boolean forward, int d, int[] subVector) {
 
         int[] dimensionSize = mdcm.getDimensionSizes();
         //if done

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java?rev=1232767&r1=1232766&r2=1232767&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java Wed Jan 18 07:17:48 2012
@@ -20,8 +20,12 @@ import java.util.Random;
 
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateFunction;
+import org.apache.commons.math.analysis.function.Sin;
 import org.apache.commons.math.analysis.function.Sinc;
 import org.apache.commons.math.complex.Complex;
+import org.apache.commons.math.exception.MathIllegalArgumentException;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -35,195 +39,199 @@ import org.junit.Test;
  * @version $Id$
  */
 public final class FastFourierTransformerTest {
-    /**
-     * The common (for repeatability) seed of all random number generators used
-     * in this test.
-     */
+    /** The common seed of all random number generators used in this test. */
     private final static long SEED = 20110111L;
 
-    /**
-     * Test of transformer for the ad hoc data taken from Mathematica.
+    /*
+     * Precondition checks for standard transform.
      */
-    @Test
-    public void testAdHocData() {
-        FastFourierTransformer transformer = FastFourierTransformer.create();
-        Complex result[]; double tolerance = 1E-12;
 
-        double x[] = {1.3, 2.4, 1.7, 4.1, 2.9, 1.7, 5.1, 2.7};
-        Complex y[] = {
-            new Complex(21.9, 0.0),
-            new Complex(-2.09497474683058, 1.91507575950825),
-            new Complex(-2.6, 2.7),
-            new Complex(-1.10502525316942, -4.88492424049175),
-            new Complex(0.1, 0.0),
-            new Complex(-1.10502525316942, 4.88492424049175),
-            new Complex(-2.6, -2.7),
-            new Complex(-2.09497474683058, -1.91507575950825)};
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardTransformComplexSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final Complex[] x = createComplexData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(x);
+    }
 
-        result = transformer.transform(x);
-        for (int i = 0; i < result.length; i++) {
-            Assert.assertEquals(y[i].getReal(), result[i].getReal(), tolerance);
-            Assert.assertEquals(y[i].getImaginary(), result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardTransformRealSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final double[] x = createRealData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(x);
+    }
 
-        result = transformer.inverseTransform(y);
-        for (int i = 0; i < result.length; i++) {
-            Assert.assertEquals(x[i], result[i].getReal(), tolerance);
-            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardTransformFunctionSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(f, 0.0, Math.PI, n);
+    }
 
-        double x2[] = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2};
-        TransformUtils.scaleArray(x2, 1.0 / FastMath.sqrt(x2.length));
-        Complex y2[] = y;
+    @Test(expected = NotStrictlyPositiveException.class)
+    public void testStandardTransformFunctionNotStrictlyPositiveNumberOfSamples() {
+        final int n = -128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(f, 0.0, Math.PI, n);
+    }
 
-        transformer = FastFourierTransformer.createUnitary();
-        result = transformer.transform(y2);
-        for (int i = 0; i < result.length; i++) {
-            Assert.assertEquals(x2[i], result[i].getReal(), tolerance);
-            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = NumberIsTooLargeException.class)
+    public void testStandardTransformFunctionInvalidBounds() {
+        final int n = 128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(f, Math.PI, 0.0, n);
+    }
 
-        result = transformer.inverseTransform(x2);
-        for (int i = 0; i < result.length; i++) {
-            Assert.assertEquals(y2[i].getReal(), result[i].getReal(), tolerance);
-            Assert.assertEquals(y2[i].getImaginary(), result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardInverseTransformComplexSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final Complex[] x = createComplexData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.inverseTransform(x);
     }
 
-    @Test
-    public void test2DData() {
-        FastFourierTransformer transformer = FastFourierTransformer.create();
-        double tolerance = 1E-12;
-        Complex[][] input = new Complex[][] {new Complex[] {new Complex(1, 0),
-                                                            new Complex(2, 0)},
-                                             new Complex[] {new Complex(3, 1),
-                                                            new Complex(4, 2)}};
-        Complex[][] goodOutput = new Complex[][] {new Complex[] {new Complex(5,
-                1.5), new Complex(-1, -.5)}, new Complex[] {new Complex(-2,
-                -1.5), new Complex(0, .5)}};
-        for (int i = 0; i < goodOutput.length; i++) {
-            TransformUtils.scaleArray(
-                goodOutput[i],
-                FastMath.sqrt(goodOutput[i].length) *
-                    FastMath.sqrt(goodOutput.length));
-        }
-        Complex[][] output = (Complex[][])transformer.mdfft(input, true);
-        Complex[][] output2 = (Complex[][])transformer.mdfft(output, false);
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardInverseTransformRealSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final double[] x = createRealData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.inverseTransform(x);
+    }
 
-        Assert.assertEquals(input.length, output.length);
-        Assert.assertEquals(input.length, output2.length);
-        Assert.assertEquals(input[0].length, output[0].length);
-        Assert.assertEquals(input[0].length, output2[0].length);
-        Assert.assertEquals(input[1].length, output[1].length);
-        Assert.assertEquals(input[1].length, output2[1].length);
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testStandardInverseTransformFunctionSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.inverseTransform(f, 0.0, Math.PI, n);
+    }
 
-        for (int i = 0; i < input.length; i++) {
-            for (int j = 0; j < input[0].length; j++) {
-                Assert.assertEquals(input[i][j].getImaginary(), output2[i][j].getImaginary(),
-                             tolerance);
-                Assert.assertEquals(input[i][j].getReal(), output2[i][j].getReal(), tolerance);
-                Assert.assertEquals(goodOutput[i][j].getImaginary(), output[i][j].getImaginary(),
-                             tolerance);
-                Assert.assertEquals(goodOutput[i][j].getReal(), output[i][j].getReal(), tolerance);
-            }
-        }
+    @Test(expected = NotStrictlyPositiveException.class)
+    public void testStandardInverseTransformFunctionNotStrictlyPositiveNumberOfSamples() {
+        final int n = -128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.inverseTransform(f, 0.0, Math.PI, n);
     }
 
-    @Test
-    public void test2DDataUnitary() {
-        FastFourierTransformer transformer = FastFourierTransformer.createUnitary();
-        double tolerance = 1E-12;
-        Complex[][] input = new Complex[][] {new Complex[] {new Complex(1, 0),
-                                                            new Complex(2, 0)},
-                                             new Complex[] {new Complex(3, 1),
-                                                            new Complex(4, 2)}};
-        Complex[][] goodOutput = new Complex[][] {new Complex[] {new Complex(5,
-                1.5), new Complex(-1, -.5)}, new Complex[] {new Complex(-2,
-                -1.5), new Complex(0, .5)}};
-        Complex[][] output = (Complex[][])transformer.mdfft(input, true);
-        Complex[][] output2 = (Complex[][])transformer.mdfft(output, false);
+    @Test(expected = NumberIsTooLargeException.class)
+    public void testStandardInverseTransformFunctionInvalidBounds() {
+        final int n = 128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.create();
+        fft.transform(f, Math.PI, 0.0, n);
+    }
 
-        Assert.assertEquals(input.length, output.length);
-        Assert.assertEquals(input.length, output2.length);
-        Assert.assertEquals(input[0].length, output[0].length);
-        Assert.assertEquals(input[0].length, output2[0].length);
-        Assert.assertEquals(input[1].length, output[1].length);
-        Assert.assertEquals(input[1].length, output2[1].length);
+    /*
+     * Precondition checks for unitary transform.
+     */
 
-        for (int i = 0; i < input.length; i++) {
-            for (int j = 0; j < input[0].length; j++) {
-                Assert.assertEquals(input[i][j].getImaginary(), output2[i][j].getImaginary(),
-                             tolerance);
-                Assert.assertEquals(input[i][j].getReal(), output2[i][j].getReal(), tolerance);
-                Assert.assertEquals(goodOutput[i][j].getImaginary(), output[i][j].getImaginary(),
-                             tolerance);
-                Assert.assertEquals(goodOutput[i][j].getReal(), output[i][j].getReal(), tolerance);
-            }
-        }
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryTransformComplexSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final Complex[] x = createComplexData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(x);
     }
 
-    /**
-     * Test of transformer for the sine function.
-     */
-    @Test
-    public void testSinFunction() {
-        UnivariateFunction f = new SinFunction();
-        FastFourierTransformer transformer = FastFourierTransformer.create();
-        Complex result[]; int N = 1 << 8;
-        double min, max, tolerance = 1E-12;
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryTransformRealSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final double[] x = createRealData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(x);
+    }
 
-        min = 0.0; max = 2.0 * FastMath.PI;
-        result = transformer.transform(f, min, max, N);
-        Assert.assertEquals(0.0, result[1].getReal(), tolerance);
-        Assert.assertEquals(-(N >> 1), result[1].getImaginary(), tolerance);
-        Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
-        Assert.assertEquals(N >> 1, result[N-1].getImaginary(), tolerance);
-        for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
-            Assert.assertEquals(0.0, result[i].getReal(), tolerance);
-            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryTransformFunctionSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(f, 0.0, Math.PI, n);
+    }
 
-        min = -FastMath.PI; max = FastMath.PI;
-        result = transformer.inverseTransform(f, min, max, N);
-        Assert.assertEquals(0.0, result[1].getReal(), tolerance);
-        Assert.assertEquals(-0.5, result[1].getImaginary(), tolerance);
-        Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
-        Assert.assertEquals(0.5, result[N-1].getImaginary(), tolerance);
-        for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
-            Assert.assertEquals(0.0, result[i].getReal(), tolerance);
-            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
-        }
+    @Test(expected = NotStrictlyPositiveException.class)
+    public void testUnitaryTransformFunctionNotStrictlyPositiveNumberOfSamples() {
+        final int n = -128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(f, 0.0, Math.PI, n);
     }
 
-    /**
-     * Test of parameters for the transformer.
+    @Test(expected = NumberIsTooLargeException.class)
+    public void testUnitaryTransformFunctionInvalidBounds() {
+        final int n = 128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(f, Math.PI, 0.0, n);
+    }
+
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryInverseTransformComplexSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final Complex[] x = createComplexData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.inverseTransform(x);
+    }
+
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryInverseTransformRealSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final double[] x = createRealData(n);
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.inverseTransform(x);
+    }
+
+    @Test(expected = MathIllegalArgumentException.class)
+    public void testUnitaryInverseTransformFunctionSizeNotAPowerOfTwo() {
+        final int n = 127;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.inverseTransform(f, 0.0, Math.PI, n);
+    }
+
+    @Test(expected = NotStrictlyPositiveException.class)
+    public void testUnitaryInverseTransformFunctionNotStrictlyPositiveNumberOfSamples() {
+        final int n = -128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.inverseTransform(f, 0.0, Math.PI, n);
+    }
+
+    @Test(expected = NumberIsTooLargeException.class)
+    public void testUnitaryInverseTransformFunctionInvalidBounds() {
+        final int n = 128;
+        final UnivariateFunction f = new Sin();
+        final FastFourierTransformer fft = FastFourierTransformer.createUnitary();
+        fft.transform(f, Math.PI, 0.0, n);
+    }
+
+    /*
+     * Utility methods for checking (successful) transforms.
      */
-    @Test
-    public void testParameters() throws Exception {
-        UnivariateFunction f = new SinFunction();
-        FastFourierTransformer transformer = FastFourierTransformer.create();
 
-        try {
-            // bad interval
-            transformer.transform(f, 1, -1, 64);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // bad samples number
-            transformer.transform(f, -1, 1, 0);
-            Assert.fail("Expecting IllegalArgumentException - bad samples number");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // bad samples number
-            transformer.transform(f, -1, 1, 100);
-            Assert.fail("Expecting IllegalArgumentException - bad samples number");
-        } catch (IllegalArgumentException ex) {
-            // expected
+    private static Complex[] createComplexData(final int n) {
+        final Random random = new Random(SEED);
+        final Complex[] data = new Complex[n];
+        for (int i = 0; i < n; i++) {
+            final double re = 2.0 * random.nextDouble() - 1.0;
+            final double im = 2.0 * random.nextDouble() - 1.0;
+            data[i] = new Complex(re, im);
+        }
+        return data;
+    }
+
+    private static double[] createRealData(final int n) {
+        final Random random = new Random(SEED);
+        final double[] data = new double[n];
+        for (int i = 0; i < n; i++) {
+            data[i] = 2.0 * random.nextDouble() - 1.0;
         }
+        return data;
     }
 
     /** Naive implementation of DFT, for reference. */
@@ -253,56 +261,126 @@ public final class FastFourierTransforme
         }
         return y;
     }
-    
-    @Test
-    public void testStandardTransformComplex() {
-        final boolean forward = true;
-        final boolean standard = true;
-        doTestTransformComplex(2, 1.0E-15, forward, standard);
-        doTestTransformComplex(4, 1.0E-14, forward, standard);
-        doTestTransformComplex(8, 1.0E-14, forward, standard);
-        doTestTransformComplex(16, 1.0E-13, forward, standard);
-        doTestTransformComplex(32, 1.0E-13, forward, standard);
-        doTestTransformComplex(64, 1.0E-13, forward, standard);
-        doTestTransformComplex(128, 1.0E-12, forward, standard);
-    }
-
-    @Test
-    public void testUnitaryTransformComplex() {
-        final boolean forward = true;
-        final boolean standard = false;
-        doTestTransformComplex(2, 1.0E-15, forward, standard);
-        doTestTransformComplex(4, 1.0E-14, forward, standard);
-        doTestTransformComplex(8, 1.0E-14, forward, standard);
-        doTestTransformComplex(16, 1.0E-13, forward, standard);
-        doTestTransformComplex(32, 1.0E-13, forward, standard);
-        doTestTransformComplex(64, 1.0E-13, forward, standard);
-        doTestTransformComplex(128, 1.0E-12, forward, standard);
-    }
 
-    @Test
-    public void testStandardInverseTransformComplex() {
-        final boolean forward = false;
-        final boolean standard = true;
-        doTestTransformComplex(2, 1.0E-15, forward, standard);
-        doTestTransformComplex(4, 1.0E-14, forward, standard);
-        doTestTransformComplex(8, 1.0E-14, forward, standard);
-        doTestTransformComplex(16, 1.0E-13, forward, standard);
-        doTestTransformComplex(32, 1.0E-13, forward, standard);
-        doTestTransformComplex(64, 1.0E-12, forward, standard);
-        doTestTransformComplex(128, 1.0E-12, forward, standard);
+    private static void doTestTransformComplex(final int n, final double tol,
+        final boolean forward, final boolean standard) {
+        final FastFourierTransformer fft;
+        if (standard) {
+            fft = FastFourierTransformer.create();
+        } else {
+            fft = FastFourierTransformer.createUnitary();
+        }
+        final Complex[] x = createComplexData(n);
+        final Complex[] expected;
+        final Complex[] actual;
+        final double s;
+        if (forward) {
+            expected = dft(x, -1);
+            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
+            actual = fft.transform(x);
+        } else {
+            expected = dft(x, 1);
+            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
+            actual = fft.inverseTransform(x);
+        }
+        for (int i = 0; i < n; i++) {
+            final String msg = String.format("%d, %d", n, i);
+            final double re = s * expected[i].getReal();
+            Assert.assertEquals(msg, re, actual[i].getReal(),
+                tol * FastMath.abs(re));
+            final double im = s * expected[i].getImaginary();
+            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
+                FastMath.abs(re));
+        }
     }
 
-    @Test
-    public void testUnitaryInverseTransformComplex() {
-        final boolean forward = false;
-        final boolean standard = false;
+    private static void doTestTransformReal(final int n, final double tol,
+        final boolean forward, final boolean standard) {
+        final FastFourierTransformer fft;
+        if (standard) {
+            fft = FastFourierTransformer.create();
+        } else {
+            fft = FastFourierTransformer.createUnitary();
+        }
+        final double[] x = createRealData(n);
+        final Complex[] xc = new Complex[n];
+        for (int i = 0; i < n; i++) {
+            xc[i] = new Complex(x[i], 0.0);
+        }
+        final Complex[] expected;
+        final Complex[] actual;
+        final double s;
+        if (forward) {
+            expected = dft(xc, -1);
+            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
+            actual = fft.transform(x);
+        } else {
+            expected = dft(xc, 1);
+            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
+            actual = fft.inverseTransform(x);
+        }
+        for (int i = 0; i < n; i++) {
+            final String msg = String.format("%d, %d", n, i);
+            final double re = s * expected[i].getReal();
+            Assert.assertEquals(msg, re, actual[i].getReal(),
+                tol * FastMath.abs(re));
+            final double im = s * expected[i].getImaginary();
+            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
+                FastMath.abs(re));
+        }
+    }
+
+    private static void doTestTransformFunction(final UnivariateFunction f,
+        final double min, final double max, int n, final double tol,
+        final boolean forward, final boolean standard) {
+        final FastFourierTransformer fft;
+        if (standard) {
+            fft = FastFourierTransformer.create();
+        } else {
+            fft = FastFourierTransformer.createUnitary();
+        }
+        final Complex[] x = new Complex[n];
+        for (int i = 0; i < n; i++) {
+            final double t = min + i * (max - min) / n;
+            x[i] = new Complex(f.value(t));
+        }
+        final Complex[] expected;
+        final Complex[] actual;
+        final double s;
+        if (forward) {
+            expected = dft(x, -1);
+            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
+            actual = fft.transform(f, min, max, n);
+        } else {
+            expected = dft(x, 1);
+            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
+            actual = fft.inverseTransform(f, min, max, n);
+        }
+        for (int i = 0; i < n; i++) {
+            final String msg = String.format("%d, %d", n, i);
+            final double re = s * expected[i].getReal();
+            Assert.assertEquals(msg, re, actual[i].getReal(),
+                tol * FastMath.abs(re));
+            final double im = s * expected[i].getImaginary();
+            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
+                FastMath.abs(re));
+        }
+    }
+
+    /*
+     * Tests of standard transform (when data is valid).
+     */
+
+    @Test
+    public void testStandardTransformComplex() {
+        final boolean forward = true;
+        final boolean standard = true;
         doTestTransformComplex(2, 1.0E-15, forward, standard);
         doTestTransformComplex(4, 1.0E-14, forward, standard);
         doTestTransformComplex(8, 1.0E-14, forward, standard);
         doTestTransformComplex(16, 1.0E-13, forward, standard);
         doTestTransformComplex(32, 1.0E-13, forward, standard);
-        doTestTransformComplex(64, 1.0E-12, forward, standard);
+        doTestTransformComplex(64, 1.0E-13, forward, standard);
         doTestTransformComplex(128, 1.0E-12, forward, standard);
     }
 
@@ -320,35 +398,38 @@ public final class FastFourierTransforme
     }
 
     @Test
-    public void testUnitaryTransformReal() {
+    public void testStandardTransformFunction() {
+        final UnivariateFunction f = new Sinc();
+        final double min = -FastMath.PI;
+        final double max = FastMath.PI;
         final boolean forward = true;
-        final boolean standard = false;
-        doTestTransformReal(2, 1.0E-15, forward, standard);
-        doTestTransformReal(4, 1.0E-14, forward, standard);
-        doTestTransformReal(8, 1.0E-14, forward, standard);
-        doTestTransformReal(16, 1.0E-13, forward, standard);
-        doTestTransformReal(32, 1.0E-13, forward, standard);
-        doTestTransformReal(64, 1.0E-13, forward, standard);
-        doTestTransformReal(128, 1.0E-11, forward, standard);
+        final boolean standard = true;
+        doTestTransformFunction(f, min, max, 2, 1.0E-15, forward, standard);
+        doTestTransformFunction(f, min, max, 4, 1.0E-14, forward, standard);
+        doTestTransformFunction(f, min, max, 8, 1.0E-14, forward, standard);
+        doTestTransformFunction(f, min, max, 16, 1.0E-13, forward, standard);
+        doTestTransformFunction(f, min, max, 32, 1.0E-13, forward, standard);
+        doTestTransformFunction(f, min, max, 64, 1.0E-12, forward, standard);
+        doTestTransformFunction(f, min, max, 128, 1.0E-11, forward, standard);
     }
 
     @Test
-    public void testStandardInverseTransformReal() {
+    public void testStandardInverseTransformComplex() {
         final boolean forward = false;
         final boolean standard = true;
-        doTestTransformReal(2, 1.0E-15, forward, standard);
-        doTestTransformReal(4, 1.0E-14, forward, standard);
-        doTestTransformReal(8, 1.0E-14, forward, standard);
-        doTestTransformReal(16, 1.0E-13, forward, standard);
-        doTestTransformReal(32, 1.0E-13, forward, standard);
-        doTestTransformReal(64, 1.0E-12, forward, standard);
-        doTestTransformReal(128, 1.0E-11, forward, standard);
+        doTestTransformComplex(2, 1.0E-15, forward, standard);
+        doTestTransformComplex(4, 1.0E-14, forward, standard);
+        doTestTransformComplex(8, 1.0E-14, forward, standard);
+        doTestTransformComplex(16, 1.0E-13, forward, standard);
+        doTestTransformComplex(32, 1.0E-13, forward, standard);
+        doTestTransformComplex(64, 1.0E-12, forward, standard);
+        doTestTransformComplex(128, 1.0E-12, forward, standard);
     }
 
     @Test
-    public void testUnitaryInverseTransformReal() {
+    public void testStandardInverseTransformReal() {
         final boolean forward = false;
-        final boolean standard = false;
+        final boolean standard = true;
         doTestTransformReal(2, 1.0E-15, forward, standard);
         doTestTransformReal(4, 1.0E-14, forward, standard);
         doTestTransformReal(8, 1.0E-14, forward, standard);
@@ -359,11 +440,11 @@ public final class FastFourierTransforme
     }
 
     @Test
-    public void testStandardTransformFunction() {
+    public void testStandardInverseTransformFunction() {
         final UnivariateFunction f = new Sinc();
         final double min = -FastMath.PI;
         final double max = FastMath.PI;
-        final boolean forward = true;
+        final boolean forward = false;
         final boolean standard = true;
         doTestTransformFunction(f, min, max, 2, 1.0E-15, forward, standard);
         doTestTransformFunction(f, min, max, 4, 1.0E-14, forward, standard);
@@ -374,6 +455,36 @@ public final class FastFourierTransforme
         doTestTransformFunction(f, min, max, 128, 1.0E-11, forward, standard);
     }
 
+    /*
+     * Tests of unitary transform (when data is valid).
+     */
+
+    @Test
+    public void testUnitaryTransformComplex() {
+        final boolean forward = true;
+        final boolean standard = false;
+        doTestTransformComplex(2, 1.0E-15, forward, standard);
+        doTestTransformComplex(4, 1.0E-14, forward, standard);
+        doTestTransformComplex(8, 1.0E-14, forward, standard);
+        doTestTransformComplex(16, 1.0E-13, forward, standard);
+        doTestTransformComplex(32, 1.0E-13, forward, standard);
+        doTestTransformComplex(64, 1.0E-13, forward, standard);
+        doTestTransformComplex(128, 1.0E-12, forward, standard);
+    }
+
+    @Test
+    public void testUnitaryTransformReal() {
+        final boolean forward = true;
+        final boolean standard = false;
+        doTestTransformReal(2, 1.0E-15, forward, standard);
+        doTestTransformReal(4, 1.0E-14, forward, standard);
+        doTestTransformReal(8, 1.0E-14, forward, standard);
+        doTestTransformReal(16, 1.0E-13, forward, standard);
+        doTestTransformReal(32, 1.0E-13, forward, standard);
+        doTestTransformReal(64, 1.0E-13, forward, standard);
+        doTestTransformReal(128, 1.0E-11, forward, standard);
+    }
+
     @Test
     public void testUnitaryTransformFunction() {
         final UnivariateFunction f = new Sinc();
@@ -391,19 +502,29 @@ public final class FastFourierTransforme
     }
 
     @Test
-    public void testStandardInverseTransformFunction() {
-        final UnivariateFunction f = new Sinc();
-        final double min = -FastMath.PI;
-        final double max = FastMath.PI;
+    public void testUnitaryInverseTransformComplex() {
         final boolean forward = false;
-        final boolean standard = true;
-        doTestTransformFunction(f, min, max, 2, 1.0E-15, forward, standard);
-        doTestTransformFunction(f, min, max, 4, 1.0E-14, forward, standard);
-        doTestTransformFunction(f, min, max, 8, 1.0E-14, forward, standard);
-        doTestTransformFunction(f, min, max, 16, 1.0E-13, forward, standard);
-        doTestTransformFunction(f, min, max, 32, 1.0E-13, forward, standard);
-        doTestTransformFunction(f, min, max, 64, 1.0E-12, forward, standard);
-        doTestTransformFunction(f, min, max, 128, 1.0E-11, forward, standard);
+        final boolean standard = false;
+        doTestTransformComplex(2, 1.0E-15, forward, standard);
+        doTestTransformComplex(4, 1.0E-14, forward, standard);
+        doTestTransformComplex(8, 1.0E-14, forward, standard);
+        doTestTransformComplex(16, 1.0E-13, forward, standard);
+        doTestTransformComplex(32, 1.0E-13, forward, standard);
+        doTestTransformComplex(64, 1.0E-12, forward, standard);
+        doTestTransformComplex(128, 1.0E-12, forward, standard);
+    }
+
+    @Test
+    public void testUnitaryInverseTransformReal() {
+        final boolean forward = false;
+        final boolean standard = false;
+        doTestTransformReal(2, 1.0E-15, forward, standard);
+        doTestTransformReal(4, 1.0E-14, forward, standard);
+        doTestTransformReal(8, 1.0E-14, forward, standard);
+        doTestTransformReal(16, 1.0E-13, forward, standard);
+        doTestTransformReal(32, 1.0E-13, forward, standard);
+        doTestTransformReal(64, 1.0E-12, forward, standard);
+        doTestTransformReal(128, 1.0E-11, forward, standard);
     }
 
     @Test
@@ -422,128 +543,166 @@ public final class FastFourierTransforme
         doTestTransformFunction(f, min, max, 128, 1.0E-11, forward, standard);
     }
 
-    private static Complex[] createComplexData(final int n) {
-        final Random random = new Random(SEED);
-        final Complex[] data = new Complex[n];
-        for (int i = 0; i < n; i++) {
-            final double re = 2.0 * random.nextDouble() - 1.0;
-            final double im = 2.0 * random.nextDouble() - 1.0;
-            data[i] = new Complex(re, im);
-        }
-        return data;
-    }
+    /*
+     * Additional tests for 1D data.
+     */
 
-    private static double[] createRealData(final int n) {
-        final Random random = new Random(SEED);
-        final double[] data = new double[n];
-        for (int i = 0; i < n; i++) {
-            data[i] = 2.0 * random.nextDouble() - 1.0;
+    /**
+     * Test of transformer for the ad hoc data taken from Mathematica.
+     */
+    @Test
+    public void testAdHocData() {
+        FastFourierTransformer transformer = FastFourierTransformer.create();
+        Complex result[]; double tolerance = 1E-12;
+
+        double x[] = {1.3, 2.4, 1.7, 4.1, 2.9, 1.7, 5.1, 2.7};
+        Complex y[] = {
+            new Complex(21.9, 0.0),
+            new Complex(-2.09497474683058, 1.91507575950825),
+            new Complex(-2.6, 2.7),
+            new Complex(-1.10502525316942, -4.88492424049175),
+            new Complex(0.1, 0.0),
+            new Complex(-1.10502525316942, 4.88492424049175),
+            new Complex(-2.6, -2.7),
+            new Complex(-2.09497474683058, -1.91507575950825)};
+
+        result = transformer.transform(x);
+        for (int i = 0; i < result.length; i++) {
+            Assert.assertEquals(y[i].getReal(), result[i].getReal(), tolerance);
+            Assert.assertEquals(y[i].getImaginary(), result[i].getImaginary(), tolerance);
         }
-        return data;
-    }
 
-    private static void doTestTransformComplex(final int n, final double tol,
-        final boolean forward, final boolean standard) {
-        final FastFourierTransformer fft;
-        if (standard) {
-            fft = FastFourierTransformer.create();
-        } else {
-            fft = FastFourierTransformer.createUnitary();
+        result = transformer.inverseTransform(y);
+        for (int i = 0; i < result.length; i++) {
+            Assert.assertEquals(x[i], result[i].getReal(), tolerance);
+            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
         }
-        final Complex[] x = createComplexData(n);
-        final Complex[] expected;
-        final Complex[] actual;
-        final double s;
-        if (forward) {
-            expected = dft(x, -1);
-            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
-            actual = fft.transform(x);
-        } else {
-            expected = dft(x, 1);
-            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
-            actual = fft.inverseTransform(x);
+
+        double x2[] = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2};
+        TransformUtils.scaleArray(x2, 1.0 / FastMath.sqrt(x2.length));
+        Complex y2[] = y;
+
+        transformer = FastFourierTransformer.createUnitary();
+        result = transformer.transform(y2);
+        for (int i = 0; i < result.length; i++) {
+            Assert.assertEquals(x2[i], result[i].getReal(), tolerance);
+            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
         }
-        for (int i = 0; i < n; i++) {
-            final String msg = String.format("%d, %d", n, i);
-            final double re = s * expected[i].getReal();
-            Assert.assertEquals(msg, re, actual[i].getReal(),
-                tol * FastMath.abs(re));
-            final double im = s * expected[i].getImaginary();
-            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
-                FastMath.abs(re));
+
+        result = transformer.inverseTransform(x2);
+        for (int i = 0; i < result.length; i++) {
+            Assert.assertEquals(y2[i].getReal(), result[i].getReal(), tolerance);
+            Assert.assertEquals(y2[i].getImaginary(), result[i].getImaginary(), tolerance);
         }
     }
 
-    private static void doTestTransformReal(final int n, final double tol,
-        final boolean forward, final boolean standard) {
-        final FastFourierTransformer fft;
-        if (standard) {
-            fft = FastFourierTransformer.create();
-        } else {
-            fft = FastFourierTransformer.createUnitary();
-        }
-        final double[] x = createRealData(n);
-        final Complex[] xc = new Complex[n];
-        for (int i = 0; i < n; i++) {
-            xc[i] = new Complex(x[i], 0.0);
-        }
-        final Complex[] expected;
-        final Complex[] actual;
-        final double s;
-        if (forward) {
-            expected = dft(xc, -1);
-            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
-            actual = fft.transform(x);
-        } else {
-            expected = dft(xc, 1);
-            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
-            actual = fft.inverseTransform(x);
+    /**
+     * Test of transformer for the sine function.
+     */
+    @Test
+    public void testSinFunction() {
+        UnivariateFunction f = new SinFunction();
+        FastFourierTransformer transformer = FastFourierTransformer.create();
+        Complex result[]; int N = 1 << 8;
+        double min, max, tolerance = 1E-12;
+
+        min = 0.0; max = 2.0 * FastMath.PI;
+        result = transformer.transform(f, min, max, N);
+        Assert.assertEquals(0.0, result[1].getReal(), tolerance);
+        Assert.assertEquals(-(N >> 1), result[1].getImaginary(), tolerance);
+        Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
+        Assert.assertEquals(N >> 1, result[N-1].getImaginary(), tolerance);
+        for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
+            Assert.assertEquals(0.0, result[i].getReal(), tolerance);
+            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
         }
-        for (int i = 0; i < n; i++) {
-            final String msg = String.format("%d, %d", n, i);
-            final double re = s * expected[i].getReal();
-            Assert.assertEquals(msg, re, actual[i].getReal(),
-                tol * FastMath.abs(re));
-            final double im = s * expected[i].getImaginary();
-            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
-                FastMath.abs(re));
+
+        min = -FastMath.PI; max = FastMath.PI;
+        result = transformer.inverseTransform(f, min, max, N);
+        Assert.assertEquals(0.0, result[1].getReal(), tolerance);
+        Assert.assertEquals(-0.5, result[1].getImaginary(), tolerance);
+        Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
+        Assert.assertEquals(0.5, result[N-1].getImaginary(), tolerance);
+        for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
+            Assert.assertEquals(0.0, result[i].getReal(), tolerance);
+            Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
         }
     }
 
-    private static void doTestTransformFunction(final UnivariateFunction f,
-        final double min, final double max, int n, final double tol,
-        final boolean forward, final boolean standard) {
-        final FastFourierTransformer fft;
-        if (standard) {
-            fft = FastFourierTransformer.create();
-        } else {
-            fft = FastFourierTransformer.createUnitary();
-        }
-        final Complex[] x = new Complex[n];
-        for (int i = 0; i < n; i++) {
-            final double t = min + i * (max - min) / n;
-            x[i] = new Complex(f.value(t));
+    /*
+     * Additional tests for 2D data.
+     */
+
+    @Test
+    public void test2DData() {
+        FastFourierTransformer transformer = FastFourierTransformer.create();
+        double tolerance = 1E-12;
+        Complex[][] input = new Complex[][] {new Complex[] {new Complex(1, 0),
+                                                            new Complex(2, 0)},
+                                             new Complex[] {new Complex(3, 1),
+                                                            new Complex(4, 2)}};
+        Complex[][] goodOutput = new Complex[][] {new Complex[] {new Complex(5,
+                1.5), new Complex(-1, -.5)}, new Complex[] {new Complex(-2,
+                -1.5), new Complex(0, .5)}};
+        for (int i = 0; i < goodOutput.length; i++) {
+            TransformUtils.scaleArray(
+                goodOutput[i],
+                FastMath.sqrt(goodOutput[i].length) *
+                    FastMath.sqrt(goodOutput.length));
         }
-        final Complex[] expected;
-        final Complex[] actual;
-        final double s;
-        if (forward) {
-            expected = dft(x, -1);
-            s = standard ? 1.0 : 1.0 / FastMath.sqrt(n);
-            actual = fft.transform(f, min, max, n);
-        } else {
-            expected = dft(x, 1);
-            s = standard ? 1.0 / n : 1.0 / FastMath.sqrt(n);
-            actual = fft.inverseTransform(f, min, max, n);
+        Complex[][] output = (Complex[][])transformer.mdfft(input, true);
+        Complex[][] output2 = (Complex[][])transformer.mdfft(output, false);
+
+        Assert.assertEquals(input.length, output.length);
+        Assert.assertEquals(input.length, output2.length);
+        Assert.assertEquals(input[0].length, output[0].length);
+        Assert.assertEquals(input[0].length, output2[0].length);
+        Assert.assertEquals(input[1].length, output[1].length);
+        Assert.assertEquals(input[1].length, output2[1].length);
+
+        for (int i = 0; i < input.length; i++) {
+            for (int j = 0; j < input[0].length; j++) {
+                Assert.assertEquals(input[i][j].getImaginary(), output2[i][j].getImaginary(),
+                             tolerance);
+                Assert.assertEquals(input[i][j].getReal(), output2[i][j].getReal(), tolerance);
+                Assert.assertEquals(goodOutput[i][j].getImaginary(), output[i][j].getImaginary(),
+                             tolerance);
+                Assert.assertEquals(goodOutput[i][j].getReal(), output[i][j].getReal(), tolerance);
+            }
         }
-        for (int i = 0; i < n; i++) {
-            final String msg = String.format("%d, %d", n, i);
-            final double re = s * expected[i].getReal();
-            Assert.assertEquals(msg, re, actual[i].getReal(),
-                tol * FastMath.abs(re));
-            final double im = s * expected[i].getImaginary();
-            Assert.assertEquals(msg, im, actual[i].getImaginary(), tol *
-                FastMath.abs(re));
+    }
+
+    @Test
+    public void test2DDataUnitary() {
+        FastFourierTransformer transformer = FastFourierTransformer.createUnitary();
+        double tolerance = 1E-12;
+        Complex[][] input = new Complex[][] {new Complex[] {new Complex(1, 0),
+                                                            new Complex(2, 0)},
+                                             new Complex[] {new Complex(3, 1),
+                                                            new Complex(4, 2)}};
+        Complex[][] goodOutput = new Complex[][] {new Complex[] {new Complex(5,
+                1.5), new Complex(-1, -.5)}, new Complex[] {new Complex(-2,
+                -1.5), new Complex(0, .5)}};
+        Complex[][] output = (Complex[][])transformer.mdfft(input, true);
+        Complex[][] output2 = (Complex[][])transformer.mdfft(output, false);
+
+        Assert.assertEquals(input.length, output.length);
+        Assert.assertEquals(input.length, output2.length);
+        Assert.assertEquals(input[0].length, output[0].length);
+        Assert.assertEquals(input[0].length, output2[0].length);
+        Assert.assertEquals(input[1].length, output[1].length);
+        Assert.assertEquals(input[1].length, output2[1].length);
+
+        for (int i = 0; i < input.length; i++) {
+            for (int j = 0; j < input[0].length; j++) {
+                Assert.assertEquals(input[i][j].getImaginary(), output2[i][j].getImaginary(),
+                             tolerance);
+                Assert.assertEquals(input[i][j].getReal(), output2[i][j].getReal(), tolerance);
+                Assert.assertEquals(goodOutput[i][j].getImaginary(), output[i][j].getImaginary(),
+                             tolerance);
+                Assert.assertEquals(goodOutput[i][j].getReal(), output[i][j].getReal(), tolerance);
+            }
         }
     }
+
 }



Mime
View raw message