1function C = GB_spec_Matrix_ewiseMult (C, Mask, accum, mult, A, B, descriptor) 2%GB_SPEC_MATRIX_EWISEMULT a MATLAB mimic of GrB_Matrix_ewiseMult 3% 4% Usage: 5% C = GB_spec_Matrix_ewiseMult (C, Mask, accum, mult, A, B, descriptor) 6% 7% Computes C<Mask> = accum(C,T), in GraphBLAS notation, where T =A.*B, A'.*B, 8% A.*B' or A'.*B'. The pattern of T is the union of A and B. 9 10% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 11% SPDX-License-Identifier: Apache-2.0 12 13%------------------------------------------------------------------------------- 14% get inputs 15%------------------------------------------------------------------------------- 16 17if (nargout > 1 || nargin ~= 7) 18 error ('usage: C = GB_spec_Matrix_ewiseMult (C, Mask, accum, mult, A, B, descriptor)') ; 19end 20 21C = GB_spec_matrix (C) ; 22A = GB_spec_matrix (A) ; 23B = GB_spec_matrix (B) ; 24[mult_op optype ztype xtype ytype] = GB_spec_operator (mult, C.class) ; 25[C_replace Mask_comp Atrans Btrans Mask_struct] = ... 26 GB_spec_descriptor (descriptor) ; 27Mask = GB_spec_getmask (Mask, Mask_struct) ; 28 29%------------------------------------------------------------------------------- 30% do the work via a clean MATLAB interpretation of the entire GraphBLAS spec 31%------------------------------------------------------------------------------- 32 33% apply the descriptor to A 34if (Atrans) 35 A.matrix = A.matrix.' ; 36 A.pattern = A.pattern' ; 37end 38 39% apply the descriptor to B 40if (Btrans) 41 B.matrix = B.matrix.' ; 42 B.pattern = B.pattern' ; 43end 44 45% T = A.*B, with typecasting 46T.matrix = GB_spec_zeros (size (A.matrix), ztype) ; 47 48% the pattern of T is the intersection of both A and B 49T.pattern = A.pattern & B.pattern ; 50 51% apply the mult to entries in the intersection of A and B 52if (GB_spec_is_positional (mult)) 53 [m, n] = size (A.matrix) ; 54 for i = 1:m 55 for j = 1:n 56 if (T.pattern (i,j)) 57 T.matrix (i,j) = GB_spec_binop_positional (mult_op, i, j, i, j) ; 58 end 59 end 60 end 61else 62 p = T.pattern ; 63 % first cast the entries into the class of the operator 64 A1 = GB_mex_cast (A.matrix (p), xtype) ; 65 B1 = GB_mex_cast (B.matrix (p), ytype) ; 66 T.matrix (p) = GB_spec_op (mult, A1, B1) ; 67end 68 69T.class = ztype ; 70 71% C<Mask> = accum (C,T): apply the accum, then Mask, and return the result 72C = GB_spec_accum_mask (C, Mask, accum, T, C_replace, Mask_comp, 0) ; 73 74