function Y = createArray(dims, F)
%createArray  Create a distributed array of a specified size and class
%   X = createArray(..., distributed)
%   X = createArray(..., Like = T)
%   X = createArray(..., FillValue = F)
%   X = createArray(..., CLASSNAME, FillValue = F)
%   X = createArray(..., Like = T, FillValue = F)
%   
%   See also createArray, DISTRIBUTED.


%   Copyright 2023-2024 The MathWorks, Inc.

% Static build method.

if nargin<2
    F = 0; % Default to full real double zero
elseif ~isscalar(F)
    error(message("MATLAB:createArray:invalidFillValue"));
end
% CreateArray design is that we construct then assign.
T = distributed.empty;
T = subsasgn(T,substruct("()",{1}), F); % This will error if the conversion is not valid.

% Now that the FillValue is distributed we can just use the "like" version.
Y = distributedutil.distributedSpmdWrapper( @createArrayLike, T, dims, T );

end
