1function C = lt (A, B) 2%A < B less than. 3% C = (A < B) is an element-by-element comparison 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/le, GrB/gt, GrB/ge, GrB/ne, GrB/eq. 7 8% FUTURE: lt(A,B) for two matrices A and B is slower than it could be. 9% See comments in gb_union_op. 10 11% The pattern of C depends on the type of inputs: 12% A scalar, B scalar: C is scalar. 13% A scalar, B matrix: C is full if A<0, otherwise C is a subset of B. 14% B scalar, A matrix: C is full if B>0, otherwise C is a subset of A. 15% A matrix, B matrix: C has the pattern of the set union, A+B. 16 17% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 18% SPDX-License-Identifier: GPL-3.0-or-later 19 20if (isobject (A)) 21 A = A.opaque ; 22end 23 24if (isobject (B)) 25 B = B.opaque ; 26end 27 28[am, an, atype] = gbsize (A) ; 29[bm, bn, btype] = gbsize (B) ; 30a_is_scalar = (am == 1) && (an == 1) ; 31b_is_scalar = (bm == 1) && (bn == 1) ; 32ctype = gboptype (atype, btype) ; 33 34if (a_is_scalar) 35 if (b_is_scalar) 36 % both A and B are scalars 37 C = GrB (gb_union_op ('<', A, B)) ; 38 else 39 % A is a scalar, B is a matrix 40 if (gb_scalar (A) < 0) 41 if (~gb_issigned (btype)) 42 % a < 0, and B has an unsigned type. C is all true. 43 C = GrB (gb_scalar_to_full (bm, bn, 'logical', ... 44 gb_fmt (B), true)) ; 45 else 46 % since a < 0, entries not present in B result in a true 47 % value, so the result is full. Expand A to full. 48 A = gb_scalar_to_full (bm, bn, ctype, gb_fmt (B), A) ; 49 C = GrB (gbemult (A, '<', gbfull (B, ctype))) ; 50 end 51 else 52 % since a >= 0, entries not present in B result in a false 53 % value, so the result is a sparse subset of B. select all 54 % entries in B > a, then convert to true. 55 C = GrB (gbapply ('1.logical', gbselect (B, '>', A))) ; 56 end 57 end 58else 59 if (b_is_scalar) 60 % A is a matrix, B is a scalar 61 b = gb_scalar (B) ; 62 if (b < 0 && ~gb_issigned (atype)) 63 % b is negative, and A has an unsigned type. C is all false. 64 C = GrB (gbnew (am, an, 'logical')) ; 65 elseif (b > 0) 66 % since b > 0, entries not present in A result in a true 67 % value, so the result is full. Expand B to a full matrix. 68 B = gb_scalar_to_full (am, an, ctype, gb_fmt (A), B) ; 69 C = GrB (gbemult (gbfull (A, ctype), '<', B)) ; 70 else 71 % since b <= 0, entries not present in A result in a false 72 % value, so the result is a sparse subset of A. Select all 73 % entries in A < b, then convert to true. 74 C = GrB (gbapply ('1.logical', gbselect (A, '<', B))) ; 75 end 76 else 77 % both A and B are matrices. C is the set union of A and B. 78 C = GrB (gb_union_op ('<', A, B)) ; 79 end 80end 81 82