function obj = permuteExplicitly(obj)
%PERMUTEEXPLICITLY Return equivalent dlarray without internal permutation

%   Copyright 2019-2020 The MathWorks, Inc.

if isempty(obj.ViewToDataMap)
    % No implicit permutation on input, direct return.
    return
end

perm = obj.ViewToDataMap;
if ~isequal(perm, 1:numel(perm))
    % Only apply a permutation if it is needed
    % Extract data as is
    [fdobj, objdata] = extractData(obj.FormattedData);
    
    % Apply view permutation
    objdata = permute(objdata, perm);
    
    % Apply permutation to dimension labels
    if hasFormat(obj)
        fdobj.DimensionMetadata = fdobj.DimensionMetadata(perm);
    end
    
    obj.FormattedData = insertData(fdobj, objdata);
end

% Remove all information related to permutation
obj.ViewToDataMap = [];
obj.DataToViewMap = [];
end