scipy/scipy — pull request #3664 by endolith (2014-05-17 04:10:30+00:00)
Title: BUG: correlate was extremely slow when in2.size > in1.size

Direct correlation/convolution is recommended when one input is much smaller than the other, since it can be faster than fft convolution. However for scipy's version this is not true if the second input is larger than the first, probably because the underlying C code is only optimized for the case of the first input being larger than the second, since the "old behavior" of automatically swapping the inputs mandated this.

So this change swaps the inputs if the first is smaller, but then reverses and conjugates the output to undo the effects of the reversal.

This is not needed for valid mode since in1.size < in2.size is rejected
'same' mode does not seem to suffer from this, since the output size is determined by in1?

```
a = rand(50000)
b = rand(3)

timeit convolve(a, b, 'same')
100 loops, best of 3: 7.83 ms per loop

timeit convolve(b, a, 'same')
100 loops, best of 3: 3.02 ms per loop
```

but it's definitely needed for 'full' mode, which can be extremely slower:

```
a = rand(50000)
b = rand(3)

timeit convolve(a, b, 'full')
100 loops, best of 3: 7.89 ms per loop

timeit convolve(b, a, 'full')
1 loops, best of 3: 48.9 s per loop (6200 times as long)
```