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

8 ビュー (過去 30 日間)
Omar Ashraf
Omar Ashraf 2022 年 9 月 13 日
編集済み: Deep 2025 年 1 月 23 日 5:38
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?

回答 (1 件)

Deep
Deep 2025 年 1 月 23 日 5:36
編集済み: Deep 2025 年 1 月 23 日 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.

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by