function y = spfun(fun,s)
%MATLAB Code Generation Library Function

%   Copyright 2016-2017 The MathWorks, Inc.
%#codegen
coder.internal.prefer_const(fun);
narginchk(2,2);
coder.internal.assert(ismatrix(s), 'MATLAB:spfun:ndInput');
coder.internal.assert(ischar(fun) || isa(fun,'function_handle'), ...
                      'Coder:toolbox:unsupportedClass', ...
                      mfilename, class(fun));
if ischar(fun)
    f = str2func(fun);
else
    f = fun;
end
if issparse(s)
    y = spfunImpl(f,s);
else
    [i,j,x] = find(s);
    [m,n] = size(s);
    y = sparse(i,j,f(x),m,n);
end
