function dZ = internal_crosschannelnormBackward(dZ, X, ~, windowSize, alpha, beta, k)
% internal_crosschannelnormBackward   Cross-channel normalization backpropagation
%
%   Inputs: 
%   dZ         - The derivative of the loss function with respect to the
%                output of the normalization layer in form of a
%                (S)x(S)x(C)x(B) numeric array.
%   X          - The input feature maps in form of a (S)x(S)x(C)x(B)
%                numeric array.
%   windowSize - The number of maps to use for the normalization of each
%                element.
%   alpha      - Multiplier for the normalization term.
%   beta       - Exponent for the normalization term.
%   k          - Offset for the normalization term.
%
%   Output:
%   dX         - The derivative of the loss function with respect to the
%                input of the normalization layer in form of a
%                (S)x(S)x(C)x(B) numeric array.

%   Copyright 2019-2021 The MathWorks, Inc.

if ~isreal(dZ)
    error(message('deep:dlarray:ComplexGradientOutput', 'crosschannelnorm'));
end

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

dZ = builtin('_xchannelnorm', X, windowSize, alpha, beta, k, dZ);

end
