function y = speye(m,n)
%MATLAB Code Generation Library Function

%   Copyright 2016-2017 The MathWorks, Inc.
%#codegen
narginchk(0,2);
switch nargin
  case 0
    ndiag = coder.internal.indexInt(1);
    meye = ndiag;
    neye = ndiag;
  case 1
    coder.internal.prefer_const(m);
    coder.internal.assert(numel(m) == 1 || numel(m) == 2, ...
                          'MATLAB:speye:InvalidInputFormat');
    if numel(m) == 1
        ndiag = coder.internal.checkAndSaturateExpandSize(m);
        meye = ndiag;
        neye = ndiag;
    else
        meye = coder.internal.checkAndSaturateExpandSize(m(1));
        neye = coder.internal.checkAndSaturateExpandSize(m(2));
        ndiag = eml_min(meye,neye);
    end
  case 2
    coder.internal.prefer_const(m,n);
    coder.internal.assert(isscalar(m) && isscalar(n), ...
                          'MATLAB:speye:InvalidInputFormat');
    meye = coder.internal.checkAndSaturateExpandSize(m(1));
    neye = coder.internal.checkAndSaturateExpandSize(n(1));
    ndiag = eml_min(meye,neye);
end
y = coder.internal.sparse.eyeLike(ndiag,meye,neye,1);
