1function C = select (arg1, arg2, arg3, arg4, arg5, arg6, arg7)
2%GRB.SELECT: select entries from a GraphBLAS sparse matrix.
3%
4%   C = GrB.select (selectop, A)
5%   C = GrB.select (selectop, A, b)
6%   C = GrB.select (selectop, A, b, desc)
7%
8%   C = GrB.select (Cin, accum, selectop, A)
9%   C = GrB.select (Cin, accum, selectop, A, b)
10%   C = GrB.select (Cin, accum, selectop, A, b, desc)
11%
12%   C = GrB.select (Cin, M, selectop, A)
13%   C = GrB.select (Cin, M, selectop, A, b)
14%   C = GrB.select (Cin, M, selectop, A, b, desc)
15%
16%   C = GrB.select (Cin, M, accum, selectop, A)
17%   C = GrB.select (Cin, M, accum, selectop, A, b)
18%   C = GrB.select (Cin, M, accum, selectop, A, b, desc)
19%
20% GrB.select selects a subset of entries from the matrix A, based on
21% their value or position.  For example, L = GrB.select ('tril', A, 0)
22% returns the lower triangular part of the GraphBLAS or MATLAB matrix A,
23% just like L = tril (A) for a MATLAB matrix A.  The select operators can
24% also depend on the values of the entries.  The b parameter is an
25% input scalar, used in many of the select operators.  For example,
26% L = GrB.select ('tril', A, -1) is the same as L = tril (A, -1), which
27% returns the strictly lower triangular part of A.  The b scalar is
28% required for 'tril', 'triu', 'diag', 'offdiag' and the 2-input
29% operators.  It must not appear when using the '*0' operators.
30%
31% The selectop is a string defining the operator:
32%
33%   operator        MATLAB equivalent           alternative strings
34%   --------        -----------------           -------------------
35%   'tril'          C = tril (A,b)
36%   'triu'          C = triu (A,b)
37%   'diag'          C = diag (A,b), see note
38%   'offdiag'       C = entries not in diag(A,b)
39%   'nonzero'       C = A (A ~= 0)              '~=0'
40%   'zero'          C = A (A == 0)              '==0'
41%   'positive'      C = A (A >  0)              '>0'
42%   'nonnegative'   C = A (A >= 0)              '>=0'
43%   'negative'      C = A (A <  0)              '<0'
44%   'nonpositive'   C = A (A <= 0)              '<=0'
45%   '~='            C = A (A ~= b)
46%   '=='            C = A (A == b)
47%   '>'             C = A (A >  b)
48%   '>='            C = A (A >= b)
49%   '<'             C = A (A <  b)
50%   '<='            C = A (A <= b)
51%
52% Note that C = GrB.select ('diag',A,b) does not return a vector,
53% but a diagonal matrix, instead.
54%
55% Many of the operations have equivalent synonyms, as listed above.
56%
57% Cin is an optional input matrix.  If Cin is not present or is an empty
58% matrix (Cin = [ ]) then it is implicitly a matrix with no entries, of
59% the right size (which depends on A, and the descriptor).  Its type is
60% the output type of the accum operator, if it is present; otherwise, its
61% type is the type of the matrix A.
62%
63% M is the optional mask matrix.  If not present, or if empty, then no
64% mask is used.  If present, M must have the same size as C.
65%
66% If accum is not present, then the operation becomes C<...> =
67% select(...).  Otherwise, accum (C, select(...)) is computed.  The accum
68% operator acts like a sparse matrix addition (see GrB.eadd).
69%
70% The selectop is a required string defining the select operator to use.
71% All operators operate on all types (the select operators do not do any
72% typecasting of its inputs).
73%
74% A is the input matrix.  It is transposed on input if desc.in0 =
75% 'transpose'.
76%
77% desc is optional. See 'help GrB.descriptorinfo' for more details.
78%
79% See also GrB/tril, GrB/triu, GrB/diag.
80
81% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
82% SPDX-License-Identifier: GPL-3.0-or-later
83
84if (isobject (arg1))
85    arg1 = arg1.opaque ;
86end
87
88if (isobject (arg2))
89    arg2 = arg2.opaque ;
90end
91
92if (nargin > 2 && isobject (arg3))
93    arg3 = arg3.opaque ;
94end
95
96if (nargin > 3 && isobject (arg4))
97    arg4 = arg4.opaque ;
98end
99
100if (nargin > 4 && isobject (arg5))
101    arg5 = arg5.opaque ;
102end
103
104if (nargin > 5 && isobject (arg6))
105    arg6 = arg6.opaque ;
106end
107
108switch (nargin)
109    case 2
110        [C, k] = gbselect (arg1, arg2) ;
111    case 3
112        [C, k] = gbselect (arg1, arg2, arg3) ;
113    case 4
114        [C, k] = gbselect (arg1, arg2, arg3, arg4) ;
115    case 5
116        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5) ;
117    case 6
118        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5, arg6) ;
119    case 7
120        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5, arg6, arg7) ;
121end
122
123if (k == 0)
124    C = GrB (C) ;
125end
126
127