Package ptolemy.math

Class ComplexArrayMath


  • public class ComplexArrayMath
    extends java.lang.Object
    This class a provides a library for mathematical operations on arrays of complex numbers, in particular arrays of instances of class ptolemy.math.Complex. Unless explicitly noted otherwise, all array arguments are assumed to be non-null. If a null array is passed to a method, a NullPointerException will be thrown in the method or called methods.
    Since:
    Ptolemy II 0.3
    Version:
    $Id$
    Author:
    Albert Chen, William Wu, Edward A. Lee, Jeff Tsay
    Pt.AcceptedRating:
    Yellow (ctsay)
    Pt.ProposedRating:
    Yellow (ctsay)
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ComplexArrayMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static int _commonLength​(Complex[] array1, Complex[] array2, java.lang.String methodName)
      Throw an exception if the two arrays are not of the same length, or if either array is null.
      static Complex[] add​(Complex[] array, Complex z)
      Return a new array that is constructed from array by adding the complex number z to every element of array.
      static Complex[] add​(Complex[] array1, Complex[] array2)
      Return a new array that is the element-by-element sum of the two input arrays.
      static Complex[] append​(Complex[] array1, int idx1, int length1, Complex[] array2, int idx2, int length2)
      Return a new array that is the result of appending length2 elements of array2, starting from the idx2th element, to length1 elements of array1, starting from the idx1th element.
      static Complex[] append​(Complex[] array1, Complex[] array2)
      Return a new array that is the result of appending array2 to the end of array1.
      static Complex[] applyBinaryOperation​(ComplexBinaryOperation op, Complex[] array, Complex z)
      Return a new array that is formed by applying an instance of a ComplexBinaryOperation to each element in the input array, using z as the right operand in all cases and the array elements as the left operands (op.operate(array[i], z)).
      static Complex[] applyBinaryOperation​(ComplexBinaryOperation op, Complex[] array1, Complex[] array2)
      Return a new array that is formed by applying an instance of a ComplexBinaryOperation to the two arrays, element by element, using the elements of the first array as the left operands and the elements of the second array as the right operands.
      static Complex[] applyBinaryOperation​(ComplexBinaryOperation op, Complex z, Complex[] array)
      Return a new array that is formed by applying an instance of a ComplexBinaryOperation to each element in the input array, using z as the left argument to op in all cases and the array elements as the right arguments (op.operate(z, array[i])).
      static Complex[] applyUnaryOperation​(ComplexUnaryOperation op, Complex[] array)
      Return a new array that is formed by applying an instance of a ComplexUnaryOperation to each element in the input array (op.operate(array[i])).
      static Complex[] conjugate​(Complex[] array)
      Return a new array of complex numbers that is formed by taking the complex-conjugate of each element in the argument array.
      static Complex[] divide​(Complex[] array, Complex divisor)
      Return a new array that is the result of dividing each element of the given array by the given value.
      static Complex[] divideElements​(Complex[] array1, Complex[] array2)
      Return a new array that is the element-by-element division of the first array by the second array.
      static Complex dotProduct​(Complex[] array1, Complex[] array2)
      Return a complex number that is the dot product of the two argument arrays.
      static Complex[] formComplexArray​(double[] realPart, double[] imagPart)
      Return a new array of Complex numbers using two arrays for the real and imaginary parts.
      static double[] imagParts​(Complex[] x)
      Return a new array of doubles with the imaginary parts of the array of complex numbers.
      static double l2norm​(Complex[] array)
      Return a double that is the L2-norm of the array.
      static double l2normSquared​(Complex[] array)
      Return a double that is the sum of the squared magnitudes of the elements of array.
      static Complex[] limit​(Complex[] array, Complex bottom, Complex top)
      Return a new array that is a copy of the first argument except that the elements are limited to lie within the specified range.
      static double[] magnitude​(Complex[] array)
      Return a new array of doubles containing the magnitudes of the elements of the specified array of complex numbers.
      static Complex[] multiply​(Complex[] array, Complex factor)
      Return a new array that is constructed from the argument by multiplying each element in array by the second argument, which is a complex number.
      static Complex[] multiply​(Complex[] array1, Complex[] array2)
      Return a new array that is the element-by-element multiplication of the two input arrays.
      static Complex[] negative​(Complex[] array)
      Return a new array that is the formed from the additive inverse of each element of the input array (-array[i]).
      static Complex[] padMiddle​(Complex[] array, int newLength)
      Return a new array of Complex numbers that is formed by padding the middle of the array with 0's.
      static double[] phase​(Complex[] array)
      Return a new array containing the angles of the elements of the specified complex array.
      static Complex[] polynomial​(Complex[] roots)
      Given the roots of a polynomial, return a polynomial that has has such roots.
      static Complex[] pow​(Complex[] array, double exponent)
      Return a new array of complex numbers that is formed by raising each element to the specified exponent, a double.
      static Complex product​(Complex[] array)
      Return the product of the elements in the array.
      static double[] realParts​(Complex[] x)
      Return a new array of doubles that includes the real parts of the array of complex numbers.
      static Complex[] resize​(Complex[] array, int newLength)
      Return a new array of length newLength that is formed by either truncating or padding the input array.
      static Complex[] resize​(Complex[] array, int newLength, int startIdx)
      Return a new array of length newLength that is formed by either truncating or padding the input array.
      static Complex[] scale​(Complex[] array, double factor)
      Return a new array that is constructed from the argument by scaling each element in the array by factor, which is a double.
      static Complex[] scale​(Complex[] array, Complex factor)
      Return a new array that is constructed from the argument by scaling each element in array by factor, which is a complex number.
      static Complex[] subtract​(Complex[] array, Complex z)
      Return a new array that is constructed by subtracting the complex number z from every element in the given array.
      static Complex[] subtract​(Complex[] array1, Complex[] array2)
      Return a new array that is the element-by-element subtraction of the second array from the first array.
      static java.lang.String toString​(Complex[] array)
      Return a new String representing the array, formatted as in Java array initializers.
      static java.lang.String toString​(Complex[] array, java.lang.String elementDelimiter, java.lang.String vectorBegin, java.lang.String vectorEnd)
      Return a new String representing the array, formatted specified starting with vectorBegin, where each successive element is separated by elementDelimiter and ending with vectorEnd.
      static boolean within​(Complex[] array1, Complex[] array2, double maxError)
      Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to maxError.
      static boolean within​(Complex[] array1, Complex[] array2, double[] maxError)
      Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the corresponding elements in maxError.
      static boolean within​(Complex[] array1, Complex[] array2, Complex maxError)
      Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitude of maxError.
      static boolean within​(Complex[] array1, Complex[] array2, Complex[] maxError)
      Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitudes of the corresponding elements in maxError.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComplexArrayMath

        protected ComplexArrayMath()
    • Method Detail

      • add

        public static final Complex[] add​(Complex[] array,
                                          Complex z)
        Return a new array that is constructed from array by adding the complex number z to every element of array.
        Parameters:
        array - An array of complex numbers.
        z - The complex number to be added to each element of array.
        Returns:
        A new array of complex numbers equal to array with z added to each element.
      • add

        public static final Complex[] add​(Complex[] array1,
                                          Complex[] array2)
        Return a new array that is the element-by-element sum of the two input arrays. If the sizes of both arrays are 0, return a new array of size 0.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        Returns:
        A new array that is the element-by-element sum of the two input arrays.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • append

        public static final Complex[] append​(Complex[] array1,
                                             Complex[] array2)
        Return a new array that is the result of appending array2 to the end of array1. This method simply calls append(array1, 0, array1.length, array2, 0, array2.length)
        Parameters:
        array1 - The first array of complex numbers.
        array2 - The second array of complex numbers.
        Returns:
        A new array formed by appending array2 to the end of array1.
      • append

        public static final Complex[] append​(Complex[] array1,
                                             int idx1,
                                             int length1,
                                             Complex[] array2,
                                             int idx2,
                                             int length2)
        Return a new array that is the result of appending length2 elements of array2, starting from the idx2th element, to length1 elements of array1, starting from the idx1th element. Appending empty arrays is supported. In that case, the corresponding idx may be any number. Allow System.arraycopy() to throw array access exceptions if idx .. idx + length - 1 are not all valid array indices, for both of the arrays.
        Parameters:
        array1 - The first array of complex numbers.
        idx1 - The starting index for array1.
        length1 - The number of elements of array1 to use.
        array2 - The second array of complex numbers, which is appended.
        idx2 - The starting index for array2.
        length2 - The number of elements of array2 to append.
        Returns:
        A new array of Complex.
      • applyBinaryOperation

        public static final Complex[] applyBinaryOperation​(ComplexBinaryOperation op,
                                                           Complex z,
                                                           Complex[] array)
        Return a new array that is formed by applying an instance of a ComplexBinaryOperation to each element in the input array, using z as the left argument to op in all cases and the array elements as the right arguments (op.operate(z, array[i])). If the length of the array is 0, return a new array of length 0.
        Parameters:
        op - The complex binary operation to be applied to the given complex number and complex array.
        z - The complex number that is the first argument to op.
        array - The array of complex numbers that is the second argument to op.
        Returns:
        A new array containing elements equal to (op.operate(z, array[i])).
      • applyBinaryOperation

        public static final Complex[] applyBinaryOperation​(ComplexBinaryOperation op,
                                                           Complex[] array,
                                                           Complex z)
        Return a new array that is formed by applying an instance of a ComplexBinaryOperation to each element in the input array, using z as the right operand in all cases and the array elements as the left operands (op.operate(array[i], z)). If the length of the array is 0, return a new array of length 0.
        Parameters:
        op - The complex binary operation to be applied to the given complex number and complex array.
        z - The complex number that is the second argument to op.
        array - The array of complex numbers that is the first argument to op.
        Returns:
        A new array containing elements equal to (op.operate(array[i], z)).
      • applyBinaryOperation

        public static final Complex[] applyBinaryOperation​(ComplexBinaryOperation op,
                                                           Complex[] array1,
                                                           Complex[] array2)
        Return a new array that is formed by applying an instance of a ComplexBinaryOperation to the two arrays, element by element, using the elements of the first array as the left operands and the elements of the second array as the right operands. (op.operate(array[i], array2[i])). If the lengths of both arrays are 0, return a new array of length 0.
        Parameters:
        op - The complex binary operation to be applied to each pair of corresponding elements of each complex array.
        array1 - The first array.
        array2 - The second array.
        Returns:
        A new array that with elements equal to (op.operate(array[i], array2[i])).
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • applyUnaryOperation

        public static final Complex[] applyUnaryOperation​(ComplexUnaryOperation op,
                                                          Complex[] array)
        Return a new array that is formed by applying an instance of a ComplexUnaryOperation to each element in the input array (op.operate(array[i])). If the length of the array is 0, return a new array of length 0.
        Parameters:
        op - The complex unary operation to be applied to each element of the given complex array.
        array - An array of complex numbers.
        Returns:
        A new array of complex numbers with each element equal to (op.operate(array[i])).
      • conjugate

        public static final Complex[] conjugate​(Complex[] array)
        Return a new array of complex numbers that is formed by taking the complex-conjugate of each element in the argument array. If the argument has length 0, return a new array of complex numbers, with length 0.
        Parameters:
        array - The given array of complex numbers.
        Returns:
        A new array of complex numbers formed by taking the complex-conjugate of each element in the argument array.
      • divideElements

        public static final Complex[] divideElements​(Complex[] array1,
                                                     Complex[] array2)
        Return a new array that is the element-by-element division of the first array by the second array. If the sizes of both arrays are 0, return a new array of size 0.
        Parameters:
        array1 - The first array of complex numbers.
        array2 - The second array of complex numbers.
        Returns:
        A new array of complex numbers equal to the element-by-element division of the first array by the second array.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • divide

        public static final Complex[] divide​(Complex[] array,
                                             Complex divisor)
        Return a new array that is the result of dividing each element of the given array by the given value.
        Parameters:
        array - An array of complex numbers.
        divisor - The number by which to divide each element of the array.
        Returns:
        A new array of complex numbers that is the result of dividing each element of array by divisor.
      • dotProduct

        public static final Complex dotProduct​(Complex[] array1,
                                               Complex[] array2)
        Return a complex number that is the dot product of the two argument arrays. The dot product is computed by the sum of the element-by-element products of array1 and the complex conjugates of array2. If the size of each array is 0, return Complex.ZERO.
        Parameters:
        array1 - The first array of complex numbers.
        array2 - The second array of complex numbers.
        Returns:
        A new array of complex numbers equal to the dot product of the two given arrays.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • formComplexArray

        public static final Complex[] formComplexArray​(double[] realPart,
                                                       double[] imagPart)
        Return a new array of Complex numbers using two arrays for the real and imaginary parts. If realPart is null, it is treated as if it were an array of zeros and an array of complex numbers that are purely imaginary is constructed. If imagPart is null, it is treated as if it were an array of zeroes and an array of complex numbers that are purely real is constructed. If both arrays are of length 0, or one array is null and the other array is of length 0, return a new array of complex numbers with length 0. If both arrays are null, allow a NullPointerException to be thrown by the array access code.
        Parameters:
        realPart - An array of doubles, used for the real parts.
        imagPart - An array of doubles, used for the imaginary parts.
        Returns:
        A new array of complex numbers each containing real and imaginary parts equal to the elements in realPart and imagPart, respectively.
      • imagParts

        public static final double[] imagParts​(Complex[] x)
        Return a new array of doubles with the imaginary parts of the array of complex numbers.
        Parameters:
        x - The input array of complex numbers.
        Returns:
        A new array of doubles with the imaginary parts of the array of complex numbers.
      • l2norm

        public static final double l2norm​(Complex[] array)
        Return a double that is the L2-norm of the array. If the length of the array is zero, return 0.0.
        Parameters:
        array - The given array of complex numbers.
        Returns:
        A double that is the L2-norm of array.
      • l2normSquared

        public static final double l2normSquared​(Complex[] array)
        Return a double that is the sum of the squared magnitudes of the elements of array. This is equal to the square of the L2-norm of array. If the length of the array is zero, return 0.0.
        Parameters:
        array - The given array of complex numbers.
        Returns:
        A double that is square of the L2-norm of array.
      • limit

        public static final Complex[] limit​(Complex[] array,
                                            Complex bottom,
                                            Complex top)
                                     throws java.lang.IllegalArgumentException
        Return a new array that is a copy of the first argument except that the elements are limited to lie within the specified range. The specified range is given by two complex numbers, bottom and top, where both the real and imaginary parts of bottom are expected to be less than the real and imaginary parts of top. Thus, bottom and top define a rectangle in the complex plane, with bottom at the lower left and top at the upper right. If any value in the array is infinite then it is replaced by the corresponding real or imaginary part of top or bottom, depending on the sign of infinity. If any value is NaN (not a number), then the result will be NaN. To leave either the bottom or the top unconstrained, specify Complex.NEGATIVE_INFINITY or Complex.POSITIVE_INFINITY. If the length of the array is 0, return a new array of length 0.
        Parameters:
        array - An array of complex numbers.
        bottom - The bottom limit.
        top - The top limit.
        Returns:
        A new array with values in the rectangle defined by bottom and top.
        Throws:
        java.lang.IllegalArgumentException - If bottom has either a real or imaginary part larger than the corresponding part of top.
      • magnitude

        public static final double[] magnitude​(Complex[] array)
        Return a new array of doubles containing the magnitudes of the elements of the specified array of complex numbers.
        Parameters:
        array - The given array of complex numbers.
        Returns:
        A new array of doubles containing the magnitudes of the elements of the specified array of complex numbers.
      • multiply

        public static final Complex[] multiply​(Complex[] array1,
                                               Complex[] array2)
        Return a new array that is the element-by-element multiplication of the two input arrays. If the size of each array is 0, return a new array of size 0.
        Parameters:
        array1 - The first array of complex numbers.
        array2 - The second array of complex numbers.
        Returns:
        A new array of complex numbers equal to the element-by-element multiplication of the two given arrays.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • multiply

        public static final Complex[] multiply​(Complex[] array,
                                               Complex factor)
        Return a new array that is constructed from the argument by multiplying each element in array by the second argument, which is a complex number. If the size of the array is 0, return a new array of size 0.
        Parameters:
        array - An array of complex numbers.
        factor - The complex number by which each element of array is multiplied by.
        Returns:
        A new array of complex numbers formed by multiplying each element in array by factor.
      • negative

        public static final Complex[] negative​(Complex[] array)
        Return a new array that is the formed from the additive inverse of each element of the input array (-array[i]).
        Parameters:
        array - The given array of complex numbers.
        Returns:
        A new array of complex numbers formed from the additive inverse of each element of the input array (-array[i]).
      • padMiddle

        public static final Complex[] padMiddle​(Complex[] array,
                                                int newLength)
        Return a new array of Complex numbers that is formed by padding the middle of the array with 0's. If the length of the input array is odd, the sample with index ceil(L/2) will be repeated in the output array, where L is the length of the input array. If the lengths of the input and output arrays are equal, return a copy of the input array. This method is useful for preparing data for an IFFT.
        Parameters:
        array - An array of complex numbers.
        newLength - The desired length of the returned array.
        Returns:
        A new array of complex numbers formed by padding the middle of array with 0's.
      • phase

        public static final double[] phase​(Complex[] array)
        Return a new array containing the angles of the elements of the specified complex array.
        Parameters:
        array - An array of complex numbers.
        Returns:
        An array of angles in the range of -pi to pi.
      • polynomial

        public static final Complex[] polynomial​(Complex[] roots)
        Given the roots of a polynomial, return a polynomial that has has such roots. If the roots are [r0, ..., rN-1], then the polynomial is given by [a0, ..., aN], where

        a0 + a1z-1 + ... + aNz-N = (1 - r0z-1) (1 - r1z-1) ... (1 - rN-1z-1). The returned polynomial will always be monic, meaning that a0 = 1.

        Parameters:
        roots - An array of roots of a polynomial.
        Returns:
        A new array representing a monic polynomial with the given roots.
      • pow

        public static final Complex[] pow​(Complex[] array,
                                          double exponent)
        Return a new array of complex numbers that is formed by raising each element to the specified exponent, a double. If the size of the array is 0, return a new array of size 0.
        Parameters:
        array - The input array of complex numbers.
        exponent - A double, which is the exponent.
        Returns:
        A new array that is formed by raising each element of array to the elementth power.
      • product

        public static final Complex product​(Complex[] array)
        Return the product of the elements in the array. If there are no elements in the array, return a Complex number with value zero.
        Parameters:
        array - An array of complex numbers.
        Returns:
        A new complex number equal to the product of the elements in the array.
      • realParts

        public static final double[] realParts​(Complex[] x)
        Return a new array of doubles that includes the real parts of the array of complex numbers.
        Parameters:
        x - An array of complex numbers
        Returns:
        A new array of doubles that includes the real parts of the array of complex numbers.
      • resize

        public static final Complex[] resize​(Complex[] array,
                                             int newLength)
        Return a new array of length newLength that is formed by either truncating or padding the input array. This method simply calls : resize(array, newLength, 0)
        Parameters:
        array - An array of complex numbers.
        newLength - The desired size of the output array.
        Returns:
        A new array of length newLength that is formed by either truncating or padding array.
      • resize

        public static final Complex[] resize​(Complex[] array,
                                             int newLength,
                                             int startIdx)
        Return a new array of length newLength that is formed by either truncating or padding the input array. Elements from the input array are copied to the output array, starting from array[startIdx] until one of the following conditions is met : 1) The input array has no more elements to copy. 2) The output array has been completely filled. startIdx must index a valid entry in array unless the input array is of zero length or the output array is of zero length. If case 1) is met, the remainder of the output array is filled with new complex numbers with value 0. Copying here means shallow copying, i.e. pointers to Complex objects are copied instead of allocation of new copies. This works because Complex objects are immutable.
        Parameters:
        array - An array of complex numbers.
        newLength - The desired size of the output array.
        startIdx - The starting index for the input array.
        Returns:
        A new array of length newLength that is formed by either truncating or padding array.
      • scale

        public static final Complex[] scale​(Complex[] array,
                                            Complex factor)
        Return a new array that is constructed from the argument by scaling each element in array by factor, which is a complex number. If the array argument is of length 0, return a new array of length 0.
        Parameters:
        array - An array of complex numbers.
        factor - A complex number used to multiply each element of array by.
        Returns:
        A new array of complex numbers that is constructed from the argument by scaling each element in array by factor.
      • scale

        public static final Complex[] scale​(Complex[] array,
                                            double factor)
        Return a new array that is constructed from the argument by scaling each element in the array by factor, which is a double. If the array argument is of length 0, return a new array of length 0.
        Parameters:
        array - An array of complex numbers.
        factor - A double used to multiply each element of array by.
        Returns:
        A new array of complex numbers that is constructed from the argument by scaling each element in array by factor.
      • subtract

        public static final Complex[] subtract​(Complex[] array,
                                               Complex z)
        Return a new array that is constructed by subtracting the complex number z from every element in the given array. If the array argument is of length 0, return a new array of length 0.
        Parameters:
        array - An array of complex numbers.
        z - A complex number subtracted from each element of array.
        Returns:
        A new array that is constructed by subtracting z from every element in array.
      • subtract

        public static final Complex[] subtract​(Complex[] array1,
                                               Complex[] array2)
        Return a new array that is the element-by-element subtraction of the second array from the first array. If the size of each array is 0, return a new array of size 0.
        Parameters:
        array1 - An array of complex numbers from which to subtract.
        array2 - An array of complex numbers to subtract.
        Returns:
        A new array of complex numbers equal to the element-by-element subtraction of the second array from the first array.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • toString

        public static final java.lang.String toString​(Complex[] array)
        Return a new String representing the array, formatted as in Java array initializers.
        Parameters:
        array - An array of complex numbers.
        Returns:
        A new string representing the array.
      • toString

        public static final java.lang.String toString​(Complex[] array,
                                                      java.lang.String elementDelimiter,
                                                      java.lang.String vectorBegin,
                                                      java.lang.String vectorEnd)
        Return a new String representing the array, formatted specified starting with vectorBegin, where each successive element is separated by elementDelimiter and ending with vectorEnd.
        Parameters:
        array - An array of complex numbers.
        elementDelimiter - The delimiter between elements, typically ", ".
        vectorBegin - The start of the array, typically "{".
        vectorEnd - The end of the array, typically "}".
        Returns:
        A new string representing the array in the format specified by the ArrayStringFormat argument.
      • within

        public static final boolean within​(Complex[] array1,
                                           Complex[] array2,
                                           Complex maxError)
        Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitude of maxError. If both arrays are empty, return true.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        maxError - A complex number whose magnitude is taken to be the distance threshold.
        Returns:
        True if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitude of maxError.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • within

        public static final boolean within​(Complex[] array1,
                                           Complex[] array2,
                                           double maxError)
        Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to maxError. If both arrays are empty, return true. If maxError is negative, return false.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        maxError - The threshold for the magnitude of the difference.
        Returns:
        True if all the distances between corresponding elements array1 and array2 are all less than or equal to maxError.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • within

        public static final boolean within​(Complex[] array1,
                                           Complex[] array2,
                                           double[] maxError)
        Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the corresponding elements in maxError. If both arrays are empty, return true. If any element in maxError is negative, return false.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        maxError - The array of thresholds for the magnitudes of the difference.
        Returns:
        True if all the distances between corresponding elements array1 and array2 are all less than or equal to the corresponding elements in maxError.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • within

        public static final boolean within​(Complex[] array1,
                                           Complex[] array2,
                                           Complex[] maxError)
        Return true if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitudes of the corresponding elements in maxError. If both arrays are empty, return true.

        Note that there is no notion of negative distance with complex numbers, so unlike the within() methods for other types, this method will not return false if an element of the maxError matrix is negative.

        Parameters:
        array1 - The first array.
        array2 - The second array.
        maxError - An array of complex numbers whose magnitude for each element is taken to be the distance threshold.
        Returns:
        True if all the distances between corresponding elements array1 and array2 are all less than or equal to the magnitudes of the corresponding elements in maxError.
        Throws:
        java.lang.IllegalArgumentException - If the arrays are not of the same length.
      • _commonLength

        protected static final int _commonLength​(Complex[] array1,
                                                 Complex[] array2,
                                                 java.lang.String methodName)
        Throw an exception if the two arrays are not of the same length, or if either array is null. An exception is NOT thrown if both arrays are of length 0. If no exception is thrown, return the common length of the arrays.
        Parameters:
        array1 - The first array of doubles.
        array2 - The second array of doubles.
        methodName - A String representing the method name of the caller, without parentheses.
        Returns:
        The common length of both arrays.