One-line FFT, nice!

Manu turkeyman at gmail.com
Wed Sep 12 03:35:44 PDT 2012


On 9 September 2012 01:56, Mehrdad <wfunction at hotmail.com> wrote:

> I was pretty excited to figure out that a one-liner FFT is
> possible in D!
> creal[] dft(creal[] v) { return v.length > 1 ? (p => chain(map!(q
> => q[0] + q[1])(p), map!(q => q[0] -
> q[1])(p)))(zip(dft(v.stride(2)**.array()), map!(p => p[1] *
> expi(p[0] * -2 * PI / v.length))(zip(iota(v.length / 2),
> dft(v.drop(1).stride(2).array(**)))))).array() : v; }
>
> Of course, the Python version is still shorter:
> def dft(v): return (lambda e, o: map(add, e, o) + map(sub, e,
> o))(dft(v[0::2]), [o * rect(1, k * -2 * pi / len(v)) for k, o in
> enumerate(dft(v[1::2]))]) if len(v) > 1 else v
>
> but it's still cool (barring the unreadability, haha).
> Yay D!
>

Very curious to know how this performs. Since it's making use of lots of
templates from the standard library, how much do they influence efficiency?
How well does the compiler do its job optimising this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120912/28343fbe/attachment-0001.html>


More information about the Digitalmars-d mailing list