現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
The value returned from getNumInputsImpl method must be a constant value. But the Value is immutable
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
i get the following error when generating code:
The value returned from getNumInputsImpl method must be a constant value.
Properties used in calculating this value must be Nontunable.
The error occurred for MATLAB System block 'SiL_LUT_1D/MATLAB System1'.
The method:
function num = getNumInputsImpl(obj)
num = obj.Approx.numInputs + 1; % input
end
The propertie numInputs of Approx(ValueClass):
properties (SetAccess = immutable)
numInputs = 0;
end
And obj.Approx is a nontunable Property of the System block. So for my understanding, this value can't change in anyway and should be interpreted as a constant value. Any suggestion on a fix or workaround?
1 件のコメント
Thomas Kucharczyk
2020 年 2 月 26 日
回答 (2 件)
Thomas Kucharczyk
2020 年 2 月 26 日
function num = getNumInputsImpl(obj)
if obj.numInputs ~= obj.Approx.numInputs + 1
obj.numInputs = obj.Approx.numInputs + 1;
end
num = obj.numInputs; % input
end
The above approach with the Nontunable Property "numInputs" will give following error during code generation:
### Starting build procedure for model: SiL_LUT_1D
### Generating code and artifacts to 'Model specific' folder structure
Code Generation 1
Elapsed: 1 sec
### Generating code into build folder: D:\masterarbeit\git\ols-library\Experiment\build\SiL_LUT_1D_ert_rtw
CGIR assertion 'T::isa((const Type*)aType)' failed in 'b:\matlab\src\cg_ir\export\include\cg_ir\type\type.hpp:528'
[ 0] 0x000000055fdc6e8d bin\win64\eml.dll+01011341 EML::COV::registerCoverageListener+00401597
[ 1] 0x000000056015c191 bin\win64\eml.dll+04768145 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00574545
[ 2] 0x00000005601643cd bin\win64\eml.dll+04801485 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00607885
[ 3] 0x00000005601721cd bin\win64\eml.dll+04858317 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00664717
[ 4] 0x000000056006731f bin\win64\eml.dll+03765023 EML::NameCapture::verify+00736239
[ 5] 0x00000005600648ea bin\win64\eml.dll+03754218 EML::NameCapture::verify+00725434
[ 6] 0x0000000560065258 bin\win64\eml.dll+03756632 EML::NameCapture::verify+00727848
[ 7] 0x00000005601b1db4 bin\win64\eml.dll+05119412 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00925812
[ 8] 0x00000005601239a9 bin\win64\eml.dll+04536745 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00343145
[ 9] 0x0000000560130bdd bin\win64\eml.dll+04590557 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00396957
[ 10] 0x0000000560054986 bin\win64\eml.dll+03688838 EML::NameCapture::verify+00660054
[ 11] 0x000000056004e94f bin\win64\eml.dll+03664207 EML::NameCapture::verify+00635423
[ 12] 0x000000056004ed91 bin\win64\eml.dll+03665297 EML::NameCapture::verify+00636513
[ 13] 0x000000056008e194 bin\win64\eml.dll+03924372 EML::NameCapture::verify+00895588
[ 14] 0x00000005601239a9 bin\win64\eml.dll+04536745 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00343145
[ 15] 0x0000000560130bdd bin\win64\eml.dll+04590557 CG::GenericTagCategory<EML::DesignRangeTag,0>::unregisterCategory+00396957
### Build procedure for model: 'SiL_LUT_1D' aborted due to an error.
Unexpected or internal error encountered in "in CGIR: b:\matlab\src\cg_ir\export\include\cg_ir\type\type.hpp line 528: T::isa((const Type*)aType)
". Please report this to MathWorks if you can cause it to recur
Component:Simulink | Category:Block diagram error
Honglei Chen
2020 年 2 月 26 日
You said numInputs is nontunable, did you try to use Nontunable in the property defintion? Like
properties (Nontunable)
numInputs = 0
end
HTH
13 件のコメント
Thomas Kucharczyk
2020 年 2 月 27 日
編集済み: Thomas Kucharczyk
2020 年 2 月 27 日
"Properties may not be set in this method (it should leave the System object unchanged)."
Today i get the above error, yesterday i got a build error.
Thomas Kucharczyk
2020 年 2 月 27 日
So, where can i change a property, i.e. obj.numInputs, when another property changes? Event handler won't work here too:
Code generation does not support function handles pointing to non-static methods.
methods
% constructor
function obj = OLSEvaluator(varargin)
setProperties(obj,nargin,varargin{:});
% EventObject, Property name, Event, static function handle
addlistener(obj,'Approx','PostSet', @obj.handlePropEvents);
end
function handlePropEvents(obj, src, evnt)
% return if not Approx property
if strcmp(src.Name, 'Approx') == false
return;
end
% return if not PostSet event
if strcmp(evnt.EventName, 'PostSet') == false
return;
end
% return if not a Approximator class
if isa(obj.Approx, 'Approximator') == false
return;
end
% add additional input for lambda (x_0 .. x_n, lambda)
obj.numInputs = obj.Approx.numInputs + 1;
end
end
Honglei Chen
2020 年 2 月 27 日
If it's numInputs is nontunable, then you cannot change it once the simulation starts. You can probably update it once in setupImpl.
Thomas Kucharczyk
2020 年 2 月 27 日
setupImpls doesn't get called when updating the diagramm or making a change in the System block dialog. So it's not possible to change obj.numInputs to adjust the number of inputs. Therefore it's not possible to connect signals to the System block.
Honglei Chen
2020 年 2 月 27 日
I was trying to explain for a nontunable property, you are not supposed to change it in your method. It looks like you are using a property, Approx, to control whether a port should be rendered? If so, I'd suggest you to define Approx as a nontunable property and use that one to return the number of inputs. You probably don't need an extra numInputs property.
HTH
Thomas Kucharczyk
2020 年 2 月 27 日
編集済み: Thomas Kucharczyk
2020 年 2 月 27 日
The property Approx (obj.Approx) is already defined as a Nontunable property. This property gets a value class assigned with the property numInputs, which is set to immutable. But this approch gives the error from the initial question. My guess is, that this shouldn't happen, since you can't change any property of obj.Approx as it is a Nontunable property.
% Approx definition in the matlab system block
properties (Nontunable)
Approx = [];
end
% Approx will be set to a value class of following definition:
classdef Approximator
% Public, immutable properties
properties (SetAccess = immutable)
numInputs = 0;
dimension;
end
Honglei Chen
2020 年 2 月 27 日
I see. You should be able to change Approx as long as the simulation has not started. I don't know the logic behind it but you shouldn't need to use listeners to control number of inputs. You can reference Approximator's properties in getNumInputsImpl too.
HTH
Thomas Kucharczyk
2020 年 2 月 27 日
編集済み: Thomas Kucharczyk
2020 年 2 月 27 日
I have already used the property of Approximator to set the number of inputs. But code generation will fail using this approach. Please keep in mind, that this is only a problem for code generation, interpreted execution works fine.
Thomas Kucharczyk
2020 年 2 月 27 日
Since Approx is a Nontunable property my suggestion is, that the code generator fails to descent into the Approx properties and mind the Nontunable attribute of Approx. This is a bug imho.
Honglei Chen
2020 年 2 月 28 日
Hi Thomas, sorry I cannot help more without seeing the entire code. If you are willing to provide the complete code, I'd be happy to pass it to the corresponding team to investigate. Alternatively, you can contact the tech support to report the bug too.
Thomas Kucharczyk
2020 年 3 月 2 日
Comment out following lines in exampleClass.m and the model will fork fine:
obj.phi = cell(1, numInputs);
for i = 1:numInputs
obj.phi{i} = zeros(1, 10);
end
Don't forget to create the value class:
exampleObject = exampleClass(4);
Thomas Kucharczyk
2020 年 3 月 6 日
"Code generation does not support assigning an object of a value class into a nontunable property. For example, obj.prop=v; is invalid when prop is a nontunable property and v is an object based on a value class." from MATLAB Classes Definition for Code Generation
This approach shouldn't even start code generation. Maybe there is a check missing for value classes which are set to a property?
Honglei Chen
2020 年 3 月 6 日
Good suggestion, I'll create an enhancement request for the team, thanks.
参考
カテゴリ
Help Center および File Exchange で HDL Code Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)