Rate This Document
Findability
Accuracy
Completeness
Readability

Guru R2R Matrix Transposition

Implement the matrix transposition function through the special usage of the r2r interface of the guru class. Use the KML_FFT guru class interface to create a transformation whose rank is 0 and howmany_rank is 2.

For example:
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);
}