kml_fft(f)_plan_guru_dft_c2r
建立多组数据序列n维C2R变换的plan。其中,单个FFT的数据序列不需要是连续的,可以以跨步的形式提供。
接口定义
C interface:
kml_fft_plan kml_fft_plan_guru_dft_c2r(int rank, const kml_fft_iodim *dims, int howmany_rank, const kml_fft_iodim *howmany_dims, kml_fft_complex *in, double *out, unsigned flags);
kml_fftf_plan kml_fftf_plan_guru_dft_c2r(int rank, const kml_fftf_iodim *dims, int howmany_rank, const kml_fftf_iodim *howmany_dims, kml_fft_complex *in, float *out, unsigned flags);
Fortran interface:
RES = KML_FFT_PLAN_GURU_DFT_C2R(RANK, DIMS, HOWMANY_RANK, HOWMANY_DIMS, IN, OUT, FLAGS);
RES = KML_FFTF_PLAN_GURU_DFT_C2R(RANK, DIMS, HOWMANY_RANK, HOWMANY_DIMS, IN, OUT, FLAGS);
返回值
函数返回一个kml_fft(f)_plan类型的结构体指针。将该对象作为参数传入kml_fft(f)_execute函数中使用,将对当前提供的输入in和输出out执行FFT变换;另外,也可以通过将该对象作为参数传入kml_fft(f)_execute_dft_c2r函数中以对新的输入in和输出out执行FFT变换。
如果函数返回非空指针,则表示plan执行成功,否则表示执行失败。
参数
参数名 |
数据类型 |
描述 |
输入/输出 |
---|---|---|---|
rank |
int |
单个FFT序列的维度。 约束:1 ≤ rank ≤ 3。 |
输入 |
dims |
|
dims是大小为rank的结构体数组,dims[i]包含以下成员:
约束:dims[i].n ≥ 1, for i in 0 to rank - 1。 |
输入 |
howmany_rank |
int |
多个rank维FFT之间的内存排布用howmany_rank维的howmany_dims数组来描述,howmany_rank表示每个要计算的rank维FFT变换的起始地址的内存访问模式所需的维数。 约束:0 ≤ howmany_rank ≤ 3。 |
输入 |
howmany_dims |
|
howmany_dims是大小为howmany_rank的结构体数组,howmany_dims[i]包含以下成员:
|
输入 |
in |
|
输入待变换的数据。 |
输入 |
out |
|
输出快速傅里叶变换后的数据。 |
输出 |
flags |
unsigned int |
planning选项,未使用。 |
输入 |
依赖
C: "kfft.h"
示例
C interface:
int rank = 2; kml_fft_iodim *dims; dims = (kml_fft_iodim*)kml_fft_malloc(sizeof(kml_fft_iodim) * rank); dims[0].n = 2; dims[0].is = 2; dims[0].os = 3; dims[1].n = 3; dims[1].is = 1; dims[1].os = 1; int howmany_rank = 1; kml_fft_iodim *howmany_dims; howmany_dims = (kml_fft_iodim*)kml_fft_malloc(sizeof(kml_fft_iodim) * howmany_rank); howmany_dims[0].n = 2; howmany_dims[0].is = 2 * 2; howmany_dims[0].os = 2 * 3; double init[8][2] = {{120, 0}, {8, 8}, {0, 0}, {0, 16}, {0, 16}, {-8, 8}, {-8, 0}, {-8, 8}}; kml_fft_complex *in; in = (kml_fft_complex*)kml_fft_malloc(sizeof(kml_fft_complex) * 8); for (int i = 0; i < 8; i++) { in[i][0] = init[i][0]; in[i][1] = init[i][1]; } double *out; out = (double*)kml_fft_malloc(sizeof(double) * 12); kml_fft_plan plan; plan = kml_fft_plan_guru_dft_c2r(rank, dims, howmany_rank, howmany_dims, in, out, KML_FFT_ESTIMATE); kml_fft_execute_dft_c2r(plan, in, out); kml_fft_destroy_plan(plan); kml_fft_free(howmany_dims); kml_fft_free(dims); kml_fft_free(in); kml_fft_free(out); /* * out = {1.360000e+02, 7.043078e+01, 1.535692e+02, 1.360000e+02, * 1.258564e+02, 9.814359e+01, -4.000000e+01, -1.971281e+01, * 3.571281e+01, 8.000000e+00, 8.000000e+00, 8.000000e+00} */
Fortran interface:
INTEGER(C_INT) :: RANK = 2 INTEGER(C_INT) :: HOWMANY_RANK = 1 REAL(C_DOUBLE), DIMENSION(8, 2) :: INIT TYPE(KML_FFT_IODIM), POINTER :: DIMS(:), HOWMANY_DIMS(:) TYPE(KML_FFT_COMPLEX), POINTER :: IN(:) REAL(8), POINTER :: OUT(:) TYPE(C_PTR) :: PIN, POUT, PDIMS, PHOWMANY_DIMS INTEGER(C_SIZE_T) :: CSIZE, RSIZE CSIZE = 16 * 8 RSIZE = 8 * 12 PIN = KML_FFT_MALLOC(CSIZE) POUT = KML_FFT_MALLOC(RSIZE) CALL C_F_POINTER(PIN, IN, SHAPE=[8]) CALL C_F_POINTER(POUT, OUT, SHAPE=[12]) CSIZE = 12 * 2 RSIZE = 12 * 1 PIODIMS = KML_FFT_MALLOC(CSIZE) PHOWMANY_IODIMS = KML_FFT_MALLOC(RSIZE) CALL C_F_POINTER(PIODIMS, DIMS, SHAPE=[2]) CALL C_F_POINTER(PHOWMANY_DIMS, HOWMANY_DIMS, SHAPE=[1]) DIMS(0)%N = 2 DIMS(0)%IS = 2 DIMS(0)%OS = 3 DIMS(1)%N = 3 DIMS(1)%IS = 1 DIMS(1)%OS = 1 HOWMANY_DIMS(0)%N = 2 HOWMANY_DIMS(0)%IS = 2 * 2 HOWMANY_DIMS(0)%OS = 2 * 3 DATA INIT/120, 8, 0, 0, 0, -8, -8, -8, 0, 8, 0, 16, 16, 8, 0, 8/ INTEGER :: I DO WHILE(I <= 8) IN(I)%R = INIT(I, 0) IN(I)%I = INIT(I, 1) END DO TYPE(C_PTR) :: PLAN PLAN = KML_FFT_PLAN_GURU_DFT_C2R(RANK, DIMS, HOWMANY_RANK, HOWMANY_DIMS, IN, OUT, KML_FFT_ESTIMATE) CALL KML_FFT_EXECUTE_DFT_C2R(PLAN, IN, OUT); CALL KML_FFT_DESTROY_PLAN(PLAN) CALL KML_FFT_FREE(PHOWMANY_DIMS) CALL KML_FFT_FREE(PDIMS) CALL KML_FFT_FREE(PIN) CALL KML_FFT_FREE(POUT) ! ! OUT = /1.360000E+02, 7.043078E+01, 1.535692E+02, 1.360000E+02, ! 1.258564E+02, 9.814359E+01, -4.000000E+01, -1.971281E+01, ! 3.571281E+01, 8.000000E+00, 8.000000E+00, 8.000000E+00/ !