codegen error: The left-hand side has been constrained to be non-complex, but the right-hand side is complex
codegen error: The left-hand side has been constrained to be non-complex, but the right-hand side is complex
我是 matlab 的新手,正在尝试将遗留的 matlab 代码编译成 C。这样做时遇到以下错误:
??? The left-hand side has been constrained to be non-complex, but the
right-hand side is complex. To correct this problem, make the
right-hand side real using the function REAL, or change the initial
assignment to the left-hand side variable to be a complex value using
the COMPLEX function.
它抱怨的代码在下面代码的注释中:
function [z_out,ovf_flag,ovf_cnt] = fxpt_sgn_saturate(z_in,Nb_out)
Nb_out=(Nb_out<=0)+(Nb_out>0)*Nb_out;
max_val = 2^(Nb_out-1)-1;
min_val = -2^(Nb_out-1);
ovf_cnt = 0;
tmp_ind = find(real(z_in) > max_val);
z_in(tmp_ind) = max_val+1j*imag(z_in(tmp_ind)); // ERROR OCCURS HERE
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(real(z_in) < min_val);
z_in(tmp_ind) = min_val+1j*imag(z_in(tmp_ind));
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(imag(z_in) > max_val);
z_in(tmp_ind) = real(z_in(tmp_ind))+1j*max_val;
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(imag(z_in) < min_val);
z_in(tmp_ind) = real(z_in(tmp_ind))+1j*min_val;
ovf_cnt = ovf_cnt + numel(tmp_ind);
z_out = z_in;
ovf_flag = ~(ovf_cnt==0);
return
我不是特别了解代码。有解决此问题的想法吗?
谢谢
生成代码时,您可以使用 -args
flag 指定输入参数的大小、class 和复杂性。您可以将 z_in
显式转换为复数,以确保代码生成成功。
codegen fxpt_sgn_saturate -args {complex(z_in), double(Nb_out)}
或者,如果您从许多其他函数中调用此函数并且仅在顶层函数上调用 codegen
,那么您需要将输入显式转换为复杂数据类型在调用函数之前编写代码,以便 codegen
可以适当地确定输入的复杂性。
function a(thing)
fxpt_sgn_saturate(complex(thing), 10);
end
我是 matlab 的新手,正在尝试将遗留的 matlab 代码编译成 C。这样做时遇到以下错误:
??? The left-hand side has been constrained to be non-complex, but the right-hand side is complex. To correct this problem, make the right-hand side real using the function REAL, or change the initial assignment to the left-hand side variable to be a complex value using the COMPLEX function.
它抱怨的代码在下面代码的注释中:
function [z_out,ovf_flag,ovf_cnt] = fxpt_sgn_saturate(z_in,Nb_out)
Nb_out=(Nb_out<=0)+(Nb_out>0)*Nb_out;
max_val = 2^(Nb_out-1)-1;
min_val = -2^(Nb_out-1);
ovf_cnt = 0;
tmp_ind = find(real(z_in) > max_val);
z_in(tmp_ind) = max_val+1j*imag(z_in(tmp_ind)); // ERROR OCCURS HERE
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(real(z_in) < min_val);
z_in(tmp_ind) = min_val+1j*imag(z_in(tmp_ind));
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(imag(z_in) > max_val);
z_in(tmp_ind) = real(z_in(tmp_ind))+1j*max_val;
ovf_cnt = ovf_cnt + numel(tmp_ind);
tmp_ind = find(imag(z_in) < min_val);
z_in(tmp_ind) = real(z_in(tmp_ind))+1j*min_val;
ovf_cnt = ovf_cnt + numel(tmp_ind);
z_out = z_in;
ovf_flag = ~(ovf_cnt==0);
return
我不是特别了解代码。有解决此问题的想法吗?
谢谢
生成代码时,您可以使用 -args
flag 指定输入参数的大小、class 和复杂性。您可以将 z_in
显式转换为复数,以确保代码生成成功。
codegen fxpt_sgn_saturate -args {complex(z_in), double(Nb_out)}
或者,如果您从许多其他函数中调用此函数并且仅在顶层函数上调用 codegen
,那么您需要将输入显式转换为复杂数据类型在调用函数之前编写代码,以便 codegen
可以适当地确定输入的复杂性。
function a(thing)
fxpt_sgn_saturate(complex(thing), 10);
end