You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2012/01/05 05:08:18 UTC
svn commit: r1227475 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/transform/
test/java/org/apache/commons/math/transform/
Author: celestin
Date: Thu Jan 5 04:08:18 2012
New Revision: 1227475
URL: http://svn.apache.org/viewvc?rev=1227475&view=rev
Log:
Moved
- transform.FastFourierTransformer.scaleArray(Complex[], double)
- transform.FastFourierTransformer.scaleArray(double[], double)
to newly created class transform.TransformUtils.
Related to MATH-677.
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java (with props)
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java?rev=1227475&r1=1227474&r2=1227475&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java Thu Jan 5 04:08:18 2012
@@ -167,7 +167,7 @@ public class FastCosineTransformer imple
if (orthogonal) {
final double s = FastMath.sqrt(2.0 / (f.length - 1));
- return FastFourierTransformer.scaleArray(fct(f), s);
+ return TransformUtils.scaleArray(fct(f), s);
}
return fct(f);
}
@@ -203,7 +203,7 @@ public class FastCosineTransformer imple
final double s2 = 2.0 / (f.length - 1);
final double s1 = orthogonal ? FastMath.sqrt(s2) : s2;
- return FastFourierTransformer.scaleArray(fct(f), s1);
+ return TransformUtils.scaleArray(fct(f), s1);
}
/**
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=1227475&r1=1227474&r2=1227475&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 Thu Jan 5 04:08:18 2012
@@ -154,7 +154,7 @@ public class FastFourierTransformer impl
if (unitary) {
final double s = 1.0 / FastMath.sqrt(f.length);
- return scaleArray(fft(f, false), s);
+ return TransformUtils.scaleArray(fft(f, false), s);
}
return fft(f, false);
}
@@ -184,7 +184,7 @@ public class FastFourierTransformer impl
final double[] data = FunctionUtils.sample(f, min, max, n);
if (unitary) {
final double s = 1.0 / FastMath.sqrt(n);
- return scaleArray(fft(data, false), s);
+ return TransformUtils.scaleArray(fft(data, false), s);
}
return fft(data, false);
}
@@ -204,7 +204,7 @@ public class FastFourierTransformer impl
roots.computeOmega(f.length);
if (unitary) {
final double s = 1.0 / FastMath.sqrt(f.length);
- return scaleArray(fft(f), s);
+ return TransformUtils.scaleArray(fft(f), s);
}
return fft(f);
}
@@ -221,7 +221,7 @@ public class FastFourierTransformer impl
throws MathIllegalArgumentException {
final double s = 1.0 / (unitary ? FastMath.sqrt(f.length) : f.length);
- return scaleArray(fft(f, true), s);
+ return TransformUtils.scaleArray(fft(f, true), s);
}
/**
@@ -248,7 +248,7 @@ public class FastFourierTransformer impl
final double[] data = FunctionUtils.sample(f, min, max, n);
final double s = 1.0 / (unitary ? FastMath.sqrt(n) : n);
- return scaleArray(fft(data, true), s);
+ return TransformUtils.scaleArray(fft(data, true), s);
}
/**
@@ -264,7 +264,7 @@ public class FastFourierTransformer impl
roots.computeOmega(-f.length); // pass negative argument
final double s = 1.0 / (unitary ? FastMath.sqrt(f.length) : f.length);
- return scaleArray(fft(f), s);
+ return TransformUtils.scaleArray(fft(f), s);
}
/**
@@ -316,7 +316,7 @@ public class FastFourierTransformer impl
transformed[2 * n - i] = transformed[i].conjugate();
}
- return scaleArray(transformed, 0.5);
+ return TransformUtils.scaleArray(transformed, 0.5);
}
/**
@@ -402,38 +402,6 @@ public class FastFourierTransformer impl
}
/**
- * Multiply every component in the given real array by the
- * given real number. The change is made in place.
- *
- * @param f the real array to be scaled
- * @param d the real scaling coefficient
- * @return a reference to the scaled array
- */
- public static double[] scaleArray(double[] f, double d) {
-
- for (int i = 0; i < f.length; i++) {
- f[i] *= d;
- }
- return f;
- }
-
- /**
- * Multiply every component in the given complex array by the
- * given real number. The change is made in place.
- *
- * @param f the complex array to be scaled
- * @param d the real scaling coefficient
- * @return a reference to the scaled array
- */
- public static Complex[] scaleArray(Complex[] f, double d) {
-
- for (int i = 0; i < f.length; i++) {
- f[i] = new Complex(d * f[i].getReal(), d * f[i].getImaginary());
- }
- return f;
- }
-
- /**
* Performs a multi-dimensional Fourier transform on a given array. Use
* {@link #transform(Complex[])} and {@link #inverseTransform(Complex[])} in
* a row-column implementation in any number of dimensions with
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java?rev=1227475&r1=1227474&r2=1227475&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastHadamardTransformer.java Thu Jan 5 04:08:18 2012
@@ -75,7 +75,7 @@ public class FastHadamardTransformer imp
public double[] inverseTransform(double[] f)
throws IllegalArgumentException {
- return FastFourierTransformer.scaleArray(fht(f), 1.0 / f.length);
+ return TransformUtils.scaleArray(fht(f), 1.0 / f.length);
}
/**
@@ -96,7 +96,7 @@ public class FastHadamardTransformer imp
final double[] unscaled =
fht(FunctionUtils.sample(f, min, max, n));
- return FastFourierTransformer.scaleArray(unscaled, 1.0 / n);
+ return TransformUtils.scaleArray(unscaled, 1.0 / n);
}
/**
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java?rev=1227475&r1=1227474&r2=1227475&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java Thu Jan 5 04:08:18 2012
@@ -168,7 +168,7 @@ public class FastSineTransformer impleme
public double[] transform(double[] f) throws MathIllegalArgumentException {
if (orthogonal) {
final double s = FastMath.sqrt(2.0 / f.length);
- return FastFourierTransformer.scaleArray(fst(f), s);
+ return TransformUtils.scaleArray(fst(f), s);
}
return fst(f);
}
@@ -195,7 +195,7 @@ public class FastSineTransformer impleme
data[0] = 0.0;
if (orthogonal) {
final double s = FastMath.sqrt(2.0 / n);
- return FastFourierTransformer.scaleArray(fst(data), s);
+ return TransformUtils.scaleArray(fst(data), s);
}
return fst(data);
}
@@ -215,7 +215,7 @@ public class FastSineTransformer impleme
return transform(f);
}
final double s = 2.0 / f.length;
- return FastFourierTransformer.scaleArray(fst(f), s);
+ return TransformUtils.scaleArray(fst(f), s);
}
/**
@@ -244,7 +244,7 @@ public class FastSineTransformer impleme
data[0] = 0.0;
final double s = 2.0 / n;
- return FastFourierTransformer.scaleArray(fst(data), s);
+ return TransformUtils.scaleArray(fst(data), s);
}
/**
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java?rev=1227475&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java Thu Jan 5 04:08:18 2012
@@ -0,0 +1,62 @@
+/*
+ * 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.math.transform;
+
+import org.apache.commons.math.complex.Complex;
+
+/**
+ * Useful functions for the implementation of various transforms.
+ */
+public class TransformUtils {
+ /** Private constructor. */
+ private TransformUtils() {
+ super();
+ }
+
+ /**
+ * Multiply every component in the given real array by the
+ * given real number. The change is made in place.
+ *
+ * @param f the real array to be scaled
+ * @param d the real scaling coefficient
+ * @return a reference to the scaled array
+ */
+ public static double[] scaleArray(double[] f, double d) {
+
+ for (int i = 0; i < f.length; i++) {
+ f[i] *= d;
+ }
+ return f;
+ }
+
+ /**
+ * Multiply every component in the given complex array by the
+ * given real number. The change is made in place.
+ *
+ * @param f the complex array to be scaled
+ * @param d the real scaling coefficient
+ * @return a reference to the scaled array
+ */
+ public static Complex[] scaleArray(Complex[] f, double d) {
+
+ for (int i = 0; i < f.length; i++) {
+ f[i] = new Complex(d * f[i].getReal(), d * f[i].getImaginary());
+ }
+ return f;
+ }
+
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/TransformUtils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java?rev=1227475&r1=1227474&r2=1227475&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java Thu Jan 5 04:08:18 2012
@@ -54,7 +54,7 @@ public final class FastCosineTransformer
Assert.assertEquals(x[i], result[i], tolerance);
}
- FastFourierTransformer.scaleArray(x, FastMath.sqrt(0.5 * (x.length-1)));
+ TransformUtils.scaleArray(x, FastMath.sqrt(0.5 * (x.length-1)));
transformer = FastCosineTransformer.createOrthogonal();
result = transformer.transform(y);
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=1227475&r1=1227474&r2=1227475&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 Thu Jan 5 04:08:18 2012
@@ -64,7 +64,7 @@ public final class FastFourierTransforme
}
double x2[] = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2};
- FastFourierTransformer.scaleArray(x2, 1.0 / FastMath.sqrt(x2.length));
+ TransformUtils.scaleArray(x2, 1.0 / FastMath.sqrt(x2.length));
Complex y2[] = y;
transformer = FastFourierTransformer.createUnitary();
@@ -93,7 +93,7 @@ public final class FastFourierTransforme
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++) {
- FastFourierTransformer.scaleArray(
+ TransformUtils.scaleArray(
goodOutput[i],
FastMath.sqrt(goodOutput[i].length) *
FastMath.sqrt(goodOutput.length));
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java?rev=1227475&r1=1227474&r2=1227475&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java Thu Jan 5 04:08:18 2012
@@ -54,7 +54,7 @@ public final class FastSineTransformerTe
Assert.assertEquals(x[i], result[i], tolerance);
}
- FastFourierTransformer.scaleArray(x, FastMath.sqrt(x.length / 2.0));
+ TransformUtils.scaleArray(x, FastMath.sqrt(x.length / 2.0));
transformer = FastSineTransformer.createOrthogonal();
result = transformer.transform(y);