function y = ifft(x,varargin)
%MATLAB Code Generation Library Function.

%   Limitations:
%     The 'symmetric' option is not supported.

%   Copyright 2002-2023 The MathWorks, Inc.
%#codegen

narginchk(1,4);
coder.internal.prefer_const(varargin);
coder.internal.allowHalfInputs;

% Input must be a non-sparse numeric or logical array/scalar
coder.internal.assert((coder.internal.isBuiltInNumeric(x) || islogical(x) || ...
    isa(x,'half')) && ~issparse(x) && ~isa(x, 'int64') && ~isa(x, 'uint64'), ...
    'Coder:toolbox:unsupportedClass','eml_fft',class(x));

% We convert non float types (like ints and logicals) to doubles
if(~isfloat(x))
    y = ifft(double(x),varargin{:});
    return;
end

% The symflag may only be nonsymmetric for code generation
if nargin >= 2 && coder.internal.isCharOrScalarString(varargin{nargin - 1})
   
    matchParam = @coder.internal.matchStringParameter;
    isSymmetric = matchParam(varargin{nargin-1},'symmetric');
    isNonSymmetric = matchParam(varargin{nargin-1},'nonsymmetric');
    coder.internal.assert(isSymmetric || isNonSymmetric,...
         'MATLAB:fftfcn:InvalidTrailingStringArgument','IfNotConst','Fail');  
    % % Indicates the number of arguments excluding the 'symFlag' arg
    nonFlagArgs = nargin - 1;
else
    isSymmetric = false;
    nonFlagArgs = nargin;
end

if nonFlagArgs == 3
    dim = varargin{2};

    % The dimension must be constant and valid
    coder.internal.assert(coder.internal.isConst(dim), ...
                          'Coder:toolbox:eml_fft_4', ...
                          'IfNotConst','Fail');
    coder.internal.assertValidDim(dim);

    dim = coder.internal.indexInt(dim);
else
    % Choose dim to be first variable or non-singleton-fixed dimension
    dim = coder.internal.indexInt(coder.internal.constNonSingletonDim(x));

    % Require that if dim has variable size, it has non-unit length
    % at runtime (unless it is a scalar and dim is 2)
    coder.internal.assert(coder.internal.isConst(size(x, dim)) || ...
                          (isscalar(x) && dim == 2) || ...
                          size(x,dim) ~= 1, ...
                          'Coder:toolbox:autoDimIncompatibility');
end

if nonFlagArgs >= 2
    lens = varargin{1};
    if ~isempty(lens)

        % Require that input length is nonnegative integer and not > intmax(int32)
        % if it is nonempty
        coder.internal.assert(isscalar(lens) && isreal(lens) && ...
                              coder.internal.isBuiltInNumeric(lens) && ...
                              lens(1) >= 0 && lens(1) == floor(lens(1)), ...
                              'MATLAB:fftfcn:lengthNotNonNegInt');
        coder.internal.assert(lens(1) <= intmax(coder.internal.indexIntClass), ...
                              'MATLAB:pmaxsize');
        lens = coder.internal.indexInt(lens);
    else
        % An empty input behaves as though there is no input at all
        lens = coder.internal.indexInt(size(x, dim));
    end
else
    lens = coder.internal.indexInt(size(x, dim));
end
lens = lens(1);
y = coder.internal.fft.fft(x, lens, dim, true,isSymmetric);

% LocalWords:  symflag nonsymmetric fftfcn pmaxsize
