function varargout = cross(varargin)
%CROSS  Vector cross product.
%   C = CROSS(A,B)
%   C = CROSS(A,B,DIM)
%   
%   See also CROSS, DISTRIBUTED.


%   Copyright 2019 The MathWorks, Inc.

varargout = cell(1,max(1,nargout));

if nargin>=3 && parallel.internal.array.isremote(varargin{3})
    % Gather 3rd input (DIM) if present
    varargin{3} = gather(varargin{3});
    
    % In case only DIM was remote, call in-memory version wiithout SPMD
    if ~parallel.internal.array.isremote(varargin{1}) && ...
            ~parallel.internal.array.isremote(varargin{2})
        [varargout{:}] = cross(varargin{:});
    end
end

% Flow through the standard MATLAB version on the codistributed array
[varargout{:}] = distributedutil.distributedSpmdWrapper( @cross, varargin{:} );
