function layer = leakyReluLayer(scale, NameValueArgs)
% leakyReluLayer   Leaky rectified linear unit (ReLU) layer
%
%   layer = leakyReluLayer(scale) creates a leaky rectified linear unit
%   layer. This type of layer performs a simple threshold operation,
%   where any input value less than zero is multiplied by a scalar
%   multiple. This is equivalent to:
%     out = in;        % For in>0
%     out = scale.*in; % For in<=0
%
%   layer = leakyReluLayer() uses a default scale of 0.01.
%
%   layer = leakyReluLayer(scale, 'PARAM1', VAL1) specifies optional
%   parameter name/value pairs for creating the layer:
%       'Name'  - A name for the layer. The default is ''.
%
%   Example:
%       % Create a rectified linear unit layer.
%
%       layer = leakyReluLayer(0.1);
%
%   See also reluLayer, clippedReluLayer, nnet.cnn.layer.LeakyReLULayer.
%
%   <a href="matlab:helpview('deeplearning','list_of_layers')">List of Deep Learning Layers</a>

%   Copyright 2017-2023 The MathWorks, Inc.

arguments
    scale(1,1) { mustBeNumeric, mustBeFinite } = 0.01
    NameValueArgs.Name { nnet.internal.cnn.layer.paramvalidation.validateLayerName } = ''
end
scale = iConvertToDouble(nnet.internal.cnn.layer.util.gatherParametersToCPU(scale));

% Create an internal representation of a ReLU layer.
internalLayer = nnet.internal.cnn.layer.LeakyReLU(convertStringsToChars(NameValueArgs.Name), scale);

% Pass the internal layer to a function to construct a user visible LeakyReLU
% layer.
layer = nnet.cnn.layer.LeakyReLULayer(internalLayer);

end

function value = iConvertToDouble(value)
value = nnet.internal.cnn.layer.util.convertToDouble(value);
end
