function [n, m] = size(x, dim)

  sz = [nan inf];

  if (nargin == 2) && (nargout == 2)
    error('size: invalid call')
  elseif (nargout == 2)
    n = sz(1);
    m = sz(2);
  elseif (nargin == 2)
    n = sz(dim);
  else
    n = sz;
  end

end
