coder.noImplicitExpansionInFunction
R2026b生成コードの指定した関数内で暗黙的な拡張を無効化
説明
coder.noImplicitExpansionInFunction は、それが呼び出される MATLAB® 関数の生成コードで暗黙的な拡張を無効にします。
暗黙的な拡張を無効にすると、生成コードでの二項演算および二項関数の適用時にオペランドの自動サイズ変更や追加のコード生成が行われず、パフォーマンスも変化しません。暗黙的な拡張を有効にしたコードの生成、生成コードでの暗黙的な拡張の最適化、および基本的な演算で互換性のある配列サイズを参照してください。
coder.noImplicitExpansionInFunction は、生成コードの二項演算にのみ影響します。この関数では、MATLAB コードでの暗黙的な拡張は無効になりません。特定の二項演算および二項関数を MATLAB で暗黙的な拡張なしで適用するには、coder.sameSizeBinaryOp を使用します。
例
coder.noImplicitExpansionInFunction を目的の関数内で呼び出して、その MATLAB 関数の生成コードで暗黙的な拡張を無効にします。暗黙的な拡張を無効にすると、二項演算および二項関数の適用時に以下が発生しません。
サイズに互換性があるオペランドの自動サイズ変更
追加のコード生成
パフォーマンスの変化
この例では、関数 DisableImpExpinFunction と ImpExpinFunction で、サイズに互換性がある 2 つのオペランドを加算します。これらのコードは同じですが、前者では暗黙的な拡張を無効にします。DisableImpExpinFunction の生成コードには、暗黙的な拡張を適用する追加コードは含まれません。ImpExpinFunction の生成コードには、オペランドのサイズに互換性がある場合に、それらが実行時に暗黙的に拡張可能であれば実行する必要があるループが含まれます。
2 つの関数のコード生成レポートで、out の値を代入する式のサイズが異なります。
目的の関数内で coder.noImplicitExpansionInFunction を呼び出して、暗黙的な拡張なしで 2 つのオペランドの和を計算する関数 DisableImpExpinFunction を定義します。
type DisableImpExpinFunction.mfunction out = DisableImpExpinFunction(a,b) coder.noImplicitExpansionInFunction; out = a + b; end
暗黙的な拡張を有効にして 2 つのオペランドの和を計算する関数 ImpExpinFunction を定義します。
type ImpExpinFunction.mfunction out = ImpExpinFunction(a,b) out = a + b; end
これらの関数に対する固定サイズと可変サイズの入力型を定義します。
a = coder.typeof(1,[2 1]); b = coder.typeof(1,[2 inf]);
次のコマンドを使用して関数のコードを生成します。
codegen DisableImpExpinFunction -args {a,b} -config:lib -lang:c++ -report
Code generation successful: View report
codegen ImpExpinFunction.m -args {a,b} -config:lib -lang:c++ -report
Code generation successful: View report
関数の生成コードの比較
暗黙的な拡張を適用するために、オペランドを自動的に拡張する追加コードが生成コードに導入されます。次のコードは 2 つの関数の生成コードの違いを示しています。
type codegen/lib/DisableImpExpinFunction/DisableImpExpinFunction.cpp//
// Prerelease License - for engineering feedback and testing purposes
// only. Not for sale.
// File: DisableImpExpinFunction.cpp
//
// MATLAB Coder version : 26.2
// C/C++ source code generated on : 10-Jul-2026 10:18:50
//
// Include Files
#include "DisableImpExpinFunction.h"
#include "coder_array.h"
// Function Definitions
//
// Arguments : const double a[2]
// const coder::array<double, 2U> &b
// double out[2]
// Return Type : void
//
void DisableImpExpinFunction(const double a[2],
const coder::array<double, 2U> &b, double out[2])
{
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
}
//
// File trailer for DisableImpExpinFunction.cpp
//
// [EOF]
//
type codegen/lib/ImpExpinFunction/ImpExpinFunction.cpp//
// Prerelease License - for engineering feedback and testing purposes
// only. Not for sale.
// File: ImpExpinFunction.cpp
//
// MATLAB Coder version : 26.2
// C/C++ source code generated on : 10-Jul-2026 10:18:54
//
// Include Files
#include "ImpExpinFunction.h"
#include "ImpExpinFunction_data.h"
#include "ImpExpinFunction_initialize.h"
#include "coder_array.h"
#include "omp.h"
// Function Definitions
//
// Arguments : const double a[2]
// const coder::array<double, 2U> &b
// coder::array<double, 2U> &out
// Return Type : void
//
void ImpExpinFunction(const double a[2], const coder::array<double, 2U> &b,
coder::array<double, 2U> &out)
{
int i2;
int loop_ub;
if (!isInitialized_ImpExpinFunction) {
ImpExpinFunction_initialize();
}
loop_ub = b.size(1);
out.set_size(2, b.size(1));
if ((b.size(1) << 1) < 400) {
for (int i{0}; i < loop_ub; i++) {
int i1;
out[2 * i] = a[0] + b[2 * i];
i1 = 2 * i + 1;
out[i1] = a[1] + b[i1];
}
} else {
#pragma omp parallel for num_threads(omp_get_max_threads()) private(i2)
for (int i = 0; i < loop_ub; i++) {
out[2 * i] = a[0] + b[2 * i];
i2 = 2 * i + 1;
out[i2] = a[1] + b[i2];
}
}
}
//
// File trailer for ImpExpinFunction.cpp
//
// [EOF]
//
暗黙的な拡張が有効な場合、ImpExpinFunction で示されているように、オペランドのサイズを変更する追加コードが生成コードに含まれます。暗黙的な拡張が無効な場合、DisableImpExpinFunction で示されているように、オペランドにサイズ変更を適用する追加コードは生成コードに含まれていません。
コード生成レポートで出力変数のサイズを比較します。DisableImpExpinFunction の変数 out を代入する式のサイズは 2x1 です。
ImpExpinFunction の変数 out を代入する式のサイズは 2x:? です。
バージョン履歴
R2021b で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)