function x = mrdivide(x, y)
%/   Slash or right matrix divide.
%   C = A / B
%   C = MRDIVIDE(A,B)
%   
%   A/B is only supported if B is a scalar. C has the same dimension
%   labels as A.
%   
%   See also MRDIVIDE, RDIVIDE, DLARRAY.

%   Copyright 2019-2022 The MathWorks, Inc.

if ~isscalar(y)
    error(message('deep:mrdivide:DivideByNonScalar'));
end

if iIsDLArray(x)
    [fdx, xdata] = extractData(x.FormattedData);
else
    deep.internal.dlarray.validateNonDlarray(x);
    xdata = x;
end

if iIsDLArray(y)
    [fdy, ydata] = extractData(y.FormattedData);
else
    deep.internal.dlarray.validateNonDlarray(y);
    ydata = y;
end

xdata = xdata ./ ydata;

if iIsDLArray(x)
    x.FormattedData = insertData(fdx, xdata);
else
    fdy.DimensionMetadata = '';
    y.FormattedData = insertData(fdy, xdata);
    
    % Just in case the scalar y had a permutation vector:
    y.ViewToDataMap = [];
    x = y;
end
end

function ret = iIsDLArray(X)
ret = isa(X, 'dlarray');
end
