Codegen failed to infer output size of built-in function, ??? Dimension 1 is fixed on the left-hand side but varies on the right ([1 x :?] ~= [:? x :?])
2 views (last 30 days)
Show older comments
I tried to codegen a large file containing downsample(), below is a simplified one. For some reason, I have to specify the output size. However, coder failed to infer the size of output of dowmsample().
function a = zzz_tmp0329_33(n)%#codegen
coder.varsize('a', [1 Inf], [0 1] );
b = [1,2,3,4];
a = downsample(b, n);
end
Below is the script to run codegen
% ZZZ_TMP0329_33_SCRIPT Generate static library zzz_tmp0329_33 from
% zzz_tmp0329_33.
%
% Script generated from project 'zzz_tmp0329_33.prj' on 14-Sep-2022.
%
% See also CODER, CODER.CONFIG, CODER.TYPEOF, CODEGEN.
%% Create configuration object of class 'coder.CodeConfig'.
cfg = coder.config('lib','ecoder',false);
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.GenCodeOnly = true;
%% Define argument types for entry-point 'zzz_tmp0329_33'.
ARGS = cell(1,1);
ARGS{1} = cell(1,1);
ARGS{1}{1} = coder.typeof(0);
%% Invoke MATLAB Coder.
codegen -config cfg zzz_tmp0329_33 -args ARGS{1}
The error says ??? Dimension 1 is fixed on the left-hand side but varies on the right ([1 x :?] ~= [:? x :?]). Why would it say downsample a vector leads to size [:? x :?] ?
Do you know why coder cannot determine the size of output from downsample()?
0 Comments
Answers (1)
David Fink
on 14 Sep 2022
Thank you for reporting this!
There have been some changes to downsample - try a recent version of MATLAB - R2021b or newer, where this is fixed.
2 Comments
David Fink
on 15 Sep 2022
In R2020a, you could reshape the output of downsample to the expected 1x?:
a = reshape(downsample(b, n), 1, []);
which (similar to upgrading to R2021b or newer) would allow you to remove the coder.varsize declaration.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!