From ac37165ed7a22cbdeccfe348b10245dc83b414b1 Mon Sep 17 00:00:00 2001 From: Eric Barnhill Date: Sat, 23 Apr 2016 18:19:17 +0200 Subject: [PATCH] Added changes to ComplexUtils.java proposed in feature-MATH-1290: array-wise conversion and extraction methods for converting Complex[] arrays to double and float arrays, split and interleaved, and vice versa; also extracting arrays of absolute value and argument. --- .../commons/math4/complex/ComplexUtils.java | 872 +++++++----------- 1 file changed, 313 insertions(+), 559 deletions(-) diff --git a/src/main/java/org/apache/commons/math4/complex/ComplexUtils.java b/src/main/java/org/apache/commons/math4/complex/ComplexUtils.java index 2f01f0ef5..a95c099ee 100644 --- a/src/main/java/org/apache/commons/math4/complex/ComplexUtils.java +++ b/src/main/java/org/apache/commons/math4/complex/ComplexUtils.java @@ -37,9 +37,6 @@ public class ComplexUtils { /** * Creates a complex number from the given polar representation. *

- * The value returned is {@code r·ei·theta}, - * computed as {@code r·cos(theta) + r·sin(theta)i} - *

* If either {@code r} or {@code theta} is NaN, or {@code theta} is * infinite, {@link Complex#NaN} is returned. *

@@ -50,19 +47,16 @@ public class ComplexUtils { *

      * Examples:
      * {@code
-     * polar2Complex(INFINITY, π/4) = INFINITY + INFINITY i
+     * polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i
      * polar2Complex(INFINITY, 0) = INFINITY + NaN i
-     * polar2Complex(INFINITY, -π/4) = INFINITY - INFINITY i
-     * polar2Complex(INFINITY, 5π/4) = -INFINITY - INFINITY i }
+     * polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i
+     * polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i }
      * 
* - * @param r - * the modulus of the complex number to create - * @param theta - * the argument of the complex number to create + * @param r the modulus of the complex number to create + * @param theta the argument of the complex number to create * @return {@code Complex} - * @throws MathIllegalArgumentException - * if {@code r} is negative. + * @throws MathIllegalArgumentException if {@code r} is negative. * @since 1.1 */ public static Complex polar2Complex(double r, double theta) throws MathIllegalArgumentException { @@ -119,11 +113,10 @@ public class ComplexUtils { * Creates {@code Complex[][][]} array given {@code double[][][]} arrays of * r and theta. * - * @param r {@code double[]} of moduli - * @param theta {@code double[]} of arguments - * @return {@code Complex[][][]} - * @throws MathIllegalArgumentException - * if {@code r} is negative. + * @param r array of moduli + * @param theta array of arguments + * @return {@code Complex} + * @throws MathIllegalArgumentException if {@code r} is negative. * @since 4.0 */ public static Complex[][][] polar2Complex(double[][][] r, double[][][] theta) throws MathIllegalArgumentException { @@ -139,10 +132,8 @@ public class ComplexUtils { * Returns double from array {@code real[]} at entry {@code index} as a * {@code Complex}. * - * @param real - * Array of real numbers. - * @param index - * Location in the array. + * @param real array of real numbers + * @param index location in the array * @return {@code Complex}. * * @since 4.0 @@ -155,11 +146,9 @@ public class ComplexUtils { * Returns float from array {@code real[]} at entry {@code index} as a * {@code Complex}. * - * @param real - * Array of real numbers. - * @param index - * Location in the array. - * @return {@code Complex[]} array. + * @param real array of real numbers + * @param index location in the array + * @return {@code Complex} array * * @since 4.0 */ @@ -171,11 +160,9 @@ public class ComplexUtils { * Returns double from array {@code imaginary[]} at entry {@code index} as a * {@code Complex}. * - * @param imaginary - * Array of imaginary numbers. - * @param index - * Location in the array. - * @return {@code Complex[]} array. + * @param imaginary array of imaginary numbers + * @param index location in the array + * @return {@code Complex} array * * @since 4.0 */ @@ -187,11 +174,9 @@ public class ComplexUtils { * Returns float from array {@code imaginary[]} at entry {@code index} as a * {@code Complex}. * - * @param imaginary - * Array of imaginary numbers. - * @param index - * Location in the array. - * @return {@code Complex[]} array. + * @param imaginary array of imaginary numbers + * @param index location in the array + * @return {@code Complex} array * * @since 4.0 */ @@ -203,10 +188,8 @@ public class ComplexUtils { * Returns real component of Complex from array {@code Complex[]} at entry * {@code index} as a {@code double}. * - * @param complex - * Array of complex numbers. - * @param index - * Location in the array. + * @param complex array of complex numbers + * @param index location in the array * @return {@code double}. * * @since 4.0 @@ -219,10 +202,8 @@ public class ComplexUtils { * Returns real component of array {@code Complex[]} at entry {@code index} * as a {@code float}. * - * @param complex - * Array of complex numbers. - * @param index - * Location in the array. + * @param complex array of complex numbers + * @param index location in the array * @return {@code float}. * * @since 4.0 @@ -235,10 +216,8 @@ public class ComplexUtils { * Returns imaginary component of Complex from array {@code Complex[]} at * entry {@code index} as a {@code double}. * - * @param complex - * Array of complex numbers. - * @param index - * Location in the array. + * @param complex array of complex numbers + * @param index location in the array * @return {@code double}. * * @since 4.0 @@ -251,10 +230,8 @@ public class ComplexUtils { * Returns imaginary component of array {@code Complex[]} at entry * {@code index} as a {@code float}. * - * @param complex - * Array of complex numbers. - * @param index - * Location in the array. + * @param complex array of complex numbers + * @param index location in the array * @return {@code float}. * * @since 4.0 @@ -267,14 +244,9 @@ public class ComplexUtils { * Returns a Complex object from interleaved {@code double[]} array at entry * {@code index}. * - * @param d - * {@code double[]} of interleaved complex numbers alternating - * real and imaginary values - * @param index - * Location in the array. This is the location by complex number, - * e.g. index number 5 in the {@code double[]} array will return - * {@code new Complex(d[10], d[11])} - * @return {@code Complex[]}. + * @param d array of interleaved complex numbers alternating real and imaginary values + * @param index location in the array This is the location by complex number, e.g. index number 5 in the array will return {@code new Complex(d[10], d[11])} + * @return {@code Complex}. * * @since 4.0 */ @@ -286,14 +258,9 @@ public class ComplexUtils { * Returns a Complex object from interleaved {@code float[]} array at entry * {@code index}. * - * @param f - * {@code float[]} of interleaved complex numbers alternating - * real and imaginary values - * @param index - * Location in the array. This is the location by complex number, - * e.g. index number 5 in the {@code float[]} array will return - * new {@code Complex(d[10], d[11])} - * @return {@code Complex[]}. + * @param f float array of interleaved complex numbers alternating real and imaginary values + * @param index location in the array This is the location by complex number, e.g. index number 5 in the {@code float[]} array will return new {@code Complex(d[10], d[11])} + * @return {@code Complex}. * * @since 4.0 */ @@ -305,11 +272,9 @@ public class ComplexUtils { * Returns values of Complex object from array {@code Complex[]} at entry * {@code index} as a size 2 {@code double} of the form {real, imag}. * - * @param complex - * Array of complex numbers. - * @param index - * Location in the array. - * @return size 2 {@code double[]}. + * @param complex array of complex numbers + * @param index location in the array + * @return size 2 array. * * @since 4.0 */ @@ -321,10 +286,8 @@ public class ComplexUtils { * Returns Complex object from array {@code Complex[]} at entry * {@code index} as a size 2 {@code float} of the form {real, imag}. * - * @param complex - * {@code Complex[]} array. - * @param index - * Location in the array. + * @param complex {@code Complex} array + * @param index location in the array * @return size 2 {@code float[]}. * * @since 4.0 @@ -337,14 +300,10 @@ public class ComplexUtils { * Converts a {@code double[]} array to a {@code Complex[]} array for the * range {@code start} - {@code end}. * - * @param real - * Array of real numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param real array of real numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -363,14 +322,10 @@ public class ComplexUtils { * Converts a {@code float[]} array to a {@code Complex[]} array for the * range {@code start} - {@code end}. * - * @param real - * Array of real numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param real array of real numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -389,16 +344,11 @@ public class ComplexUtils { * Converts a {@code double[]} array to a {@code Complex[]} array for the * range {@code start} - {@code end} by {@code increment}. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -417,16 +367,11 @@ public class ComplexUtils { * Converts a {@code float[]} array to a {@code Complex[]} array for the * range {@code start} - {@code end} by {@code increment}. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -445,13 +390,9 @@ public class ComplexUtils { * Converts a {@code double[]} array to a {@code Complex[]} array for the * {@code IntegerSequence} range. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -469,13 +410,9 @@ public class ComplexUtils { * Converts a {@code float[]} array to a {@code Complex[]} array for the * {@code IntegerSequence} range. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -492,10 +429,8 @@ public class ComplexUtils { /** * Converts a {@code double[]} array to a {@code Complex[]} array. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -512,10 +447,8 @@ public class ComplexUtils { /** * Converts a {@code float[]} array to a {@code Complex[]} array. * - * @param real - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @return {@code Complex[]} array. + * @param real array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -533,9 +466,8 @@ public class ComplexUtils { * Converts a 2D real {@code double[][]} array to a 2D {@code Complex[][]} * array. * - * @param d - * 2D {@code double[][]} - * @return 2D {@code Complex[][]} array + * @param d 2D array + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -552,9 +484,8 @@ public class ComplexUtils { * Converts a 3D real {@code double[][][]} array to a {@code Complex [][][]} * array. * - * @param d - * 3D complex interleaved {@code double[][][]} - * @return 3D {@code Complex[][][]} array + * @param d 3D complex interleaved array + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -571,13 +502,10 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code double[]} array for the * range {@code start} - {@code end}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @return {@code double[]} array of the real component. + * @param c {@code Complex} array + * @param start start index + * @param end end index + * @return array of the real component * * @since 4.0 */ @@ -596,13 +524,10 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code float[]} array for the * range {@code start} - {@code end}. * - * @param c - * Complex array - * @param start - * Start index. - * @param end - * End index. - * @return {@code float[]} array of the real component. + * @param c {@code Complex} array + * @param start start index + * @param end end index + * @return {@code float[]} array of the real component * * @since 4.0 */ @@ -621,15 +546,11 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code double[]} array for the * range {@code start} - {@code end} by {@code increment}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code double[]} array of the real component. + * @param c {@code Complex} array + * @param start start index + * @param end end index + * @param increment range increment + * @return array of the real component * * @since 4.0 */ @@ -648,15 +569,11 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code float[]} array for the * range {@code start} - {@code end} by {@code increment}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code float[]} array of the real component. + * @param c {@code Complex} array + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code float[]} array of the real component * * @since 4.0 */ @@ -675,12 +592,9 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code double[]} array for the * {@code IntegerSequence} range. * - * @param c - * {@code Complex[]} array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code double[]} array of the real component. + * @param c {@code Complex} array + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return array of the real component * * @since 4.0 */ @@ -698,12 +612,9 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to a {@code float[]} array for the * {@code IntegerSequence} range. * - * @param c - * {@code Complex[]} array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code float[]} array of the real component. + * @param c {@code Complex} array + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code float[]} array of the real component * * @since 4.0 */ @@ -721,9 +632,8 @@ public class ComplexUtils { * Converts real component of {@code Complex[]} array to a {@code double[]} * array. * - * @param c - * {@code Complex[]} array. - * @return {@code double[]} array of the real component. + * @param c {@code Complex} array + * @return array of the real component * * @since 4.0 */ @@ -741,9 +651,8 @@ public class ComplexUtils { * Converts real component of {@code Complex[]} array to a {@code float[]} * array. * - * @param c - * {@code Complex[]} array. - * @return {@code float[]} array of the real component. + * @param c {@code Complex} array + * @return {@code float[]} array of the real component * * @since 4.0 */ @@ -761,9 +670,8 @@ public class ComplexUtils { * Converts real component of a 2D {@code Complex[][]} array to a 2D * {@code double[][]} array. * - * @param c - * 2D {@code Complex[][]} array - * @return double[][] of real component + * @param c 2D {@code Complex} array + * @return {@code double[][]} of real component * @since 4.0 */ public static double[][] complex2Real(Complex[][] c) { @@ -779,9 +687,8 @@ public class ComplexUtils { * Converts real component of a 2D {@code Complex[][]} array to a 2D * {@code float[][]} array. * - * @param c - * 2D {@code Complex[][]} array - * @return float[][] of real component + * @param c 2D {@code Complex} array + * @return {@code float[][]} of real component * @since 4.0 */ public static float[][] complex2RealFloat(Complex[][] c) { @@ -797,9 +704,8 @@ public class ComplexUtils { * Converts real component of a 3D {@code Complex[][][]} array to a 3D * {@code double[][][]} array. * - * @param c - * 3D complex interleaved {@code double[][][]} - * @return {@code double[][][]} array of real component + * @param c 3D complex interleaved array + * @return array of real component * * @since 4.0 */ @@ -816,9 +722,8 @@ public class ComplexUtils { * Converts real component of a 3D {@code Complex[][][]} array to a 3D * {@code float[][][]} array. * - * @param c - * 3D {@code Complex[][][]} array - * @return float[][][] of real component + * @param c 3D {@code Complex} array + * @return {@code float[][][]} of real component * @since 4.0 */ public static float[][][] complex2RealFloat(Complex[][][] c) { @@ -834,14 +739,10 @@ public class ComplexUtils { * Converts a {@code double[]} array to an imaginary {@code Complex[]} array * for the range {@code start} - {@code end}. * - * @param imaginary - * Array of imaginary numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param imaginary array of imaginary numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -860,14 +761,10 @@ public class ComplexUtils { * Converts a {@code float[]} array to an imaginary {@code Complex[]} array * for the range {@code start} - {@code end}. * - * @param imaginary - * Array of imaginary numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param imaginary array of imaginary numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -886,16 +783,11 @@ public class ComplexUtils { * Converts a {@code double[]} array to an imaginary {@code Complex[]} array * for the range {@code start} - {@code end} by {@code increment}. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -914,16 +806,11 @@ public class ComplexUtils { * Converts a {@code float[]} array to an imaginary {@code Complex[]} array * for the range {@code start} - {@code end} by {@code increment}. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -942,13 +829,9 @@ public class ComplexUtils { * Converts a {@code double[]} array to an imaginary {@code Complex[]} array * for the {@code IntegerSequence} range. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -966,13 +849,9 @@ public class ComplexUtils { * Converts a {@code float[]} array to an imaginary {@code Complex[]} array * for the {@code IntegerSequence} range. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -990,10 +869,8 @@ public class ComplexUtils { * Converts a {@code double[]} array to an imaginary {@code Complex[]} * array. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -1010,10 +887,8 @@ public class ComplexUtils { /** * Converts a {@code float[]} array to an imaginary {@code Complex[]} array. * - * @param imaginary - * Array of numbers to be converted to their {@code Complex} - * equivalent. - * @return {@code Complex[]} array. + * @param imaginary array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -1031,9 +906,8 @@ public class ComplexUtils { * Converts a 2D imaginary array {@code double[][]} to a 2D * {@code Complex[][]} array. * - * @param d - * 2D {@code double[][]} - * @return 2D {@code Complex[][]} array + * @param d 2D array + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -1051,9 +925,8 @@ public class ComplexUtils { * Converts a 3D imaginary array {@code double[][][]} to a {@code Complex[]} * array. * - * @param d - * 3D complex imaginary {@code double[][][]} - * @return 3D {@code Complex[][][]} array + * @param d 3D complex imaginary array + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -1074,13 +947,10 @@ public class ComplexUtils { * Converts imaginary part of {@code Complex[]} array to a {@code double[]} * array for the range {@code start} - {@code end}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @return {@code double[]} array of the imaginary component. + * @param c {@code Complex} array. + * @param start start index + * @param end end index + * @return array of the imaginary component * * @since 4.0 */ @@ -1099,13 +969,10 @@ public class ComplexUtils { * Converts imaginary part of a {@code Complex[]} array to a {@code float[]} * array for the range {@code start} - {@code end}. * - * @param c - * Complex array - * @param start - * Start index. - * @param end - * End index. - * @return {@code float[]} array of the imaginary component. + * @param c Complex array + * @param start start index + * @param end end index + * @return {@code float[]} array of the imaginary component * * @since 4.0 */ @@ -1125,15 +992,11 @@ public class ComplexUtils { * {@code double[]} array for the range {@code start} - {@code end} by * {@code increment}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code double[]} array of the imaginary component. + * @param c {@code Complex} array. + * @param start start index + * @param end end index + * @param increment range increment + * @return array of the imaginary component * * @since 4.0 */ @@ -1152,15 +1015,11 @@ public class ComplexUtils { * Converts imaginary part of a {@code Complex[]} array to a {@code float[]} * array for the range {@code start} - {@code end} by {@code increment}. * - * @param c - * {@code Complex[]} array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code float[]} array of the imaginary component. + * @param c {@code Complex} array. + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code float[]} array of the imaginary component * * @since 4.0 */ @@ -1179,12 +1038,9 @@ public class ComplexUtils { * Converts imaginary part of a {@code Complex[]} array to a * {@code double[]} array for the {@code IntegerSequence} range. * - * @param c - * {@code Complex[]} array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code double[]} array of the imaginary component. + * @param c {@code Complex} array. + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return array of the imaginary component * * @since 4.0 */ @@ -1202,12 +1058,9 @@ public class ComplexUtils { * Converts imaginary part of a {@code Complex[]} array to a {@code float[]} * array for the {@code IntegerSequence} range. * - * @param c - * {@code Complex[]} array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code float[]} array of the imaginary component. + * @param c {@code Complex} array. + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code float[]} array of the imaginary component * * @since 4.0 */ @@ -1225,9 +1078,8 @@ public class ComplexUtils { * Converts imaginary part of a {@code Complex[]} array to a * {@code double[]} array. * - * @param c - * {@code Complex[]} array. - * @return {@code double[]} array of the imaginary component. + * @param c {@code Complex} array. + * @return array of the imaginary component * * @since 4.0 */ @@ -1245,9 +1097,8 @@ public class ComplexUtils { * Converts imaginary component of a {@code Complex[]} array to a * {@code float[]} array. * - * @param c - * {@code Complex[]} array. - * @return {@code float[]} array of the imaginary component. + * @param c {@code Complex} array. + * @return {@code float[]} array of the imaginary component * * @since 4.0 */ @@ -1265,9 +1116,8 @@ public class ComplexUtils { * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D * {@code double[][]} array. * - * @param c - * 2D {@code Complex[][]} array - * @return double[][] of imaginary component + * @param c 2D {@code Complex} array + * @return {@code double[][]} of imaginary component * @since 4.0 */ public static double[][] complex2Imaginary(Complex[][] c) { @@ -1283,9 +1133,8 @@ public class ComplexUtils { * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D * {@code float[][]} array. * - * @param c - * 2D {@code Complex[][]} array - * @return float[][] of imaginary component + * @param c 2D {@code Complex} array + * @return {@code float[][]} of imaginary component * @since 4.0 */ public static float[][] complex2ImaginaryFloat(Complex[][] c) { @@ -1301,9 +1150,8 @@ public class ComplexUtils { * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D * {@code double[][][]} array. * - * @param c - * 3D complex interleaved {@code double[][][]} - * @return 3D {@code Complex[][][]} array + * @param c 3D complex interleaved array + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -1320,9 +1168,8 @@ public class ComplexUtils { * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D * {@code float[][][]} array. * - * @param c - * 3D {@code Complex[][][]} array - * @return float[][][] of imaginary component + * @param c 3D {@code Complex} array + * @return {@code float[][][]} of imaginary component * @since 4.0 */ public static float[][][] complex2ImaginaryFloat(Complex[][][] c) { @@ -1340,14 +1187,10 @@ public class ComplexUtils { * Converts a complex interleaved {@code double[]} array to a * {@code Complex[]} array for the range {@code start} - {@code end}. * - * @param interleaved - * {@code double[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param interleaved array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -1366,14 +1209,10 @@ public class ComplexUtils { * Converts a complex interleaved {@code float[]} array to a * {@code Complex[]} array for the range {@code start} - {@code end}. * - * @param interleaved - * {@code float[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @return {@code Complex[]} array. + * @param interleaved float array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @return {@code Complex} array * * @since 4.0 */ @@ -1393,16 +1232,11 @@ public class ComplexUtils { * {@code Complex[]} array for the range {@code start} - {@code end} by * {@code increment}. * - * @param interleaved - * {@code double[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param interleaved array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -1422,16 +1256,11 @@ public class ComplexUtils { * {@code Complex[]} array for the range {@code start} - {@code end} by * {@code increment}. * - * @param interleaved - * {@code float[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return {@code Complex[]} array. + * @param interleaved float array of numbers to be converted to their {@code Complex} equivalent + * @param start start index + * @param end end index + * @param increment range increment + * @return {@code Complex} array * * @since 4.0 */ @@ -1450,13 +1279,9 @@ public class ComplexUtils { * Converts a complex interleaved {@code double[]} array to a * {@code Complex[]} array for the {@code IntegerSequence} range. * - * @param interleaved - * {@code double[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param interleaved array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -1474,13 +1299,9 @@ public class ComplexUtils { * Converts a complex interleaved {@code float[]} array to a * {@code Complex[]} array for the {@code IntegerSequence} range. * - * @param interleaved - * {@code float[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return {@code Complex[]} array. + * @param interleaved float array of numbers to be converted to their {@code Complex} equivalent + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return {@code Complex} array * * @since 4.0 */ @@ -1498,10 +1319,8 @@ public class ComplexUtils { * Converts a complex interleaved {@code double[]} array to a * {@code Complex[]} array * - * @param interleaved - * {@code double[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @return {@code Complex[]} array. + * @param interleaved array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -1518,10 +1337,8 @@ public class ComplexUtils { * Converts a complex interleaved {@code float[]} array to a * {@code Complex[]} array * - * @param interleaved - * {@code float[]} of numbers to be converted to their - * {@code Complex} equivalent. - * @return {@code Complex[]} array. + * @param interleaved float[] array of numbers to be converted to their {@code Complex} equivalent + * @return {@code Complex} array * * @since 4.0 */ @@ -1538,14 +1355,11 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code double[]} array for the range {@code start} - {@code end}. * - * @param c - * Complex array. - * @param start - * Start index. - * @param end - * End index. - * @return complex interleaved {@code double[]} alternating real and - * imaginary values. + * @param c Complex array + * @param start start index + * @param end end index + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1567,14 +1381,11 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code float[]} array for the range {@code start} - {@code end}. * - * @param c - * Complex array. - * @param start - * Start index. - * @param end - * End index. + * @param c Complex array + * @param start start index + * @param end end index * @return complex interleaved {@code float[]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1597,16 +1408,12 @@ public class ComplexUtils { * {@code double[]} array for the range {@code start} - {@code end} by * {@code increment}. * - * @param c - * Complex array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. - * @return complex interleaved {@code double[]} alternating real and - * imaginary values. + * @param c Complex array + * @param start start index + * @param end end index + * @param increment range increment + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1629,16 +1436,12 @@ public class ComplexUtils { * {@code float[]} array for the range {@code start} - {@code end} by * {@code increment}. * - * @param c - * Complex array. - * @param start - * Start index. - * @param end - * End index. - * @param increment - * Range increment. + * @param c Complex array + * @param start start index + * @param end end index + * @param increment range increment * @return complex interleaved {@code float[]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1660,13 +1463,10 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code double[]} array for the {@code IntegerSequence} range. * - * @param c - * Complex array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} - * @return complex interleaved {@code double[]} alternating real and - * imaginary values. + * @param c Complex array + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1687,13 +1487,10 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code float[]} array for the {@code IntegerSequence} range. * - * @param c - * Complex array. - * @param range - * an {@code Iterable} object returned by - * {@code IntegerSequence.range()} + * @param c Complex array + * @param range an {@code Iterable} object returned by {@code IntegerSequence.range()} * @return complex interleaved {@code float[]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1714,10 +1511,9 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code double[]} array * - * @param c - * Complex array. - * @return complex interleaved {@code double[]} alternating real and - * imaginary values. + * @param c Complex array + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1738,10 +1534,9 @@ public class ComplexUtils { * Converts a {@code Complex[]} array to an interleaved complex * {@code float[]} array * - * @param c - * Complex array. + * @param c Complex array * @return complex interleaved {@code float[]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1762,12 +1557,10 @@ public class ComplexUtils { * Converts a 2D {@code Complex[][]} array to an interleaved complex * {@code double[][]} array. * - * @param c - * 2D Complex array. - * @param interleavedDim - * Depth level of the array to interleave. - * @return complex interleaved {@code double[][]} alternating real and - * imaginary values. + * @param c 2D Complex array + * @param interleavedDim Depth level of the array to interleave + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1803,10 +1596,9 @@ public class ComplexUtils { * {@code double[][]} array. The second depth level of the array is assumed * to be interleaved. * - * @param c - * 2D Complex array. - * @return complex interleaved {@code double[][]} alternating real and - * imaginary values. + * @param c 2D Complex array + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1818,12 +1610,10 @@ public class ComplexUtils { * Converts a 3D {@code Complex[][][]} array to an interleaved complex * {@code double[][][]} array. * - * @param c - * 3D Complex array. - * @param interleavedDim - * Depth level of the array to interleave. - * @return complex interleaved {@code double[][][]} alternating real and - * imaginary values. + * @param c 3D Complex array + * @param interleavedDim Depth level of the array to interleave + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1833,7 +1623,7 @@ public class ComplexUtils { } int width = c.length; int height = c[0].length; - int depth = c[0].length; + int depth = c[0][0].length; double[][][] d; if (interleavedDim == 0) { d = new double[2 * width][height][depth]; @@ -1850,8 +1640,8 @@ public class ComplexUtils { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { - d[x][y][z] = c[x][y][z].getReal(); - d[x][y * 2][z] = c[x][y][z].getImaginary(); + d[x][y * 2][z] = c[x][y][z].getReal(); + d[x][y * 2 + 1][z] = c[x][y][z].getImaginary(); } } } @@ -1874,10 +1664,9 @@ public class ComplexUtils { * {@code double[][][]} array. The third depth level of the array is * interleaved. * - * @param c - * 3D Complex array. - * @return complex interleaved {@code double[][][]} alternating real and - * imaginary values. + * @param c 3D Complex array + * @return complex interleaved array alternating real and + * imaginary values * * @since 4.0 */ @@ -1889,12 +1678,10 @@ public class ComplexUtils { * Converts a 2D {@code Complex[][]} array to an interleaved complex * {@code float[][]} array. * - * @param c - * 2D Complex array. - * @param interleavedDim - * Depth level of the array to interleave. + * @param c 2D Complex array + * @param interleavedDim Depth level of the array to interleave * @return complex interleaved {@code float[][]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1930,11 +1717,10 @@ public class ComplexUtils { * {@code float[][]} array. The second depth level of the array is assumed * to be interleaved. * - * @param c - * 2D Complex array. + * @param c 2D Complex array * * @return complex interleaved {@code float[][]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -1946,12 +1732,10 @@ public class ComplexUtils { * Converts a 3D {@code Complex[][][]} array to an interleaved complex * {@code float[][][]} array. * - * @param c - * 3D Complex array. - * @param interleavedDim - * Depth level of the array to interleave. + * @param c 3D Complex array + * @param interleavedDim Depth level of the array to interleave * @return complex interleaved {@code float[][][]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -2002,11 +1786,10 @@ public class ComplexUtils { * {@code float[][][]} array. The third depth level of the array is * interleaved. * - * @param c - * 2D Complex array. + * @param c 2D Complex array * * @return complex interleaved {@code float[][][]} alternating real and - * imaginary values. + * imaginary values * * @since 4.0 */ @@ -2018,11 +1801,9 @@ public class ComplexUtils { * Converts a 2D interleaved complex {@code double[][]} array to a * {@code Complex[][]} array. * - * @param d - * 2D complex interleaved {@code double[][]} - * @param interleavedDim - * Depth level of the array to interleave. - * @return 2D {@code Complex[][]} array + * @param d 2D complex interleaved array + * @param interleavedDim Depth level of the array to interleave + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2056,9 +1837,8 @@ public class ComplexUtils { * {@code Complex[][]} array. The second depth level of the array is assumed * to be interleaved. * - * @param d - * 2D complex interleaved {@code double[][]} - * @return 2D {@code Complex[][]} array + * @param d 2D complex interleaved array + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2070,11 +1850,9 @@ public class ComplexUtils { * Converts a 3D interleaved complex {@code double[][][]} array to a * {@code Complex[][][]} array. * - * @param d - * 3D complex interleaved {@code double[][][]} - * @param interleavedDim - * Depth level of the array to interleave. - * @return 3D {@code Complex[][][]} array + * @param d 3D complex interleaved array + * @param interleavedDim Depth level of the array to interleave + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2088,7 +1866,7 @@ public class ComplexUtils { Complex[][][] c; if (interleavedDim == 0) { c = new Complex[width / 2][height][depth]; - for (int x = 0; x < width; x++) { + for (int x = 0; x < width / 2; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]); @@ -2098,7 +1876,7 @@ public class ComplexUtils { } else if (interleavedDim == 1) { c = new Complex[width][height / 2][depth]; for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { + for (int y = 0; y < height / 2; y++) { for (int z = 0; z < depth; z++) { c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]); } @@ -2108,7 +1886,7 @@ public class ComplexUtils { c = new Complex[width][height][depth / 2]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z++) { + for (int z = 0; z < depth / 2; z++) { c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]); } } @@ -2122,9 +1900,8 @@ public class ComplexUtils { * {@code Complex[][][]} array. The third depth level is assumed to be * interleaved. * - * @param d - * 3D complex interleaved {@code double[][][]} - * @return 3D {@code Complex[][][]} array + * @param d 3D complex interleaved array + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2136,11 +1913,9 @@ public class ComplexUtils { * Converts a 2D interleaved complex {@code float[][]} array to a * {@code Complex[][]} array. * - * @param d - * 2D complex interleaved {@code float[][]} - * @param interleavedDim - * Depth level of the array to interleave. - * @return 2D {@code Complex[][]} array + * @param d 2D complex interleaved float array + * @param interleavedDim Depth level of the array to interleave + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2174,9 +1949,8 @@ public class ComplexUtils { * {@code Complex[][]} array. The second depth level of the array is assumed * to be interleaved. * - * @param d - * 2D complex interleaved {@code float[][]} - * @return 2D {@code Complex[][]} array + * @param d 2D complex interleaved float array + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2188,11 +1962,9 @@ public class ComplexUtils { * Converts a 3D interleaved complex {@code float[][][]} array to a * {@code Complex[][][]} array. * - * @param d - * 3D complex interleaved {@code float[][][]} - * @param interleavedDim - * Depth level of the array to interleave. - * @return 3D {@code Complex[][][]} array + * @param d 3D complex interleaved float array + * @param interleavedDim Depth level of the array to interleave + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2206,7 +1978,7 @@ public class ComplexUtils { Complex[][][] c; if (interleavedDim == 0) { c = new Complex[width / 2][height][depth]; - for (int x = 0; x < width; x += 2) { + for (int x = 0; x < width/2; x ++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]); @@ -2216,7 +1988,7 @@ public class ComplexUtils { } else if (interleavedDim == 1) { c = new Complex[width][height / 2][depth]; for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y += 2) { + for (int y = 0; y < height/2; y ++) { for (int z = 0; z < depth; z++) { c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]); } @@ -2226,7 +1998,7 @@ public class ComplexUtils { c = new Complex[width][height][depth / 2]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { - for (int z = 0; z < depth; z += 2) { + for (int z = 0; z < depth/2; z++) { c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]); } } @@ -2240,9 +2012,8 @@ public class ComplexUtils { * {@code Complex[]} array. The third depth level of the array is assumed to * be interleaved. * - * @param d - * 3D complex interleaved {@code float[][][]} - * @return 3D {@code Complex[][][]} array + * @param d 3D complex interleaved float array + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2256,11 +2027,9 @@ public class ComplexUtils { * Converts a split complex array {@code double[] r, double[] i} to a * {@code Complex[]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return {@code Complex[]} array + * @param real real component + * @param imag imaginary component + * @return {@code Complex} array * * @since 4.0 */ @@ -2277,11 +2046,9 @@ public class ComplexUtils { * Converts a 2D split complex array {@code double[][] r, double[][] i} to a * 2D {@code Complex[][]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return 2D {@code Complex[][]} array + * @param real real component + * @param imag imaginary component + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2298,11 +2065,9 @@ public class ComplexUtils { * Converts a 3D split complex array {@code double[][][] r, double[][][] i} * to a 3D {@code Complex[][][]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return 3D {@code Complex[][][]} array + * @param real real component + * @param imag imaginary component + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2319,11 +2084,9 @@ public class ComplexUtils { * Converts a split complex array {@code float[] r, float[] i} to a * {@code Complex[]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return {@code Complex[]} array + * @param real real component + * @param imag imaginary component + * @return {@code Complex} array * * @since 4.0 */ @@ -2340,11 +2103,9 @@ public class ComplexUtils { * Converts a 2D split complex array {@code float[][] r, float[][] i} to a * 2D {@code Complex[][]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return 2D {@code Complex[][]} array + * @param real real component + * @param imag imaginary component + * @return 2D {@code Complex} array * * @since 4.0 */ @@ -2361,11 +2122,9 @@ public class ComplexUtils { * Converts a 3D split complex array {@code float[][][] r, float[][][] i} to * a 3D {@code Complex[][][]} array. * - * @param real - * real component - * @param imag - * imaginary component - * @return 3D {@code Complex[][][]} array + * @param real real component + * @param imag imaginary component + * @return 3D {@code Complex} array * * @since 4.0 */ @@ -2384,8 +2143,7 @@ public class ComplexUtils { * Initializes a {@code Complex[]} array to zero, to avoid * NullPointerExceptions. * - * @param c - * Complex[] array + * @param c Complex array * @return c * * @since 4.0 @@ -2402,8 +2160,7 @@ public class ComplexUtils { * Initializes a {@code Complex[][]} array to zero, to avoid * NullPointerExceptions. * - * @param c - * Complex[][] array + * @param c {@code Complex} array * @return c * * @since 4.0 @@ -2420,8 +2177,7 @@ public class ComplexUtils { * Initializes a {@code Complex[][][]} array to zero, to avoid * NullPointerExceptions. * - * @param c - * Complex[][][] array + * @param c {@code Complex} array * @return c * * @since 4.0 @@ -2438,9 +2194,8 @@ public class ComplexUtils { * Returns {@code double[]} containing absolute values (magnitudes) of a * {@code Complex[]} array. * - * @param c - * {@code Complex[]} array - * @return {@code double[]} array + * @param c {@code Complex} array + * @return {@code double[]} * * @since 4.0 */ @@ -2457,8 +2212,7 @@ public class ComplexUtils { * Returns {@code double[]} containing arguments (phase angles) of a * {@code Complex[]} array. * - * @param c - * {@code Complex[]} array + * @param c {@code Complex} array * @return {@code double[]} array * * @since 4.0