Last active
August 29, 2015 14:05
-
-
Save mlgill/bfd8d5684ce1d24b0e77 to your computer and use it in GitHub Desktop.
Issue with passing wavetable array for use with FFT from GNU Scientific Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <gsl/gsl_fft_complex.h> | |
| #include <stdio.h> | |
| void fft_test(int *dims, gsl_fft_complex_wavetable *wt, gsl_fft_complex_wavetable *wt_x, gsl_fft_complex_wavetable *wt_y, gsl_fft_complex_wavetable *wt_z) { | |
| printf("\nFFT Test\n"); | |
| printf("%d, %d, %d\n", dims[0], dims[1], dims[2]); // This is OK | |
| printf("%d, %d, %d\n", wt_x, wt_y, wt_z); // These are equal to values from main function--OK | |
| printf("%d, %d, %d\n", &wt[0], &wt[1], &wt[2]); // The first value is equal to those printed in main function, but the rest are not equal | |
| // Perhaps it is somehow calling the address of wt but not that of the elements of wt? | |
| } | |
| int main() | |
| { | |
| // Dimension sizes for a 3D Fourier transform | |
| int m = 32; | |
| int n = 64; | |
| int q = 24; | |
| // Wavetables for a 3D FT using GSL | |
| gsl_fft_complex_wavetable *wt_x; | |
| gsl_fft_complex_wavetable *wt_y; | |
| gsl_fft_complex_wavetable *wt_z; | |
| wt_x = gsl_fft_complex_wavetable_alloc(m); | |
| wt_y = gsl_fft_complex_wavetable_alloc(n); | |
| wt_z = gsl_fft_complex_wavetable_alloc(q); | |
| printf("Main\n"); | |
| //The simple example--check that these are the same | |
| int dims[3] = {m, n, q}; | |
| printf("%d, %d, %d\n", m, n, q); | |
| printf("%d, %d, %d\n", dims[0], dims[1], dims[2]); // OK--equal to above values | |
| // Want to combine wavetables into an array of wavetables so the function fft_test can be n-dimensional | |
| gsl_fft_complex_wavetable *wt[3] = {wt_x, wt_y, wt_z}; // It seems this has to be a pointer unlike dims | |
| // Check that these are the same addresses | |
| printf("%d, %d, %d\n", wt_x, wt_y, wt_z); | |
| printf("%d, %d, %d\n", wt[0], wt[1], wt[2]); // OK--equal to above values | |
| // Try to pass wt to the function and see if addresses are the same | |
| fft_test(dims, *wt, wt_x, wt_y, wt_z); // It seems wt has to be passed as a pointer otherwise warnings are generated | |
| return 0; | |
| } |
Author
Author
I've solved it--a struct has to be created for the array.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output:
As can be seen, the issue arises in FFT Test with the second and third values of the wavetable array. They are close to, but not the same as, the values from the main function. When passed individually, however, the wavetables produce the correct values.
I'm not the greatest C-coder, so this may be an issue with pointers and dereferencing. However, I've gotten a simple example to work (above) and have tried everything I can think of to get the more complex example to compile without errors and produce the correct values. Suggestions appreciated.