C
C#3y ago
hoggy077

Iterative from Recursive [Answered]

Can someone lend me a hand converting this to Iterative. I cant wrap my head around converting a split recursion
int ii = 0;
int kk = 0;
int N = x.Length;

Complex[] Y = new Complex[N];


if (N == 1)
{
Y[0] = x[0];
return Y;
}

Complex[] E, O, even, odd = new Complex[N / 2];
E = O = even = odd;

for (ii = 0; ii < N; ii++)
{

if (ii % 2 == 0)
{
even[ii / 2] = x[ii];
}
if (ii % 2 == 1)
{
odd[(ii - 1) / 2] = x[ii];
}
}

E = fft(even);
O = fft(odd);

for (kk = 0; kk < N; kk++)
{
Y[kk] = E[(kk % (N / 2))] + O[(kk % (N / 2))] * twiddles[kk * wSamp / N];
}

return Y;
int ii = 0;
int kk = 0;
int N = x.Length;

Complex[] Y = new Complex[N];


if (N == 1)
{
Y[0] = x[0];
return Y;
}

Complex[] E, O, even, odd = new Complex[N / 2];
E = O = even = odd;

for (ii = 0; ii < N; ii++)
{

if (ii % 2 == 0)
{
even[ii / 2] = x[ii];
}
if (ii % 2 == 1)
{
odd[(ii - 1) / 2] = x[ii];
}
}

E = fft(even);
O = fft(odd);

for (kk = 0; kk < N; kk++)
{
Y[kk] = E[(kk % (N / 2))] + O[(kk % (N / 2))] * twiddles[kk * wSamp / N];
}

return Y;
4 Replies
Anton
Anton3y ago
copy the whole function, with the signature
Complex[] E, O, even, odd = new Complex[N / 2];
E = O = even = odd;
Complex[] E, O, even, odd = new Complex[N / 2];
E = O = even = odd;
fyi, this doesn't make 4 separate arrays, it still uses the same reference
hoggy077
hoggy077OP3y ago
I should provide context. This is inside of a task to be multithreaded and I'm trying to avoid a task that spawns more tasks. Would that work in this scenario?
Anton
Anton3y ago
you're sayying it's anonymous? there's no recursion then
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server