1function C = GB_spec_apply (C, Mask, accum, op, A, descriptor)
2%GB_SPEC_APPLY a MATLAB mimic of GrB_apply
3%
4% Usage:
5% C = GB_spec_apply (C, Mask, accum, op, A, descriptor)
6
7% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
8% SPDX-License-Identifier: Apache-2.0
9
10%-------------------------------------------------------------------------------
11% get inputs
12%-------------------------------------------------------------------------------
13
14if (nargout > 1 || nargin ~= 6)
15    error ('usage: C = GB_spec_apply (C, Mask, accum, op, A, descriptor)') ;
16end
17
18C = GB_spec_matrix (C) ;
19A = GB_spec_matrix (A) ;
20[opname optype ztype xtype] = GB_spec_operator (op, C.class) ;
21[C_replace Mask_comp Atrans Btrans Mask_struct] = ...
22    GB_spec_descriptor (descriptor) ;
23Mask = GB_spec_getmask (Mask, Mask_struct) ;
24
25%-------------------------------------------------------------------------------
26% do the work via a clean MATLAB interpretation of the entire GraphBLAS spec
27%-------------------------------------------------------------------------------
28
29% apply the descriptor to A
30if (Atrans)
31    A.matrix = A.matrix.' ;
32    A.pattern = A.pattern' ;
33end
34
35% T = op(A)
36T.matrix = GB_spec_zeros (size (A.matrix), ztype) ;
37T.pattern = A.pattern ;
38T.class = ztype ;
39p = T.pattern ;
40
41if (GB_spec_is_positional (opname))
42    [m, n] = size (A.matrix) ;
43    for i = 1:m
44        for j = 1:n
45            if (p (i,j))
46                T.matrix (i,j) = GB_spec_unop_positional (opname, i, j) ;
47            end
48        end
49    end
50else
51    x = A.matrix (p) ;
52    z = GB_spec_op (op, x) ;
53    T.matrix (p) = z ;
54end
55
56% C<Mask> = accum (C,T): apply the accum, then Mask, and return the result
57C = GB_spec_accum_mask (C, Mask, accum, T, C_replace, Mask_comp, 0) ;
58
59