function analyzeNetwork(varargin)
% analyzeNetwork    Analyze deep learning networks.
%
% The network analyzer displays a visualization of the network
% architecture, detects issues with the network, and provides information
% about the network layers. The layer information includes the sizes of
% layer activations and learnable parameters, the total number of learnable
% parameters, and the sizes of state parameters for RNN layers.
%
%   ANALYZENETWORK(net) analyzes the network architecture in the specified
%   series or DAG network.
%
%   ANALYZENETWORK(dlnet) analyzes the network architecture of a dlnetwork
%   object for use in a custom training loop.
%
%   ANALYZENETWORK(layers) analyzes the network architecture of the
%   specified layer array or layer graph for usage in the trainNetwork
%   function.
%
%   ANALYZENETWORK(lgraph,'TargetUsage',target) analyzes the network
%   architecture in the specified layer graph for the specified target
%   usage:
%
%      'trainNetwork'  - Analyze network for trainNetwork usage.
%      'dlnetwork'     - Analyze network for dlnetwork usage.
%
% Example:
%   net = googlenet;
%   analyzeNetwork(net);
%
% See also TRAINNETWORK, DLNETWORK, LAYERGRAPH

%   Copyright 2017-2020 The MathWorks, Inc.

% Error if current platform is not supported.
try
    deepapp.internal.common.support.errorIfPlatformNotSupported("Network Analyzer");
catch exception
    throw(exception);
end

narginchk(1, Inf);

try
    [layersOrNet,isFunctionalMode] = iParseInput(varargin{:});
    
    internalAnalyzeNetwork = deepapp.internal.analyzer.report.AnalyzeNetwork();
    internalAnalyzeNetwork.doAnalysis(layersOrNet, inputname(1), isFunctionalMode);
catch e
    throw(e);
end

end

function [layersOrNet,isFunctionalMode] = iParseInput(varargin)
parser = deepapp.internal.analyzer.input.InputParser();
[layersOrNet,isFunctionalMode] = parser.parse(varargin{:});
end