function mtimesTransposeOp = buildMtimesTransposeOp(transA, transB)
%buildMtimesTransposeOp returns a function handle to apply mtimes

%   It is important to write these explicitly in order to benefit from the
%   in-memory fused operators, where none of the operand(s) is explicitly
%   transposed.

%   Copyright 2020 The MathWorks, Inc.

import distributedutil.TransposeFlags

mtimesTransposeOp = @(A,B) NaN;
if transA == TransposeFlags.NO_TRANSPOSE && ...
        transB == TransposeFlags.NO_TRANSPOSE
    mtimesTransposeOp = @(A,B) A*B;
elseif transA == TransposeFlags.NO_TRANSPOSE && ...
        transB == TransposeFlags.TRANSPOSE
    mtimesTransposeOp = @(A,B) A*B.';
elseif transA == TransposeFlags.NO_TRANSPOSE && ...
        transB == TransposeFlags.CONJUGATE_TRANSPOSE
    mtimesTransposeOp = @(A,B) A*B';
elseif transA == TransposeFlags.TRANSPOSE && ...
        transB == TransposeFlags.NO_TRANSPOSE
    mtimesTransposeOp = @(A,B) A.'*B;
elseif transA == TransposeFlags.TRANSPOSE && ...
        transB == TransposeFlags.TRANSPOSE
    mtimesTransposeOp = @(A,B) A.'*B.';
elseif transA == TransposeFlags.TRANSPOSE && ...
        transB == TransposeFlags.CONJUGATE_TRANSPOSE
    mtimesTransposeOp = @(A,B) A.'*B';
elseif transA == TransposeFlags.CONJUGATE_TRANSPOSE && ...
        transB == TransposeFlags.NO_TRANSPOSE
    mtimesTransposeOp = @(A,B) A'*B;
elseif transA == TransposeFlags.CONJUGATE_TRANSPOSE && ...
        transB == TransposeFlags.TRANSPOSE
    mtimesTransposeOp = @(A,B) A'*B.';
elseif transA == TransposeFlags.CONJUGATE_TRANSPOSE && ...
        transB == TransposeFlags.CONJUGATE_TRANSPOSE
    mtimesTransposeOp = @(A,B) A'*B';
end
end
