function dZ = internal_geluBackward(dZ, X, approx)
% This function is undocumented and will change in a future release.

%   Copyright 2022 The MathWorks, Inc.

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

switch approx
    case "none"
        dZ = nnet.internal.cnnhost.geluBackward(X, dZ, X);
    case "tanh"
        dZ = nnet.internal.cnnhost.geluBackwardTanhApproximation(X, dZ, X);
end
end