function s = metricsToCoderStruct(s,metricsStruct,metricsFun)
%METRICSTOCODERSTRUCT - return a struct with code generation compatible metrics information

% Copyright 2020-2021 The MathWorks, Inc.

s.Metrics = metricsStruct;
metricsnames = fieldnames(s.Metrics);
for ii = 1:numel(metricsnames)
    fields = fieldnames(s.Metrics.(metricsnames{ii}));
    for jj = 1:numel(fields)
        if isnan(s.Metrics.(metricsnames{ii}).(fields{jj}))
            s.Metrics.(metricsnames{ii}).(fields{jj}) = cast(-1,'like',s.Metrics.(metricsnames{ii}).(fields{jj}));
        end
    end
end
    
g  = @(x) func2str(x);
f = @(x) contains(x,'classreg.learning.loss.unnormalized');
builtInMetrics = cellfun(@(x)f(g(x)), metricsFun);
s.BuiltInMetrics = builtInMetrics;
s.MetricsFun = {};
s.MetricsFunFull = {};
for ii = 1:numel(s.BuiltInMetrics)
    if ~s.BuiltInMetrics(ii)
        fh = functions(metricsFun{ii});
        if ~(strcmpi(fh.type,'simple') || strcmpi(fh.type,'classsimple')) 
            error(message('stats:incremental:coder:Learner:NonSimpleFunctionsNotSupported','Metrics'));
        end
        s.MetricsFunFull{end+1} = func2str(metricsFun{ii});
    else
        s.MetricsFun{end+1} = incremental.coderutils.Loss.(metricsnames{ii});
    end
end
end
