1function C = extract (arg1, arg2, arg3, arg4, arg5, arg6, arg7) 2%GRB.EXTRACT extract sparse submatrix. 3% 4% C = GrB.extract (Cin, M, accum, A, I, J, desc) 5% 6% C<M> = A(I,J) or accum (C, A(I,J)) 7% 8% A is a required parameter. All others are optional, but if M or accum 9% appears, then Cin is also required. If desc.in0 is 'transpose', then 10% the description below assumes A = A' is computed first before the 11% extraction (A is not changed on output, however). 12% 13% desc: see 'help GrB.descriptorinfo' for details. 14% 15% I and J are cell arrays. I contains 0, 1, 2, or 3 items: 16% 17% 0: { } This is the MATLAB ':', like A(:,J), refering to all m 18% rows, if A is m-by-n. 19% 20% 1: { I } 1D list of row indices, like A(I,J) in MATLAB. 21% 22% 2: { start,fini } start and fini are scalars (either double, 23% int64, or uint64). This defines I = start:fini in 24% MATLAB index notation. 25% 26% 3: { start,inc,fini } start, inc, and fini are scalars (double, 27% int64, or uint64). This defines I = start:inc:fini in 28% MATLAB notation. 29% 30% The J argument is identical, except that it is a list of column 31% indices of A. If only one cell array is provided, J = { } is 32% implied, refering to all n columns of A, like A(I,:) in MATLAB 33% notation. 1D indexing of a matrix A, as in C = A(I), is not yet 34% supported. 35% 36% If neither I nor J are provided on input, then this implies 37% both I = { } and J = { }, or A(:,:) in MATLAB notation, 38% refering to all rows and columns of A. 39% 40% If desc.base is 'zero-based', then I and J are interpretted as 41% zero-based, where the rows and columns of A range from 0 to m-1 and 42% n-1, respectively. If desc.base is 'one-based' (which is the 43% default), then indices are intrepetted as 1-based, just as in MATLAB. 44% 45% Cin: an optional input matrix, containing the initial content of the 46% matrix C. C on output is the content of C after the assignment is 47% made. If present, Cin argument has size length(I)-by-length(J). 48% If accum is present then Cin is a required input. 49% 50% accum: an optional binary operator, defined by a string ('+.double') for 51% example. This allows for C = Cin + A(I,J) to be computed. If 52% not present, no accumulator is used and C=A(I,J) is computed. 53% If accum is present then Cin is a required input. 54% 55% M: an optional mask matrix, the same size as C. 56% 57% Example: 58% 59% A = sprand (5, 4, 0.5) 60% I = [2 1 5] 61% J = [3 3 1 2] 62% C = GrB.extract (A, {I}, {J}) 63% C2 = A (I,J) 64% C2 - C 65% 66% See also GrB/subsref. 67 68% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 69% SPDX-License-Identifier: GPL-3.0-or-later 70 71if (isobject (arg1)) 72 arg1 = arg1.opaque ; 73end 74 75if (nargin > 1 && isobject (arg2)) 76 arg2 = arg2.opaque ; 77end 78 79if (nargin > 2 && isobject (arg3)) 80 arg3 = arg3.opaque ; 81end 82 83if (nargin > 3 && isobject (arg4)) 84 arg4 = arg4.opaque ; 85end 86 87if (nargin > 4 && isobject (arg5)) 88 arg5 = arg5.opaque ; 89end 90 91if (nargin > 5 && isobject (arg6)) 92 arg6 = arg6.opaque ; 93end 94 95switch (nargin) 96 case 1 97 [C, k] = gbextract (arg1) ; 98 case 2 99 [C, k] = gbextract (arg1, arg2) ; 100 case 3 101 [C, k] = gbextract (arg1, arg2, arg3) ; 102 case 4 103 [C, k] = gbextract (arg1, arg2, arg3, arg4) ; 104 case 5 105 [C, k] = gbextract (arg1, arg2, arg3, arg4, arg5) ; 106 case 6 107 [C, k] = gbextract (arg1, arg2, arg3, arg4, arg5, arg6) ; 108 case 7 109 [C, k] = gbextract (arg1, arg2, arg3, arg4, arg5, arg6, arg7) ; 110end 111 112if (k == 0) 113 C = GrB (C) ; 114end 115 116