1function C = GB_spec_Matrix_extract (C, Mask, accum, A, I, J, descriptor)
2%GB_SPEC_MATRIX_EXTRACT a MATLAB mimic of GrB_Matrix_extract
3%
4% Usage:
5% C = GB_spec_Matrix_extract (C, Mask, accum, A, I, J, descriptor)
6%
7% MATLAB mimic of C<Mask> = accum (A (I,J))
8
9% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
10% SPDX-License-Identifier: Apache-2.0
11
12%-------------------------------------------------------------------------------
13% get inputs
14%-------------------------------------------------------------------------------
15
16if (nargout > 1 || nargin ~= 7)
17    error ('usage: C = GB_spec_Matrix_extract (C, Mask, accum, A, I, J, descriptor)') ;
18end
19
20C = GB_spec_matrix (C) ;
21A = GB_spec_matrix (A) ;
22[C_replace Mask_comp Atrans Btrans Mask_struct] = ...
23    GB_spec_descriptor (descriptor) ;
24Mask = GB_spec_getmask (Mask, Mask_struct) ;
25
26%-------------------------------------------------------------------------------
27% do the work via a clean MATLAB interpretation of the entire GraphBLAS spec
28%-------------------------------------------------------------------------------
29
30% apply the descriptor to A
31if (Atrans)
32    A.matrix = A.matrix.' ;
33    A.pattern = A.pattern' ;
34end
35
36% expand I and J if empty
37if (ischar (I) & isempty (I))
38    % I = '' is treated as the empty list
39    I = [ ] ;
40elseif (isempty (I) || isequal (I, ':'))
41    % I = [ ] is treated as ":"
42    nrows = size (A.matrix, 1) ;
43    I = 1:nrows ;
44end
45if (ischar (J) & isempty (J))
46    % J = '' is treated as the empty list
47    J = [ ] ;
48elseif (isempty (J) || isequal (J, ':'))
49    % J = [ ] is treated as the ":"
50    ncols = size (A.matrix, 2) ;
51    J = 1:ncols ;
52end
53
54T.matrix = A.matrix (I,J) ;
55T.pattern = A.pattern (I,J) ;
56T.class = A.class ;
57
58% C<Mask> = accum (C,T): apply the accum, then Mask, and return the result
59C = GB_spec_accum_mask (C, Mask, accum, T, C_replace, Mask_comp, 0) ;
60
61