function layer = geluLayer( nameValueArgs )
% geluLayer   Gaussian error linear unit (GELU) layer
%
%   layer = geluLayer creates a GELU layer that weights the input values
%   using the standard Gaussian cumulative distribution function
%
%   layer = geluLayer('PARAM1', VAL1) specifies optional parameter
%   name/value pairs for creating the layer:
%
%       'Name'            - A name for the layer. The default is ''.
%       'Approximation'   - Approximation method for the GELU operation,
%                           specified as one of the following:
%                           'none' - Do not use approximation.
%                           'tanh' - Use tanh approximation.
%                            The default value is 'none'.
%
%   Example:
%       % Create a GELU layer.
%
%       layer = geluLayer;
%
%   See also reluLayer, leakyReluLayer, nnet.cnn.layer.GELULayer.
%
%   <a href="matlab:helpview('deeplearning','list_of_layers')">List of Deep Learning Layers</a>

%   Copyright 2022 The MathWorks, Inc.

arguments
    nameValueArgs.Name {iAssertValidLayerName} = '';
    nameValueArgs.Approximation {iAssertValidApproximation} = 'none';
end
nameValueArgs.Name = convertStringsToChars(nameValueArgs.Name);
nameValueArgs.Approximation = convertStringsToChars(nameValueArgs.Approximation);

% Create an internal representation of a GELU layer.
internalLayer = nnet.internal.cnn.layer.GELU(nameValueArgs.Name, nameValueArgs.Approximation);

% Pass the internal layer to a function to construct a user visible
% GELU layer.
layer = nnet.cnn.layer.GELULayer(internalLayer);
end

function iAssertValidLayerName(name)
nnet.internal.cnn.layer.paramvalidation.validateLayerName(name);
end

function iAssertValidApproximation(approx)
supportedValues=["none", "tanh"];
validatestring(approx, supportedValues, 'geluLayer', 'value');
end
