function layer = tanhLayer(varargin)
% tanhLayer   Hyperbolic tangent (tanh) layer
%
%   layer = tanhLayer() creates a hyperbolic tangent layer. This type of
%   layer passes its input through the tanh function, which maps large 
%   positive values to +1 and large negative values to -1.
%
%   layer = tanhLayer('Name', name) additionally specifies the layer name.
%
%   Example:
%       % Create a hyperbolic tangent layer.
%
%       layer = tanhLayer();
%
%   See also tanh, reluLayer, convolution2dLayer, fullyConnectedLayer.
%
%   <a href="matlab:helpview('deeplearning','list_of_layers')">List of Deep Learning Layers</a>

%   Copyright 2018 The MathWorks, Inc.

% Parse the input arguments.
inputArguments = iParseInputArguments(varargin{:});

layer = nnet.cnn.layer.TanhLayer(inputArguments.Name);

end

function inputArguments = iParseInputArguments(varargin)
parser = iCreateParser();
parser.parse(varargin{:});
inputArguments = iConvertToCanonicalForm(parser);
end

function p = iCreateParser()
p = inputParser;
defaultName = '';
addParameter(p, 'Name', defaultName, @iAssertValidLayerName);
end

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

function inputArguments = iConvertToCanonicalForm(p)
inputArguments = struct;
inputArguments.Name = char(p.Results.Name); % make sure strings get converted to char vectors
end
