Repository: commons-math Updated Branches: refs/heads/feature-MATH-1015 93d35c8f2 -> bbd702ae2
MATH-736 Removed methods deprecated 4 years ago. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f695c9ce Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f695c9ce Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f695c9ce Branch: refs/heads/feature-MATH-1015 Commit: f695c9ce35dfcc4ed76343ce7a904f2facb45944 Parents: cbae75b Author: Gilles <er...@apache.org> Authored: Sat May 7 02:18:14 2016 +0200 Committer: Gilles <er...@apache.org> Committed: Sat May 7 02:18:14 2016 +0200 ---------------------------------------------------------------------- .../math4/transform/FastFourierTransformer.java | 257 ------------------- .../transform/FastFourierTransformerTest.java | 80 ------ 2 files changed, 337 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/f695c9ce/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java b/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java index 5f3f8c3..d599f7c 100644 --- a/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java +++ b/src/main/java/org/apache/commons/math4/transform/FastFourierTransformer.java @@ -17,8 +17,6 @@ package org.apache.commons.math4.transform; import java.io.Serializable; -import java.lang.reflect.Array; - import org.apache.commons.math4.analysis.FunctionUtils; import org.apache.commons.math4.analysis.UnivariateFunction; import org.apache.commons.math4.complex.Complex; @@ -51,7 +49,6 @@ import org.apache.commons.math4.util.MathArrays; * @since 1.2 */ public class FastFourierTransformer implements Serializable { - /** Serializable version identifier. */ static final long serialVersionUID = 20120210L; @@ -416,258 +413,4 @@ public class FastFourierTransformer implements Serializable { return TransformUtils.createComplexArray(dataRI); } - - /** - * Performs a multi-dimensional Fourier transform on a given array. Use - * {@link #transform(Complex[], TransformType)} in a row-column - * implementation in any number of dimensions with - * O(N×log(N)) complexity with - * N = n<sub>1</sub> × n<sub>2</sub> ×n<sub>3</sub> × ... - * × n<sub>d</sub>, where n<sub>k</sub> is the number of elements in - * dimension k, and d is the total number of dimensions. - * - * @param mdca Multi-Dimensional Complex Array, i.e. {@code Complex[][][][]} - * @param type the type of transform (forward, inverse) to be performed - * @return transform of {@code mdca} as a Multi-Dimensional Complex Array, i.e. {@code Complex[][][][]} - * @throws IllegalArgumentException if any dimension is not a power of two - * @deprecated see MATH-736 - */ - @Deprecated - public Object mdfft(Object mdca, TransformType type) { - MultiDimensionalComplexMatrix mdcm = (MultiDimensionalComplexMatrix) - new MultiDimensionalComplexMatrix(mdca).clone(); - int[] dimensionSize = mdcm.getDimensionSizes(); - //cycle through each dimension - for (int i = 0; i < dimensionSize.length; i++) { - mdfft(mdcm, type, i, new int[0]); - } - return mdcm.getArray(); - } - - /** - * Performs one dimension of a multi-dimensional Fourier transform. - * - * @param mdcm input matrix - * @param type the type of transform (forward, inverse) to be performed - * @param d index of the dimension to process - * @param subVector recursion subvector - * @throws IllegalArgumentException if any dimension is not a power of two - * @deprecated see MATH-736 - */ - @Deprecated - private void mdfft(MultiDimensionalComplexMatrix mdcm, - TransformType type, int d, int[] subVector) { - - int[] dimensionSize = mdcm.getDimensionSizes(); - //if done - if (subVector.length == dimensionSize.length) { - Complex[] temp = new Complex[dimensionSize[d]]; - for (int i = 0; i < dimensionSize[d]; i++) { - //fft along dimension d - subVector[d] = i; - temp[i] = mdcm.get(subVector); - } - - temp = transform(temp, type); - - for (int i = 0; i < dimensionSize[d]; i++) { - subVector[d] = i; - mdcm.set(temp[i], subVector); - } - } else { - int[] vector = new int[subVector.length + 1]; - System.arraycopy(subVector, 0, vector, 0, subVector.length); - if (subVector.length == d) { - //value is not important once the recursion is done. - //then an fft will be applied along the dimension d. - vector[d] = 0; - mdfft(mdcm, type, d, vector); - } else { - for (int i = 0; i < dimensionSize[subVector.length]; i++) { - vector[subVector.length] = i; - //further split along the next dimension - mdfft(mdcm, type, d, vector); - } - } - } - } - - /** - * Complex matrix implementation. Not designed for synchronized access may - * eventually be replaced by jsr-83 of the java community process - * http://jcp.org/en/jsr/detail?id=83 - * may require additional exception throws for other basic requirements. - * - * @deprecated see MATH-736 - */ - @Deprecated - private static class MultiDimensionalComplexMatrix - implements Cloneable { - - /** Size in all dimensions. */ - protected int[] dimensionSize; - - /** Storage array. */ - protected Object multiDimensionalComplexArray; - - /** - * Simple constructor. - * - * @param multiDimensionalComplexArray array containing the matrix - * elements - */ - MultiDimensionalComplexMatrix(Object multiDimensionalComplexArray) { - - this.multiDimensionalComplexArray = multiDimensionalComplexArray; - - // count dimensions - int numOfDimensions = 0; - for (Object lastDimension = multiDimensionalComplexArray; - lastDimension instanceof Object[];) { - final Object[] array = (Object[]) lastDimension; - numOfDimensions++; - 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]; - } - - } - - /** - * Get a matrix element. - * - * @param vector indices of the element - * @return matrix element - * @exception DimensionMismatchException if dimensions do not match - */ - public Complex get(int... vector) - throws DimensionMismatchException { - - if (vector == null) { - if (dimensionSize.length > 0) { - throw new DimensionMismatchException( - 0, - dimensionSize.length); - } - return null; - } - if (vector.length != dimensionSize.length) { - throw new DimensionMismatchException( - vector.length, - dimensionSize.length); - } - - Object lastDimension = multiDimensionalComplexArray; - - for (int i = 0; i < dimensionSize.length; i++) { - lastDimension = ((Object[]) lastDimension)[vector[i]]; - } - return (Complex) lastDimension; - } - - /** - * Set a matrix element. - * - * @param magnitude magnitude of the element - * @param vector indices of the element - * @return the previous value - * @exception DimensionMismatchException if dimensions do not match - */ - public Complex set(Complex magnitude, int... vector) - throws DimensionMismatchException { - - if (vector == null) { - if (dimensionSize.length > 0) { - throw new DimensionMismatchException( - 0, - dimensionSize.length); - } - return null; - } - if (vector.length != dimensionSize.length) { - throw new DimensionMismatchException( - vector.length, - dimensionSize.length); - } - - Object[] lastDimension = (Object[]) multiDimensionalComplexArray; - for (int i = 0; i < dimensionSize.length - 1; i++) { - lastDimension = (Object[]) lastDimension[vector[i]]; - } - - Complex lastValue = (Complex) lastDimension[vector[dimensionSize.length - 1]]; - lastDimension[vector[dimensionSize.length - 1]] = magnitude; - - return lastValue; - } - - /** - * Get the size in all dimensions. - * - * @return size in all dimensions - */ - public int[] getDimensionSizes() { - return dimensionSize.clone(); - } - - /** - * Get the underlying storage array. - * - * @return underlying storage array - */ - public Object getArray() { - return multiDimensionalComplexArray; - } - - /** {@inheritDoc} */ - @Override - public Object clone() { - MultiDimensionalComplexMatrix mdcm = - new MultiDimensionalComplexMatrix(Array.newInstance( - Complex.class, dimensionSize)); - clone(mdcm); - return mdcm; - } - - /** - * Copy contents of current array into mdcm. - * - * @param mdcm array where to copy data - */ - private void clone(MultiDimensionalComplexMatrix mdcm) { - - int[] vector = new int[dimensionSize.length]; - int size = 1; - for (int i = 0; i < dimensionSize.length; i++) { - size *= dimensionSize[i]; - } - int[][] vectorList = new int[size][dimensionSize.length]; - for (int[] nextVector : vectorList) { - System.arraycopy(vector, 0, nextVector, 0, - dimensionSize.length); - for (int i = 0; i < dimensionSize.length; i++) { - vector[i]++; - if (vector[i] < dimensionSize[i]) { - break; - } else { - vector[i] = 0; - } - } - } - - for (int[] nextVector : vectorList) { - mdcm.set(get(nextVector), nextVector); - } - } - } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/f695c9ce/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java b/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java index cb1e682..e520269 100644 --- a/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java +++ b/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java @@ -483,84 +483,4 @@ public final class FastFourierTransformerTest { Assert.assertEquals(0.0, result[i].getImaginary(), tolerance); } } - - /* - * Additional tests for 2D data. - */ - - @Test - public void test2DData() { - FastFourierTransformer transformer; - transformer = new FastFourierTransformer(DftNormalization.STANDARD); - - 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, TransformType.FORWARD); - Complex[][] output2 = (Complex[][])transformer.mdfft(output, TransformType.INVERSE); - - 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); - } - } - } - - @Test - public void test2DDataUnitary() { - FastFourierTransformer transformer; - transformer = new FastFourierTransformer(DftNormalization.UNITARY); - 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, TransformType.FORWARD); - Complex[][] output2 = (Complex[][])transformer.mdfft(output, TransformType.INVERSE); - - 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); - } - } - } - }