1function C = or (A, B)
2%| logical OR.
3% C = (A | B) is the element-by-element logical OR of A and B.  One or
4% both may be scalars.  Otherwise, A and B must have the same size.
5%
6% See also GrB/and, GrB/xor, GrB/not.
7
8% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
9% SPDX-License-Identifier: GPL-3.0-or-later
10
11if (isobject (A))
12    A = A.opaque ;
13end
14
15if (isobject (B))
16    B = B.opaque ;
17end
18
19[am, an, ~] = gbsize (A) ;
20[bm, bn, ~] = gbsize (B) ;
21a_is_scalar = (am == 1) && (an == 1) ;
22b_is_scalar = (bm == 1) && (bn == 1) ;
23
24if (a_is_scalar)
25    if (b_is_scalar)
26        % A and B are scalars
27        C = GrB (gbemult (A, '|.logical', B)) ;
28    else
29        % A is a scalar, B is a matrix
30        if (gb_scalar (A) == 0)
31            % A is false, so C is B typecasted to logical
32            C = GrB (gbnew (B, 'logical')) ;
33        else
34            % A is true, so C is a full matrix the same size as B
35            C = GrB (gb_scalar_to_full (bm, bn, 'logical', gb_fmt (B), true)) ;
36        end
37    end
38else
39    if (b_is_scalar)
40        % A is a matrix, B is a scalar
41        if (gb_scalar (B) == 0)
42            % B is false, so C is A typecasted to logical
43            C = GrB (A, 'logical') ;
44        else
45            % B is true, so C is a full matrix the same size as A
46            C = GrB (gb_scalar_to_full (am, an, 'logical', gb_fmt (A), true)) ;
47        end
48    else
49        % both A and B are matrices.  C is the set union of A and B
50        C = GrB (gbeadd (A, '|.logical', B)) ;
51    end
52end
53
54