function obj = prod(obj, varargin)
%PROD Product of elements.
%   Y = PROD(X)
%   Y = PROD(X,DIM)
%   Y = PROD(X,VECDIM)
%   Y = PROD(X,'all')
%   Y = PROD(...,'double')
%   Y = PROD(...,'native')
%   Y = PROD(...,'default')
%   Y = PROD(...,'includenan')
%   
%   The output Y has the same dimension labels, if any, as the input X.
%   
%   The order of the products within the PROD operation can change based on
%   the internal storage order of the dlarray. This can result in
%   differences on the order of round-off for two dlarrays that are
%   otherwise equal.
%
%   See also PROD, DLARRAY, GPUARRAY/PROD.

%   Copyright 2019-2023 The MathWorks, Inc.

if nargin > 1 && ~isa(obj, 'dlarray')
    varargin = extractDlarrayCell(varargin);
    obj = prod(obj, varargin{:});
    return;
end

[obj, fdx, xdata, args] = helperReduction(obj, 'prod', varargin{:});
mustBeNonEmptyDim(args);
omitnanUnsupported(args);

xdata = prod(xdata, args{:});

obj.FormattedData = insertData(fdx, xdata);
obj = dropTrailingODims(obj);
end
