What is the difference between Permute Dimensions and Transpose blocks in discrete systems?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
Deep
am 23 Jan. 2025 um 5:36
Bearbeitet: Deep
am 23 Jan. 2025 um 5:38
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!