function dZ = internal_avgpoolBackward(dZ, X, Z, poolSize, padSize, strideSize, includePadding)
% This function is undocumented and will change in a future release.

%   Copyright 2019-2020 The MathWorks, Inc.

% Ensure all inputs have the same data type
[dZ, X] = nnet.internal.cnnhost.castToSuperiorFloat(dZ, X);

% Reshape padding as [top1 top2 ... topn bot1 bot2 ... botn] to match the CPU builtin
padStart = padSize(1:2:end);
padEnd = padSize(2:2:end);

dZ = nnet.internal.cnnhost.poolingAverageBackwardND(Z, dZ, X, poolSize, padStart, padEnd, strideSize, includePadding);

end
