gusucode.com > bigdata 工具箱 matlab源码程序 > bigdata/@tall/mtimes.m

    function Z = mtimes(X,Y)
%*  Matrix multiply.
%   Z = X*Y
%   
%   Only one of X or Y can be a tall array. If Y is a tall array X must be
%   a scalar. If X is a tall array Y must have the same number of rows as X
%   has columns.
%
%   See also: mtimes, tall.

%   Copyright 2016 The MathWorks, Inc.

narginchk(2,2);

allowedTypes = {'numeric', 'char', 'logical', ... % 'categorical' is not supported for MTIMES
                'duration', 'calendarDuration'};
X = tall.validateType(X, mfilename, allowedTypes, 1);
Y = tall.validateType(Y, mfilename, allowedTypes, 2);

if istall(X)
    if istall(Y)
        error(message('MATLAB:bigdata:array:MtimesBothTall'));
    end
    
    % Scalar case can just go through times
    if isscalar(Y)
        Z = times(X,Y);
        Z.Adaptor = copySizeInformation(Z.Adaptor, X.Adaptor);
        return;
    end

    % Here, we know Y is not scalar. If it is a matrix, then X must also be a
    % matrix.
    if ismatrix(Y)
        % If X is a scalar, we've got a problem unless Y is size 1 in the tall dimension
        % - the slicefun will fail.
        if size(Y, 1) ~= 1
            X = lazyValidate(X, {@(x) ~isscalar(x), 'MATLAB:bigdata:array:MtimesTallXScalar'});
        end

        % Since Y isn't tall and isn't scalar, broadcast it and process slice-wise
        Yb = matlab.bigdata.internal.broadcast(Y);
        Z = slicefun(@mtimes, X, Yb);

        adaptor = multiplicationOutputAdaptor(X, Y);

        % In this case, we can perform the normal MTIMES propagation rules.
        % tall size matches X - size(Z) == [size(X,1), size(Y,2)].
        adaptor = copyTallSize(adaptor, X.Adaptor);
        Z.Adaptor = setSmallSizes(adaptor, size(Y, 2));
    else
        % Y is not a matrix, so either X is a scalar, or it's an error.
        X = lazyValidate(X, {@isscalar, 'MATLAB:mtimes:inputsMustBe2D'});
        Z = times(X,Y);
        Z.Adaptor = setKnownSize(Z.Adaptor, size(Y));
    end
else
    % For Y tall, X has to be scalar
    if isscalar(X)
        Z = times(X,Y);
        Z.Adaptor = copySizeInformation(Z.Adaptor, Y.Adaptor);
        return;
    end
    
    % Can't multiply non-scalar X by tall Y
    error(message('MATLAB:bigdata:array:MtimesXNotScalar'));
end

end