Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/Fast-Fourier-transform/D/fast-fourier-transform-1.d
Normal file
5
Task/Fast-Fourier-transform/D/fast-fourier-transform-1.d
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
void main() {
|
||||
import std.stdio, std.numeric;
|
||||
|
||||
[1.0, 1, 1, 1, 0, 0, 0, 0].fft.writeln;
|
||||
}
|
||||
15
Task/Fast-Fourier-transform/D/fast-fourier-transform-2.d
Normal file
15
Task/Fast-Fourier-transform/D/fast-fourier-transform-2.d
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import std.stdio, std.algorithm, std.range, std.math;
|
||||
|
||||
const(creal)[] fft(in creal[] x) pure /*nothrow*/ @safe {
|
||||
immutable N = x.length;
|
||||
if (N <= 1) return x;
|
||||
const ev = x.stride(2).array.fft;
|
||||
const od = x[1 .. $].stride(2).array.fft;
|
||||
auto l = iota(N / 2).map!(k => ev[k] + expi(-2*PI * k/N) * od[k]);
|
||||
auto r = iota(N / 2).map!(k => ev[k] - expi(-2*PI * k/N) * od[k]);
|
||||
return l.chain(r).array;
|
||||
}
|
||||
|
||||
void main() @safe {
|
||||
[1.0L+0i, 1, 1, 1, 0, 0, 0, 0].fft.writeln;
|
||||
}
|
||||
16
Task/Fast-Fourier-transform/D/fast-fourier-transform-3.d
Normal file
16
Task/Fast-Fourier-transform/D/fast-fourier-transform-3.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.stdio, std.algorithm, std.range, std.math, std.complex;
|
||||
|
||||
auto fft(T)(in T[] x) pure /*nothrow @safe*/ {
|
||||
immutable N = x.length;
|
||||
if (N <= 1) return x;
|
||||
const ev = x.stride(2).array.fft;
|
||||
const od = x[1 .. $].stride(2).array.fft;
|
||||
alias E = std.complex.expi;
|
||||
auto l = iota(N / 2).map!(k => ev[k] + T(E(-2* PI * k/N)) * od[k]);
|
||||
auto r = iota(N / 2).map!(k => ev[k] - T(E(-2* PI * k/N)) * od[k]);
|
||||
return l.chain(r).array;
|
||||
}
|
||||
|
||||
void main() {
|
||||
[1.0, 1, 1, 1, 0, 0, 0, 0].map!complex.array.fft.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue