1function C = GB_spec_subassign (C, Mask, accum, A, I, J, descriptor, scalar) 2%GB_SPEC_SUBASSIGN a MATLAB mimic of GxB_subassign 3% 4% Usage: 5% C = GB_spec_subassign (C, Mask, accum, A, I, J, descriptor, scalar) 6% 7% Computes C(I,J)<Mask> = accum(C(I,J),A), in GraphBLAS notation. 8% 9% This function does the same thing as GxB_Matrix_subassign, 10% GxB_Vector_subassign, GxB_Matrix_subassign_TYPE, GxB_Vector_subassign_TYPE, 11% GxB_Row_subassign, and GxB_Col_subassign functions. In all cases, the Mask 12% is the same size as A (after optionally being transpose) and the submatrix 13% C(I,J). Entries outside the C(I,J) submatrix are never modified. 14 15% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 16% SPDX-License-Identifier: Apache-2.0 17 18%------------------------------------------------------------------------------- 19% get inputs 20%------------------------------------------------------------------------------- 21 22if (nargout > 1 || nargin ~= 8) 23 error ('usage: C = GB_spec_subassign (C, Mask, accum, A, I, J, descriptor, scalar)') ; 24end 25 26% Convert inputs to dense matrices with explicit patterns and types, 27% and with where X(~X.pattern)==identity for all matrices A, B, and C. 28C = GB_spec_matrix (C) ; 29A = GB_spec_matrix (A) ; 30[C_replace Mask_comp Atrans Btrans Mask_struct] = ... 31 GB_spec_descriptor (descriptor) ; 32Mask = GB_spec_getmask (Mask, Mask_struct) ; 33 34%------------------------------------------------------------------------------- 35 36% apply the descriptor to A 37if (Atrans) 38 A.matrix = A.matrix.' ; 39 A.pattern = A.pattern' ; 40end 41 42% expand I and J if empty 43if (ischar (I) & isempty (I)) 44 % I = '' is treated as the empty list 45 I = [ ] ; 46elseif (isempty (I) || isequal (I, ':')) 47 % I = [ ] is treated as ":" 48 nrows = size (C.matrix, 1) ; 49 I = 1:nrows ; 50end 51if (ischar (J) & isempty (J)) 52 % J = '' is treated as the empty list 53 J = [ ] ; 54elseif (isempty (J) || isequal (J, ':')) 55 % J = [ ] is treated as the ":" 56 ncols = size (C.matrix, 2) ; 57 J = 1:ncols ; 58end 59 60if (scalar) 61 % scalar expansion: expand A into a matrix 62 ni = length (I) ; 63 nj = length (J) ; 64 A.matrix (1:ni, 1:nj) = A.matrix (1,1) ; 65 A.pattern (1:ni, 1:nj) = true ; 66end 67 68S.matrix = C.matrix (I,J) ; 69S.pattern = C.pattern (I,J) ; 70S.class = C.class ; 71 72% T = A 73T.matrix = A.matrix ; 74T.pattern = A.pattern ; 75 76% S<Mask> = accum (S,T): apply the accum, then Mask, and return the result 77S = GB_spec_accum_mask (S, Mask, accum, T, C_replace, Mask_comp, 0) ; 78 79C.matrix (I,J) = S.matrix ; 80C.pattern (I,J) = S.pattern ; 81C.class = S.class ; 82 83