What is the difference between Permute Dimensions and Transpose blocks in discrete systems?

5 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Deep
Deep el 23 de En. de 2025 a las 5:36
Editada: Deep el 23 de En. de 2025 a las 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.

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by