function lgraph = layerGraph(this)
%layerGraph   Convert DAGNetwork to layer graph
%
%   lgraph = layerGraph(net) extracts the layer graph from the DAGNetwork net.

%   Copyright 2021-2022 The MathWorks, Inc.

arguments
    this(1,1)
end

internalLayerGraph = this.getLayerGraph();
layerMap = this.getLayerMap();

lgraph = iInternalToExternalLayerGraph(internalLayerGraph, layerMap);
end

function externalLayerGraph = iInternalToExternalLayerGraph( internalLayerGraph, layersMap )
% Strip the QuantizationInfo from the layers so that the
% quantization information is not carried into different
% network constructions.
internalLayers = nnet.internal.cnn.layer.util.resetQuantizationInfo(internalLayerGraph.Layers);
externalLayers = iExternalLayers(internalLayers, layersMap);
externalLayerGraph = nnet.cnn.LayerGraph.createFromLayersAndInternalConnections(externalLayers, internalLayerGraph.Connections);
end

function externalLayers = iExternalLayers(internalLayers, layersMap)
externalLayers = layersMap.externalLayers( internalLayers );
end
