* @param oB0 Second vector
     * @param mode Convolution mode; see PyMultiarray.convolve
     * @return Cross-correlation of the two vectors
     */
    public static PyMultiarray cross_correlate(final PyObject oA0, final PyObject oB0, final int mode) {
        final boolean debug_this = false;
        if (debug_this) {
            System.out.println("MODE = " + mode);
        }
        PyMultiarray a0 = PyMultiarray.asarray(oA0), b0 = PyMultiarray
                .asarray(oB0);
        // Check arguments (If anyone cares, the 1d requirement could probably
        // be relaxed.)
        if (a0.dimensions.length != 1 || b0.dimensions.length != 1) { throw Py
                .ValueError("cross_correlate only works on 1D arrays"); }
        // Make the arrays contiguous and then make a copy of the nondata parts.
        a0 = PyMultiarray.ascontiguous(a0);
        b0 = PyMultiarray.ascontiguous(b0);
        final PyMultiarray a = new PyMultiarray(
                a0.data,
                a0._typecode,
                a0.start,
                a0.dimensions.clone(),
                a0.strides.clone());
        final PyMultiarray b = new PyMultiarray(
                b0.data,
                b0._typecode,
                b0.start,
                b0.dimensions.clone(),
                b0.strides.clone());

        final char type = PyMultiarray.commonType(a._typecode, b._typecode);
        final int length = Math.max(a.dimensions[0], b.dimensions[0]);

        /*
         * To do proper convolution(A, B), it's not enough to just FFT A and B,
         * multiply A and conjugate(B), and return the real part of the
         * inverse-FFT.
         * You need to pad.
         * Padding serves two purposes:
         * 1. It makes the vector's length equal to a power of two, so that the
         * FFT is happy.
         * 2. It prevents contamination of the results by the assumption of an
         * infinite series,
         * when any real-life series is finite.
         * 3. We do more than just padding - we re-arrange the data into a
         * particular format.
         * How much contamination is satisfactory?
         * That's determined by the choice of 'mode' variable. See User Guide
         * for CNumeric.
         * We use the FFT for a number of reasons:
         * 1. It's much faster than computing the convolution by the direct
         * method
         * (O[NlogN] compared to O[N^2])
         * 2. The FFT has already been implemented, so we don't have as much
         * work to do here.
         * 3. Any improvements made in the future to the FFT routines
         * will automatically be available here too.
         */

        // Create copies of the two arrays, arranged in particular format,
        // pad them out to a power of two.

        final int padl = PyMultiarray.XC_padded_length(length);
        if (debug_this) {
            System.out.println("Length = " + length + " --> PADL = " + padl);
        }

        final PyMultiarray a_pad = PyMultiarray.XC_pad_vector(a, padl);
        final PyMultiarray fft_a = FFT.fft(a_pad);

        final PyMultiarray b_pad = PyMultiarray.XC_pad_vector(b, padl);

        /*
         * FF-Transformed arrays are complex, so is their product.
         * Correlation works only on real (or integer) arguments and
         * the result should have the same type as the original
         * vectors. If integer, we need to make sure that we
         * round, not just truncate.
         * Finally, copy results into standard order ('unpad' them).
         */
        final PyMultiarray prod = PyMultiarray.zeros(new int[] { padl }, 'D');
        fft_a.__mul__(Umath.conjugate.__call__(FFT.fft(b_pad)), prod);
        PyMultiarray inverse_prod_real = FFT.inverse_fft(prod).getReal();

        PyMultiarray result;
        if (PyMultiarray.typeToKind(type) == PyMultiarray.INTEGER) {
            // This needs to be converted to a bona fide round() function.
            // Anyone know is there is one already?
            inverse_prod_real = (PyMultiarray) inverse_prod_real.__add__(Py
                    .newFloat(0.5));
            final PyMultiarray inverse_prod_real_round = PyMultiarray.asarray(
                    inverse_prod_real,
                    type);
            inverse_prod_real = inverse_prod_real_round;
            result = PyMultiarray.XC_unpad_vector(
                    inverse_prod_real_round,
                    a.dimensions[0],
                    b.dimensions[0],
                    mode);
        }
        else {
            result = PyMultiarray.XC_unpad_vector(
                    inverse_prod_real,
                    a.dimensions[0],
                    b.dimensions[0],
                    mode);
        }
        if (debug_this) {
            System.out.println("\nCROSS_CORRELATE: RESULT = " + result);
        }
        return result;
    }