function Z = internal_maxunpool(X, indices, outputSize)
%internal_maxunpool Internal method of dlarray/maxunpool
%
% Z = internal_maxunpool(X, INDICES, OUTPUTSIZE) returns an array of zeros
% of size OUTPUTSIZE filled with the elements of X in the positions given
% by INDICES. OUTPUTSIZE must be a valid MATLAB size vector.

%   Copyright 2019-2021 The MathWorks, Inc.

if ~isreal(X)
    error(message('deep:dlarray:ComplexNotSupported'))
end

% Allocate output
Z = zeros(outputSize, 'like', X);
% Unpool
Z(indices) = X;

end
