What is the difference between Permute Dimensions and Transpose blocks in discrete systems?
Mostra commenti meno recenti
My question is regarding the Permute Dimensions and Transpose blocks in Models targeted to generate code via EmbeddedCoder.
1 - What is the difference between the blocks in terms of functionality and CPU load and speed in generated code.
2 - Which is generally better?
Risposte (1)
colordepth
il 23 Gen 2025
Modificato: colordepth
il 23 Gen 2025
The following analysis is specifically focused on the transposition of 2D matrices. I performed a C code generation with maximum optimization settings using the "Permute Dimensions" and "Transpose" blocks for a (300, 301) dimensional input.
Permute Dimensions Block:
yElIdx = 0;
uElOffset1 = 0;
for (ntIdx1 = 0; ntIdx1 < 300; ntIdx1++) {
for (ntIdx0 = 0; ntIdx0 < 301; ntIdx0++) {
myModel_Y.Out1[yElIdx + ntIdx0] = myModel_U.Input[ntIdx0 * 300 + uElOffset1];
}
yElIdx += 301;
uElOffset1++;
}
The code generated for the "Permute Dimensions" handles complex N-D array manipulations, introducing additional indexing variables that make the code slightly more complex and potentially less efficient for simple 2D transpositions.
Transpose Block:
for (i_0 = 0; i_0 < 300; i_0++) {
for (i = 0; i < 301; i++) {
myModel_Y.Out2[i + 301 * i_0] = myModel_U.Input[300 * i + i_0];
}
}
The "Transpose" block is the better choice for 2D arrays in terms of simplicity and performance.
Categorie
Scopri di più su Deployment, Integration, and Supported Hardware in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!