This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch modularized_master in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 7e219ce34f998335645e28d94462213d8e37c7aa Author: Gilles Sadowski <gillese...@gmail.com> AuthorDate: Sun May 23 04:15:52 2021 +0200 Move normalization specifiers into their respective corresponding class. --- commons-math-transform/pom.xml | 2 +- .../commons/math4/transform/DctNormalization.java | 62 --------------------- .../commons/math4/transform/DftNormalization.java | 56 ------------------- .../commons/math4/transform/DstNormalization.java | 52 ------------------ .../math4/transform/FastCosineTransform.java | 58 +++++++++++++++++--- .../math4/transform/FastFourierTransform.java | 48 +++++++++++++--- .../commons/math4/transform/FastSineTransform.java | 48 +++++++++++++--- .../math4/transform/FastCosineTransformerTest.java | 28 +++++----- .../transform/FastFourierTransformerTest.java | 64 ++++++++++------------ .../math4/transform/FastSineTransformerTest.java | 28 +++++----- 10 files changed, 190 insertions(+), 256 deletions(-) diff --git a/commons-math-transform/pom.xml b/commons-math-transform/pom.xml index 632ab2c..ae76e4a 100644 --- a/commons-math-transform/pom.xml +++ b/commons-math-transform/pom.xml @@ -73,7 +73,7 @@ <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <rerunFailingTestsCount>3</rerunFailingTestsCount> + <rerunFailingTestsCount>4</rerunFailingTestsCount> </configuration> </plugin> </plugins> diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DctNormalization.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DctNormalization.java deleted file mode 100644 index fa77fae..0000000 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DctNormalization.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.transform; - -/** - * This enumeration defines the various types of normalizations that can be - * applied to discrete cosine transforms (DCT). - */ -public enum DctNormalization { - /** - * Should be passed to the constructor of {@link FastCosineTransform} - * to use the <em>standard</em> normalization convention. The standard - * DCT-I normalization convention is defined as follows - * <ul> - * <li>forward transform: - * y<sub>n</sub> = (1/2) [x<sub>0</sub> + (-1)<sup>n</sup>x<sub>N-1</sub>] - * + ∑<sub>k=1</sub><sup>N-2</sup> - * x<sub>k</sub> cos[π nk / (N - 1)],</li> - * <li>inverse transform: - * x<sub>k</sub> = [1 / (N - 1)] [y<sub>0</sub> - * + (-1)<sup>k</sup>y<sub>N-1</sub>] - * + [2 / (N - 1)] ∑<sub>n=1</sub><sup>N-2</sup> - * y<sub>n</sub> cos[π nk / (N - 1)],</li> - * </ul> - * where N is the size of the data sample. - */ - STANDARD_DCT_I, - - /** - * Should be passed to the constructor of {@link FastCosineTransform} - * to use the <em>orthogonal</em> normalization convention. The orthogonal - * DCT-I normalization convention is defined as follows - * <ul> - * <li>forward transform: - * y<sub>n</sub> = [2(N - 1)]<sup>-1/2</sup> [x<sub>0</sub> - * + (-1)<sup>n</sup>x<sub>N-1</sub>] - * + [2 / (N - 1)]<sup>1/2</sup> ∑<sub>k=1</sub><sup>N-2</sup> - * x<sub>k</sub> cos[π nk / (N - 1)],</li> - * <li>inverse transform: - * x<sub>k</sub> = [2(N - 1)]<sup>-1/2</sup> [y<sub>0</sub> - * + (-1)<sup>k</sup>y<sub>N-1</sub>] - * + [2 / (N - 1)]<sup>1/2</sup> ∑<sub>n=1</sub><sup>N-2</sup> - * y<sub>n</sub> cos[π nk / (N - 1)],</li> - * </ul> - * which makes the transform orthogonal. N is the size of the data sample. - */ - ORTHOGONAL_DCT_I; -} diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DftNormalization.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DftNormalization.java deleted file mode 100644 index 1198860..0000000 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DftNormalization.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.transform; - -/** - * This enumeration defines the various types of normalizations that can be - * applied to discrete Fourier transforms (DFT). The exact definition of these - * normalizations is detailed below. - * - * @see FastFourierTransform - * @since 3.0 - */ -public enum DftNormalization { - /** - * Should be passed to the constructor of {@link FastFourierTransformer} - * to use the <em>standard</em> normalization convention. This normalization - * convention is defined as follows - * <ul> - * <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup> - * x<sub>k</sub> exp(-2πi n k / N),</li> - * <li>inverse transform: x<sub>k</sub> = N<sup>-1</sup> - * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2πi n k / N),</li> - * </ul> - * where N is the size of the data sample. - */ - STANDARD, - - /** - * Should be passed to the constructor of {@link FastFourierTransformer} - * to use the <em>unitary</em> normalization convention. This normalization - * convention is defined as follows - * <ul> - * <li>forward transform: y<sub>n</sub> = (1 / √N) - * ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> - * exp(-2πi n k / N),</li> - * <li>inverse transform: x<sub>k</sub> = (1 / √N) - * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2πi n k / N),</li> - * </ul> - * which makes the transform unitary. N is the size of the data sample. - */ - UNITARY; -} diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DstNormalization.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DstNormalization.java deleted file mode 100644 index 4e9ab03..0000000 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/DstNormalization.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math4.transform; - -/** - * This enumeration defines the various types of normalizations that can be - * applied to discrete sine transforms (DST). - */ -public enum DstNormalization { - /** - * Should be passed to the constructor of {@link FastSineTransform} to - * use the <em>standard</em> normalization convention. The standard DST-I - * normalization convention is defined as follows - * <ul> - * <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup> - * x<sub>k</sub> sin(π nk / N),</li> - * <li>inverse transform: x<sub>k</sub> = (2 / N) - * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li> - * </ul> - * where N is the size of the data sample, and x<sub>0</sub> = 0. - */ - STANDARD_DST_I, - - /** - * Should be passed to the constructor of {@link FastSineTransform} to - * use the <em>orthogonal</em> normalization convention. The orthogonal - * DCT-I normalization convention is defined as follows - * <ul> - * <li>Forward transform: y<sub>n</sub> = √(2 / N) - * ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> sin(π nk / N),</li> - * <li>Inverse transform: x<sub>k</sub> = √(2 / N) - * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li> - * </ul> - * which makes the transform orthogonal. N is the size of the data sample, - * and x<sub>0</sub> = 0. - */ - ORTHOGONAL_DST_I -} diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastCosineTransform.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastCosineTransform.java index 0aa2863..7b47acc 100644 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastCosineTransform.java +++ b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastCosineTransform.java @@ -29,7 +29,7 @@ import org.apache.commons.numbers.core.ArithmeticUtils; * <p> * There are several variants of the discrete cosine transform. The present * implementation corresponds to DCT-I, with various normalization conventions, - * which are specified by the parameter {@link DctNormalization}. + * which are specified by the parameter {@link Norm}. * <p> * DCT-I is equivalent to DFT of an <em>even extension</em> of the data series. * More precisely, if x<sub>0</sub>, …, x<sub>N-1</sub> is the data set @@ -65,7 +65,7 @@ public class FastCosineTransform implements RealTransform { * transformed data. * @param inverse Whether to perform the inverse transform. */ - public FastCosineTransform(final DctNormalization normalization, + public FastCosineTransform(final Norm normalization, final boolean inverse) { op = create(normalization, inverse); } @@ -74,7 +74,7 @@ public class FastCosineTransform implements RealTransform { * @param normalization Normalization to be applied to the * transformed data. */ - public FastCosineTransform(final DctNormalization normalization) { + public FastCosineTransform(final Norm normalization) { this(normalization, false); } @@ -146,7 +146,7 @@ public class FastCosineTransform implements RealTransform { x[nMi] = a + b; t1 += c; } - final FastFourierTransform transformer = new FastFourierTransform(DftNormalization.STANDARD, + final FastFourierTransform transformer = new FastFourierTransform(FastFourierTransform.Norm.STD, false); final Complex[] y = transformer.apply(x); @@ -171,16 +171,60 @@ public class FastCosineTransform implements RealTransform { * @param inverse Whether to perform the inverse transform. * @return the transform operator. */ - private UnaryOperator<double[]> create(final DctNormalization normalization, + private UnaryOperator<double[]> create(final Norm normalization, final boolean inverse) { if (inverse) { - return normalization == DctNormalization.ORTHOGONAL_DCT_I ? + return normalization == Norm.ORTHO ? (f) -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) : (f) -> TransformUtils.scaleInPlace(fct(f), 2d / (f.length - 1)); } else { - return normalization == DctNormalization.ORTHOGONAL_DCT_I ? + return normalization == Norm.ORTHO ? (f) -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) : (f) -> fct(f); } } + + /** + * Normalization types. + */ + public enum Norm { + /** + * Should be passed to the constructor of {@link FastCosineTransform} + * to use the <em>standard</em> normalization convention. The standard + * DCT-I normalization convention is defined as follows + * <ul> + * <li>forward transform: + * y<sub>n</sub> = (1/2) [x<sub>0</sub> + (-1)<sup>n</sup>x<sub>N-1</sub>] + * + ∑<sub>k=1</sub><sup>N-2</sup> + * x<sub>k</sub> cos[π nk / (N - 1)],</li> + * <li>inverse transform: + * x<sub>k</sub> = [1 / (N - 1)] [y<sub>0</sub> + * + (-1)<sup>k</sup>y<sub>N-1</sub>] + * + [2 / (N - 1)] ∑<sub>n=1</sub><sup>N-2</sup> + * y<sub>n</sub> cos[π nk / (N - 1)],</li> + * </ul> + * where N is the size of the data sample. + */ + STD, + + /** + * Should be passed to the constructor of {@link FastCosineTransform} + * to use the <em>orthogonal</em> normalization convention. The orthogonal + * DCT-I normalization convention is defined as follows + * <ul> + * <li>forward transform: + * y<sub>n</sub> = [2(N - 1)]<sup>-1/2</sup> [x<sub>0</sub> + * + (-1)<sup>n</sup>x<sub>N-1</sub>] + * + [2 / (N - 1)]<sup>1/2</sup> ∑<sub>k=1</sub><sup>N-2</sup> + * x<sub>k</sub> cos[π nk / (N - 1)],</li> + * <li>inverse transform: + * x<sub>k</sub> = [2(N - 1)]<sup>-1/2</sup> [y<sub>0</sub> + * + (-1)<sup>k</sup>y<sub>N-1</sub>] + * + [2 / (N - 1)]<sup>1/2</sup> ∑<sub>n=1</sub><sup>N-2</sup> + * y<sub>n</sub> cos[π nk / (N - 1)],</li> + * </ul> + * which makes the transform orthogonal. N is the size of the data sample. + */ + ORTHO; + } } diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastFourierTransform.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastFourierTransform.java index be704af..d11d74c 100644 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastFourierTransform.java +++ b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastFourierTransform.java @@ -29,7 +29,7 @@ import org.apache.commons.numbers.complex.Complex; * <p> * There are several variants of the discrete Fourier transform, with various * normalization conventions, which are specified by the parameter - * {@link DftNormalization}. + * {@link Norm}. * <p> * The current implementation of the discrete Fourier transform as a fast * Fourier transform requires the length of the data set to be a power of 2. @@ -38,8 +38,6 @@ import org.apache.commons.numbers.complex.Complex; * reference, see S. Winograd, * <i>On computing the discrete Fourier transform</i>, Mathematics of * Computation, 32 (1978), 175 - 199. - * - * @see DftNormalization */ public class FastFourierTransform implements ComplexTransform { /** @@ -89,7 +87,7 @@ public class FastFourierTransform implements ComplexTransform { -0x1.921fb54442d18p-58, -0x1.921fb54442d18p-59, -0x1.921fb54442d18p-60 }; /** Type of DFT. */ - private final DftNormalization normalization; + private final Norm normalization; /** Inverse or forward. */ private final boolean inverse; @@ -98,7 +96,7 @@ public class FastFourierTransform implements ComplexTransform { * transformed data. * @param inverse Whether to perform the inverse transform. */ - public FastFourierTransform(final DftNormalization normalization, + public FastFourierTransform(final Norm normalization, final boolean inverse) { this.normalization = normalization; this.inverse = inverse; @@ -108,7 +106,7 @@ public class FastFourierTransform implements ComplexTransform { * @param normalization Normalization to be applied to the * transformed data. */ - public FastFourierTransform(final DftNormalization normalization) { + public FastFourierTransform(final Norm normalization) { this(normalization, false); } @@ -331,7 +329,7 @@ public class FastFourierTransform implements ComplexTransform { final int n = dataR.length; switch (normalization) { - case STANDARD: + case STD: if (inverse) { final double scaleFactor = 1d / n; for (int i = 0; i < n; i++) { @@ -342,7 +340,7 @@ public class FastFourierTransform implements ComplexTransform { break; - case UNITARY: + case UNIT: final double scaleFactor = 1d / Math.sqrt(n); for (int i = 0; i < n; i++) { dataR[i] *= scaleFactor; @@ -394,4 +392,38 @@ public class FastFourierTransform implements ComplexTransform { j += k; } } + + /** + * Normalization types. + */ + public enum Norm { + /** + * Should be passed to the constructor of {@link FastFourierTransformer} + * to use the <em>standard</em> normalization convention. This normalization + * convention is defined as follows + * <ul> + * <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup> + * x<sub>k</sub> exp(-2πi n k / N),</li> + * <li>inverse transform: x<sub>k</sub> = N<sup>-1</sup> + * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2πi n k / N),</li> + * </ul> + * where N is the size of the data sample. + */ + STD, + + /** + * Should be passed to the constructor of {@link FastFourierTransformer} + * to use the <em>unitary</em> normalization convention. This normalization + * convention is defined as follows + * <ul> + * <li>forward transform: y<sub>n</sub> = (1 / √N) + * ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> + * exp(-2πi n k / N),</li> + * <li>inverse transform: x<sub>k</sub> = (1 / √N) + * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> exp(2πi n k / N),</li> + * </ul> + * which makes the transform unitary. N is the size of the data sample. + */ + UNIT; + } } diff --git a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastSineTransform.java b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastSineTransform.java index da3c63b..4b37646 100644 --- a/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastSineTransform.java +++ b/commons-math-transform/src/main/java/org/apache/commons/math4/transform/FastSineTransform.java @@ -29,7 +29,7 @@ import org.apache.commons.numbers.core.ArithmeticUtils; * <p> * There are several variants of the discrete sine transform. The present * implementation corresponds to DST-I, with various normalization conventions, - * which are specified by the parameter {@link DstNormalization}. + * which are specified by the parameter {@link Norm}. * <strong>It should be noted that regardless to the convention, the first * element of the dataset to be transformed must be zero.</strong> * <p> @@ -69,7 +69,7 @@ public class FastSineTransform implements RealTransform { * @param normalization Normalization to be applied to the transformed data. * @param inverse Whether to perform the inverse transform. */ - public FastSineTransform(final DstNormalization normalization, + public FastSineTransform(final Norm normalization, final boolean inverse) { op = create(normalization, inverse); } @@ -78,7 +78,7 @@ public class FastSineTransform implements RealTransform { * @param normalization Normalization to be applied to the * transformed data. */ - public FastSineTransform(final DstNormalization normalization) { + public FastSineTransform(final Norm normalization) { this(normalization, false); } @@ -156,7 +156,7 @@ public class FastSineTransform implements RealTransform { x[nMi] = a - b; } - final FastFourierTransform transform = new FastFourierTransform(DftNormalization.STANDARD); + final FastFourierTransform transform = new FastFourierTransform(FastFourierTransform.Norm.STD); final Complex[] y = transform.apply(x); // reconstruct the FST result for the original array @@ -179,16 +179,50 @@ public class FastSineTransform implements RealTransform { * @param inverse Whether to perform the inverse transform. * @return the transform operator. */ - private UnaryOperator<double[]> create(final DstNormalization normalization, + private UnaryOperator<double[]> create(final Norm normalization, final boolean inverse) { if (inverse) { - return normalization == DstNormalization.ORTHOGONAL_DST_I ? + return normalization == Norm.ORTHO ? (f) -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) : (f) -> TransformUtils.scaleInPlace(fst(f), 2d / f.length); } else { - return normalization == DstNormalization.ORTHOGONAL_DST_I ? + return normalization == Norm.ORTHO ? (f) -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) : (f) -> fst(f); } } + + /** + * Normalization types. + */ + public enum Norm { + /** + * Should be passed to the constructor of {@link FastSineTransform} to + * use the <em>standard</em> normalization convention. The standard DST-I + * normalization convention is defined as follows + * <ul> + * <li>forward transform: y<sub>n</sub> = ∑<sub>k=0</sub><sup>N-1</sup> + * x<sub>k</sub> sin(π nk / N),</li> + * <li>inverse transform: x<sub>k</sub> = (2 / N) + * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li> + * </ul> + * where N is the size of the data sample, and x<sub>0</sub> = 0. + */ + STD, + + /** + * Should be passed to the constructor of {@link FastSineTransform} to + * use the <em>orthogonal</em> normalization convention. The orthogonal + * DCT-I normalization convention is defined as follows + * <ul> + * <li>Forward transform: y<sub>n</sub> = √(2 / N) + * ∑<sub>k=0</sub><sup>N-1</sup> x<sub>k</sub> sin(π nk / N),</li> + * <li>Inverse transform: x<sub>k</sub> = √(2 / N) + * ∑<sub>n=0</sub><sup>N-1</sup> y<sub>n</sub> sin(π nk / N),</li> + * </ul> + * which makes the transform orthogonal. N is the size of the data sample, + * and x<sub>0</sub> = 0. + */ + ORTHO + } } diff --git a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastCosineTransformerTest.java b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastCosineTransformerTest.java index 41212a4..c4d5a8f 100644 --- a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastCosineTransformerTest.java +++ b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastCosineTransformerTest.java @@ -40,7 +40,7 @@ import org.apache.commons.math3.analysis.function.Sinc; public final class FastCosineTransformerTest extends RealTransformerAbstractTest { - private final DctNormalization normalization; + private final FastCosineTransform.Norm normalization; private final int[] invalidDataSize; @@ -48,7 +48,7 @@ public final class FastCosineTransformerTest private final int[] validDataSize; - public FastCosineTransformerTest(final DctNormalization normalization) { + public FastCosineTransformerTest(final FastCosineTransform.Norm normalization) { this.normalization = normalization; this.validDataSize = new int[] { 2, 3, 5, 9, 17, 33, 65, 129 @@ -69,8 +69,8 @@ public final class FastCosineTransformerTest */ @Parameters public static Collection<Object[]> data() { - final DctNormalization[] normalization = DctNormalization.values(); - final Object[][] data = new DctNormalization[normalization.length][1]; + final FastCosineTransform.Norm[] normalization = FastCosineTransform.Norm.values(); + final Object[][] data = new FastCosineTransform.Norm[normalization.length][1]; for (int i = 0; i < normalization.length; i++){ data[i][0] = normalization[i]; } @@ -143,17 +143,17 @@ public final class FastCosineTransformerTest } final double s; if (!inverse) { - if (normalization == DctNormalization.STANDARD_DCT_I) { + if (normalization == FastCosineTransform.Norm.STD) { s = 1.0; - } else if (normalization == DctNormalization.ORTHOGONAL_DCT_I) { + } else if (normalization == FastCosineTransform.Norm.ORTHO) { s = Math.sqrt(2.0 / (n - 1.0)); } else { throw new IllegalStateException(); } } else { - if (normalization == DctNormalization.STANDARD_DCT_I) { + if (normalization == FastCosineTransform.Norm.STD) { s = 2.0 / (n - 1.0); - } else if (normalization == DctNormalization.ORTHOGONAL_DCT_I) { + } else if (normalization == FastCosineTransform.Norm.ORTHO) { s = Math.sqrt(2.0 / (n - 1.0)); } else { throw new IllegalStateException(); @@ -180,13 +180,13 @@ public final class FastCosineTransformerTest 4.0 }; - transformer = new FastCosineTransform(DctNormalization.STANDARD_DCT_I); + transformer = new FastCosineTransform(FastCosineTransform.Norm.STD); result = transformer.apply(x); for (int i = 0; i < result.length; i++) { Assert.assertEquals(y[i], result[i], tolerance); } - transformer = new FastCosineTransform(DctNormalization.STANDARD_DCT_I, true); + transformer = new FastCosineTransform(FastCosineTransform.Norm.STD, true); result = transformer.apply(y); for (int i = 0; i < result.length; i++) { Assert.assertEquals(x[i], result[i], tolerance); @@ -194,13 +194,13 @@ public final class FastCosineTransformerTest TransformUtils.scaleInPlace(x, Math.sqrt(0.5 * (x.length - 1))); - transformer = new FastCosineTransform(DctNormalization.ORTHOGONAL_DCT_I); + transformer = new FastCosineTransform(FastCosineTransform.Norm.ORTHO); result = transformer.apply(y); for (int i = 0; i < result.length; i++) { Assert.assertEquals(x[i], result[i], tolerance); } - transformer = new FastCosineTransform(DctNormalization.ORTHOGONAL_DCT_I, true); + transformer = new FastCosineTransform(FastCosineTransform.Norm.ORTHO, true); result = transformer.apply(x); for (int i = 0; i < result.length; i++) { Assert.assertEquals(y[i], result[i], tolerance); @@ -212,7 +212,7 @@ public final class FastCosineTransformerTest public void testParameters() throws Exception { final UnivariateFunction sinFunction = new Sin(); final DoubleUnaryOperator f = (x) -> sinFunction.value(x); - final FastCosineTransform transformer = new FastCosineTransform(DctNormalization.STANDARD_DCT_I); + final FastCosineTransform transformer = new FastCosineTransform(FastCosineTransform.Norm.STD); try { // bad interval @@ -242,7 +242,7 @@ public final class FastCosineTransformerTest public void testSinFunction() { final UnivariateFunction sinFunction = new Sin(); final DoubleUnaryOperator f = (x) -> sinFunction.value(x); - final FastCosineTransform transformer = new FastCosineTransform(DctNormalization.STANDARD_DCT_I); + final FastCosineTransform transformer = new FastCosineTransform(FastCosineTransform.Norm.STD); double min, max, result[], tolerance = 1e-12; int N = 9; diff --git a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java index 4653d02..2e3e3d6 100644 --- a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java +++ b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastFourierTransformerTest.java @@ -48,8 +48,7 @@ public final class FastFourierTransformerTest { public void testTransformComplexSizeNotAPowerOfTwo() { final int n = 127; final Complex[] x = createComplexData(n); - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { final FastFourierTransform fft = new FastFourierTransform(norm[i], type); @@ -68,8 +67,7 @@ public final class FastFourierTransformerTest { public void testTransformRealSizeNotAPowerOfTwo() { final int n = 127; final double[] x = createRealData(n); - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { final FastFourierTransform fft = new FastFourierTransform(norm[i], type); @@ -87,8 +85,7 @@ public final class FastFourierTransformerTest { @Test public void testTransformFunctionSizeNotAPowerOfTwo() { final int n = 127; - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { final FastFourierTransform fft = new FastFourierTransform(norm[i], type); @@ -106,8 +103,7 @@ public final class FastFourierTransformerTest { @Test public void testTransformFunctionNotStrictlyPositiveNumberOfSamples() { final int n = -128; - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { final FastFourierTransform fft = new FastFourierTransform(norm[i], type); @@ -126,8 +122,7 @@ public final class FastFourierTransformerTest { @Test public void testTransformFunctionInvalidBounds() { final int n = 128; - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { final FastFourierTransform fft = new FastFourierTransform(norm[i], type); @@ -192,7 +187,7 @@ public final class FastFourierTransformerTest { private static void doTestTransformComplex(final int n, final double tol, - final DftNormalization normalization, + final FastFourierTransform.Norm normalization, boolean inverse) { final FastFourierTransform fft = new FastFourierTransform(normalization, inverse); final Complex[] x = createComplexData(n); @@ -200,14 +195,14 @@ public final class FastFourierTransformerTest { final double s; if (!inverse) { expected = dft(x, -1); - if (normalization == DftNormalization.STANDARD){ + if (normalization == FastFourierTransform.Norm.STD){ s = 1.0; } else { s = 1.0 / Math.sqrt(n); } } else { expected = dft(x, 1); - if (normalization == DftNormalization.STANDARD) { + if (normalization == FastFourierTransform.Norm.STD) { s = 1.0 / n; } else { s = 1.0 / Math.sqrt(n); @@ -228,7 +223,7 @@ public final class FastFourierTransformerTest { private static void doTestTransformReal(final int n, final double tol, - final DftNormalization normalization, + final FastFourierTransform.Norm normalization, final boolean inverse) { final FastFourierTransform fft = new FastFourierTransform(normalization, inverse); final double[] x = createRealData(n); @@ -240,14 +235,14 @@ public final class FastFourierTransformerTest { final double s; if (!inverse) { expected = dft(xc, -1); - if (normalization == DftNormalization.STANDARD) { + if (normalization == FastFourierTransform.Norm.STD) { s = 1.0; } else { s = 1.0 / Math.sqrt(n); } } else { expected = dft(xc, 1); - if (normalization == DftNormalization.STANDARD) { + if (normalization == FastFourierTransform.Norm.STD) { s = 1.0 / n; } else { s = 1.0 / Math.sqrt(n); @@ -271,7 +266,7 @@ public final class FastFourierTransformerTest { final double max, int n, final double tol, - final DftNormalization normalization, + final FastFourierTransform.Norm normalization, final boolean inverse) { final FastFourierTransform fft = new FastFourierTransform(normalization, inverse); final Complex[] x = new Complex[n]; @@ -283,14 +278,14 @@ public final class FastFourierTransformerTest { final double s; if (!inverse) { expected = dft(x, -1); - if (normalization == DftNormalization.STANDARD) { + if (normalization == FastFourierTransform.Norm.STD) { s = 1.0; } else { s = 1.0 / Math.sqrt(n); } } else { expected = dft(x, 1); - if (normalization == DftNormalization.STANDARD) { + if (normalization == FastFourierTransform.Norm.STD) { s = 1.0 / n; } else { s = 1.0 / Math.sqrt(n); @@ -312,16 +307,15 @@ public final class FastFourierTransformerTest { @Test public void testTransformComplex() { - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { doTestTransformComplex(2, 1e-15, norm[i], type); doTestTransformComplex(4, 1e-14, norm[i], type); doTestTransformComplex(8, 1e-13, norm[i], type); doTestTransformComplex(16, 1e-13, norm[i], type); - doTestTransformComplex(32, 1e-13, norm[i], type); - doTestTransformComplex(64, 1e-12, norm[i], type); + doTestTransformComplex(32, 1e-12, norm[i], type); + doTestTransformComplex(64, 1e-11, norm[i], type); doTestTransformComplex(128, 1e-11, norm[i], type); } } @@ -329,8 +323,7 @@ public final class FastFourierTransformerTest { @Test public void testStandardTransformReal() { - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { doTestTransformReal(2, 1e-15, norm[i], type); @@ -351,8 +344,7 @@ public final class FastFourierTransformerTest { final double min = -Math.PI; final double max = Math.PI; - final DftNormalization[] norm; - norm = DftNormalization.values(); + final FastFourierTransform.Norm[] norm = FastFourierTransform.Norm.values(); for (int i = 0; i < norm.length; i++) { for (boolean type : new boolean[] { true, false }) { @@ -388,14 +380,14 @@ public final class FastFourierTransformerTest { Complex.ofCartesian(-2.6, -2.7), Complex.ofCartesian(-2.09497474683058, -1.91507575950825)}; - transformer = new FastFourierTransform(DftNormalization.STANDARD); + transformer = new FastFourierTransform(FastFourierTransform.Norm.STD); result = transformer.apply(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); } - transformer = new FastFourierTransform(DftNormalization.STANDARD, true); + transformer = new FastFourierTransform(FastFourierTransform.Norm.STD, true); result = transformer.apply(y); for (int i = 0; i < result.length; i++) { Assert.assertEquals(x[i], result[i].getReal(), tolerance); @@ -406,14 +398,14 @@ public final class FastFourierTransformerTest { TransformUtils.scaleInPlace(x2, 1.0 / Math.sqrt(x2.length)); Complex y2[] = y; - transformer = new FastFourierTransform(DftNormalization.UNITARY); + transformer = new FastFourierTransform(FastFourierTransform.Norm.UNIT); result = transformer.apply(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); } - transformer = new FastFourierTransform(DftNormalization.UNITARY, true); + transformer = new FastFourierTransform(FastFourierTransform.Norm.UNIT, true); result = transformer.apply(x2); for (int i = 0; i < result.length; i++) { Assert.assertEquals(y2[i].getReal(), result[i].getReal(), tolerance); @@ -430,8 +422,9 @@ public final class FastFourierTransformerTest { Complex result[]; int N = 1 << 8; double min, max, tolerance = 1e-12; - min = 0.0; max = 2.0 * Math.PI; - transformer = new FastFourierTransform(DftNormalization.STANDARD); + min = 0.0; + max = 2 * Math.PI; + transformer = new FastFourierTransform(FastFourierTransform.Norm.STD); result = transformer.apply(SIN, min, max, N); Assert.assertEquals(0.0, result[1].getReal(), tolerance); Assert.assertEquals(-(N >> 1), result[1].getImaginary(), tolerance); @@ -442,8 +435,9 @@ public final class FastFourierTransformerTest { Assert.assertEquals(0.0, result[i].getImaginary(), tolerance); } - min = -Math.PI; max = Math.PI; - transformer = new FastFourierTransform(DftNormalization.STANDARD, true); + min = -Math.PI; + max = Math.PI; + transformer = new FastFourierTransform(FastFourierTransform.Norm.STD, true); result = transformer.apply(SIN, min, max, N); Assert.assertEquals(0.0, result[1].getReal(), tolerance); Assert.assertEquals(-0.5, result[1].getImaginary(), tolerance); diff --git a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastSineTransformerTest.java b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastSineTransformerTest.java index aeed09e..e8178f0 100644 --- a/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastSineTransformerTest.java +++ b/commons-math-transform/src/test/java/org/apache/commons/math4/transform/FastSineTransformerTest.java @@ -39,7 +39,7 @@ import org.apache.commons.math3.analysis.function.Sinc; @RunWith(value = Parameterized.class) public final class FastSineTransformerTest extends RealTransformerAbstractTest { - private final DstNormalization normalization; + private final FastSineTransform.Norm normalization; private final int[] invalidDataSize; @@ -47,7 +47,7 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { private final int[] validDataSize; - public FastSineTransformerTest(final DstNormalization normalization) { + public FastSineTransformerTest(final FastSineTransform.Norm normalization) { this.normalization = normalization; this.validDataSize = new int[] { 1, 2, 4, 8, 16, 32, 64, 128 @@ -68,8 +68,8 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { */ @Parameters public static Collection<Object[]> data() { - final DstNormalization[] normalization = DstNormalization.values(); - final Object[][] data = new DstNormalization[normalization.length][1]; + final FastSineTransform.Norm[] normalization = FastSineTransform.Norm.values(); + final Object[][] data = new FastSineTransform.Norm[normalization.length][1]; for (int i = 0; i < normalization.length; i++) { data[i][0] = normalization[i]; } @@ -152,17 +152,17 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { } final double s; if (!inverse) { - if (normalization == DstNormalization.STANDARD_DST_I) { + if (normalization == FastSineTransform.Norm.STD) { s = 1; - } else if (normalization == DstNormalization.ORTHOGONAL_DST_I) { + } else if (normalization == FastSineTransform.Norm.ORTHO) { s = Math.sqrt(2d / n); } else { throw new IllegalStateException(); } } else { - if (normalization == DstNormalization.STANDARD_DST_I) { + if (normalization == FastSineTransform.Norm.STD) { s = 2d / n; - } else if (normalization == DstNormalization.ORTHOGONAL_DST_I) { + } else if (normalization == FastSineTransform.Norm.ORTHO) { s = Math.sqrt(2d / n); } else { throw new IllegalStateException(); @@ -210,27 +210,27 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { -1.65685424949238, 0.795649469518633 }; - transformer = new FastSineTransform(DstNormalization.STANDARD_DST_I); + transformer = new FastSineTransform(FastSineTransform.Norm.STD); result = transformer.apply(x); for (int i = 0; i < result.length; i++) { Assert.assertEquals(y[i], result[i], tolerance); } - transformer = new FastSineTransform(DstNormalization.STANDARD_DST_I, true); + transformer = new FastSineTransform(FastSineTransform.Norm.STD, true); result = transformer.apply(y); for (int i = 0; i < result.length; i++) { Assert.assertEquals(x[i], result[i], tolerance); } TransformUtils.scaleInPlace(x, Math.sqrt(x.length / 2d)); - transformer = new FastSineTransform(DstNormalization.ORTHOGONAL_DST_I); + transformer = new FastSineTransform(FastSineTransform.Norm.ORTHO); result = transformer.apply(y); for (int i = 0; i < result.length; i++) { Assert.assertEquals(x[i], result[i], tolerance); } - transformer = new FastSineTransform(DstNormalization.ORTHOGONAL_DST_I, true); + transformer = new FastSineTransform(FastSineTransform.Norm.ORTHO, true); result = transformer.apply(x); for (int i = 0; i < result.length; i++) { Assert.assertEquals(y[i], result[i], tolerance); @@ -244,7 +244,7 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { public void testSinFunction() { final UnivariateFunction sinFunction = new Sin(); final DoubleUnaryOperator f = (x) -> sinFunction.value(x); - final FastSineTransform transformer = new FastSineTransform(DstNormalization.STANDARD_DST_I); + final FastSineTransform transformer = new FastSineTransform(FastSineTransform.Norm.STD); double min, max, result[], tolerance = 1e-12; int N = 1 << 8; min = 0.0; @@ -271,7 +271,7 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest { public void testParameters() throws Exception { final UnivariateFunction sinFunction = new Sin(); final DoubleUnaryOperator f = (x) -> sinFunction.value(x); - final FastSineTransform transformer = new FastSineTransform(DstNormalization.STANDARD_DST_I); + final FastSineTransform transformer = new FastSineTransform(FastSineTransform.Norm.STD); try { // bad interval