Skip to content

Instantly share code, notes, and snippets.

@mlgill
Last active August 29, 2015 14:05
Show Gist options
  • Save mlgill/bfd8d5684ce1d24b0e77 to your computer and use it in GitHub Desktop.
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
#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;
}
@mlgill
Copy link
Author

mlgill commented Sep 1, 2014

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