1function C = gb_max2 (op, A, B)
2%GB_MAX2 2-input max
3% Implements C = max (A,B)
4
5% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6% SPDX-License-Identifier: GPL-3.0-or-later
7
8[am, an, atype] = gbsize (A) ;
9[bm, bn, btype] = gbsize (B) ;
10a_is_scalar = (am == 1) && (an == 1) ;
11b_is_scalar = (bm == 1) && (bn == 1) ;
12ctype = gboptype (atype, btype) ;
13
14if (a_is_scalar)
15    if (b_is_scalar)
16        % both A and B are scalars.  Result is also a scalar.
17        C = gb_union_op (op, A, B) ;
18    else
19        % A is a scalar, B is a matrix
20        if (gb_scalar (A) > 0)
21            % since A > 0, the result is full
22            A = gb_scalar_to_full (bm, bn, ctype, gb_fmt (B), A) ;
23            C = gbeadd (A, op, B) ;
24        else
25            % since A <= 0, the result is sparse.
26            C = gbapply2 (A, op, B) ;
27        end
28    end
29else
30    if (b_is_scalar)
31        % A is a matrix, B is a scalar
32        if (gb_scalar (B) > 0)
33            % since B > 0, the result is full
34            B = gb_scalar_to_full (am, an, ctype, gb_fmt (A), B) ;
35            C = gbeadd (A, op, B) ;
36        else
37            % since B <= 0, the result is sparse.
38            C = gbapply2 (A, op, B) ;
39        end
40    else
41        % both A and B are matrices.  Result is sparse.
42        C = gb_union_op (op, A, B) ;
43    end
44end
45
46