guru r2r矩阵转置功能
通过guru类r2r接口的特殊用法,可以实现矩阵转置功能。使用KML_FFT guru类接口创造一个rank为0,howmany_rank为2的转换。
例:
kml_fft_plan plan_transpose(int rows, int cols, double *in, double *out)
{
const unsigned flags = KML_FFT_ESTIMATE;
kml_fft_iodim howmany_dims[2];
howmany_dims[0].n = rows;
howmany_dims[0].is = cols;
howmany_dims[0].os = 1;
howmany_dims[1].n = cols;
howmany_dims[1].is = 1;
howmany_dims[1].os = rows;
return kml_fft_plan_guru_r2r(/*rank=*/ 0, /*dims=*/ NULL,
/*howmany_rank=*/ 2, howmany_dims,
in, out, /*kind=*/ NULL, flags);
}
int main() {
int len = 12;
int rows = 3;
int cols = 4;
double *in = (double *)malloc(len * sizeof(double));
for(int i = 0; i < len; i++) {
in[i] = i;
}
/*
* 0 1 2 3
* 4 5 6 7
* 8 9 10 11
*/
kml_fft_plan p = plan_transpose(rows, cols, in, in);
kml_fft_execute(p);
/*
* 0 4 8
* 1 5 9
* 2 6 10
* 3 7 11
*/
free(in);
kml_fft_destroy_plan(p);
}