1function C = accum_mask (C, Mask, accum, T, C_replace, Mask_complement) 2%ACCUM_MASK2 a simpler version of GB_spec_accum_mask 3% It does not handle typecasting and it assumes the identity value is zero. 4% The purpose is for illustration to describe what the accum/mask operation 5% does, not for actual testing. This file appears in the User Guide. 6 7% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 8% SPDX-License-Identifier: Apache-2.0 9 10[nrows ncols] = size (C.matrix) ; 11Z.matrix = zeros (nrows, ncols) ; 12Z.pattern = false (nrows, ncols) ; 13 14if (isempty (accum)) 15 % Z = T, no accum operator 16 Z.matrix = T.matrix ; 17 Z.pattern = T.pattern ; 18else 19 % Z = accum (C,T) 20 % apply the binary operator to the set intersection 21 p = T.pattern & C.pattern ; 22 Z.matrix (p) = GB_spec_op (accum, C.matrix (p), T.matrix (p)) ; 23 24 % copy entries in C but not T 25 p = C.pattern & ~T.pattern ; 26 Z.matrix (p) = C.matrix (p) ; 27 28 % copy entries in T but not C 29 p = T.pattern & ~C.pattern ; 30 Z.matrix (p) = T.matrix (p) ; 31 32 % pattern is the set union 33 Z.pattern = C.pattern | T.pattern ; 34end 35 36% apply the mask to the values and pattern 37C.matrix = mask (C.matrix, Mask, Z.matrix, C_replace, Mask_complement) ; 38C.pattern = mask (C.pattern, Mask, Z.pattern, C_replace, Mask_complement) ; 39end 40 41function C = mask (C, Mask, Z, C_replace, Mask_complement) ; 42% replace C if requested 43if (C_replace) 44 C (:,:) = 0 ; % assume identity is zero 45end 46if (isempty (Mask)) 47 % implicitly, Mask = ones (size (C)) 48 if (~Mask_complement) 49 % this is the default 50 C = Z ; 51 else 52 % note that Z need never have been computed 53 C = C ; 54 end 55else 56 % apply the mask 57 if (~Mask_complement) 58 C (Mask) = Z (Mask) ; 59 else 60 C (~Mask) = Z (~Mask) ; 61 end 62end 63end 64 65 66