What is the difference between Permute Dimensions and Transpose blocks in discrete systems?
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Deep
on 23 Jan 2025 at 5:36
Edited: Deep
on 23 Jan 2025 at 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 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!