I have copied Mark Borgerding's kissfft.hh (templated version of his FFT code) into my project and modified it to use iterators instead of pointers. Using Xcode all is well. When I tried to run it after compiling with Microsoft's Visual C++ 2017 I get an assertion error from the following code:
void transform(ComplexIterator fft_in, ComplexIterator fft_out) const
{
ComplexIterator const Fout_beg = fft_out;
ComplexIterator const Fout_end = fft_out + p*m;
do{
*fft_out = *fft_in;
fft_in += fstride;
}while(++fft_out != Fout_end );
...
"ComplexIterator" is a template type, and in this situation it is a vanilla std::vector< std::complex >::iterator. Sometimes Fout_end is pointing somewhere in the middle of the std::vector, and sometimes it is pointing one spot after the last element in the std::vector, exactly like std::vector.end(). When it is pointing to one spot after the last element, the "while" statement causes an assertion error, because the iterator went past the last element in the vector. It only went past by one (i.e. it was equal to Fout_end), but that didn't matter.
The thing is, I thought that this was standard practice for iterators. You keep iterating until you hit "end", which is outside the std::vector. I created a simple test program to check if it also tripped the assertion check.
std::vector<int> p(5);
for (auto it = p.begin(); it != p.end(); it+=1) { // do it+=1 to make it a little more like the failing code
std::cout << *it << std::endl;
}
It doesn't. What's going on here. Why is the FFT code tripping the assertion check. I can get rid of the problem by switching to Release mode, then everything works great, but I want to know if I'm doing something wrong.
Aucun commentaire:
Enregistrer un commentaire