function C = kronecker (arg1, arg2, arg3, arg4, arg5, arg6, arg7)
%GRB.KRONECKER sparse Kronecker product.
%
% syntax for a new matrix C:                        computation:
% C = GrB.kronecker (op, A, B, desc)                % C = op(A,B)
% C = GrB.kronecker (Cin, accum, op, A, B, desc)    % C = Cin + op(A,B)
% C = GrB.kronecker (Cin, M, op, A, B, desc)        % C = Cin ; C<M> = op(A,B)
% C = GrB.kronecker (Cin, M, accum, op, A, B, desc) % C = Cin ; C<M> += op(A,B)
%
% GrB.kronecker computes the Kronecker product T=kron(A,B), using any binary op
% (shown as op(A,B) in the computations listed above).
%
% T is then accumulated into C via C<M> = accum (C,T), where the accum step is
% computed using GrB.eadd and M can be modified by the descriptor desc.
%
% accum: a binary operator to accumulate the results; in the computations
% listed above it is shown as "+=" but any binary operator may be used.
%
% Cin, the mask matrix M, the accum operator, and desc are optional.  If either
% accum or M is present, then C or Cin is a required input.  If desc.in0 is
% 'transpose' then A is transposed before applying the operator.  If desc.in1
% is 'transpose', then the input matrix B is transposed before applying the
% operator. See 'help GrB.descriptorinfo' for more details.
%
% See also kron, GrB/kron, GrB.binopinfo.

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2026, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

narginchk (3, 7) ;

if (gb_is_grb (arg1))
    arg1 = struct (arg1) ;
end

if (gb_is_grb (arg2))
    arg2 = struct (arg2) ;
end

if (gb_is_grb (arg3))
    arg3 = struct (arg3) ;
end

if (nargin >= 4 && gb_is_grb (arg4))
    arg4 = struct (arg4) ;
end

if (nargin >= 5 && gb_is_grb (arg5))
    arg5 = struct (arg5) ;
end

if (nargin >= 6 && gb_is_grb (arg6))
    arg6 = struct (arg6) ;
end

% arg7: if present, it must be the descriptor

    switch (nargin)
        case 3
            [C_opaque, kind] = gbmex_kronecker (0, arg1, arg2, arg3) ;
        case 4
            [C_opaque, kind] = gbmex_kronecker (0, arg1, arg2, arg3, arg4) ;
        case 5
            [C_opaque, kind] = gbmex_kronecker (0, arg1, arg2, arg3, arg4, ...
                arg5) ;
        case 6
            [C_opaque, kind] = gbmex_kronecker (0, arg1, arg2, arg3, arg4, ...
                arg5, arg6) ;
        case 7
            [C_opaque, kind] = gbmex_kronecker (0, arg1, arg2, arg3, arg4, ...
                arg5, arg6, arg7) ;
    end
    C = gb_mexfunction_result (0, C_opaque, kind) ;

