File: select.m

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

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

if (isobject (arg1))
    arg1 = arg1.opaque ;
end

if (isobject (arg2))
    arg2 = arg2.opaque ;
end

if (nargin > 2 && isobject (arg3))
    arg3 = arg3.opaque ;
end

if (nargin > 3 && isobject (arg4))
    arg4 = arg4.opaque ;
end

if (nargin > 4 && isobject (arg5))
    arg5 = arg5.opaque ;
end

if (nargin > 5 && isobject (arg6))
    arg6 = arg6.opaque ;
end

switch (nargin)
    case 2
        [C, k] = gbselect (arg1, arg2) ;
    case 3
        [C, k] = gbselect (arg1, arg2, arg3) ;
    case 4
        [C, k] = gbselect (arg1, arg2, arg3, arg4) ;
    case 5
        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5) ;
    case 6
        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5, arg6) ;
    case 7
        [C, k] = gbselect (arg1, arg2, arg3, arg4, arg5, arg6, arg7) ;
end

if (k == 0)
    C = GrB (C) ;
end