1function testc7 2%TESTC7 test complex assign 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('\ntestc7: all complex assign C(I,J)=A --------------------------\n') ; 8rng ('default') 9 10dclear.outp = 'replace' ; 11dclear.mask = 'complement' ; 12tol = 1e-13 ; 13 14seed = 1 ; 15for m = [1 5 10 50] 16 for n = [1 5 10 50] 17 seed = seed + 1 ; 18 C = GB_mex_random (m, n, 10*(m+n), 1, seed) ; 19 for ni = 1:m 20 for nj = 1:n 21 I = randperm (m, ni) ; 22 J = randperm (n, nj) ; 23 seed = seed + 1 ; 24 A = GB_mex_random (ni, nj, 2*(ni+nj), 1, seed) ; 25 seed = seed + 1 ; 26 M = GB_mex_random (ni, nj, 4*(ni+nj), 0, seed) ; 27 C1 = C ; 28 C1 (I,J) = A ; 29 30 I0 = uint64 (I-1) ; 31 J0 = uint64 (J-1) ; 32 33 C2 = GB_mex_subassign (C, [ ], [ ], A, I0, J0, []) ; 34 assert (isequal (C1, C2.matrix)) ; 35 36 [C3,c1] = GB_mex_subassign (C, M, [ ], A, I0, J0, [], 'plus') ; 37 cin = complex (0,0) ; 38 c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ; 39 assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ; 40 41 C1 = C ; 42 C1 (I,J) = C1 (I,J) + A ; 43 44 C2 = GB_mex_subassign (C, [ ], 'plus', A, I0, J0, []) ; 45 assert (norm (C1 - C2.matrix, 1) <= tol * (norm (C1,1)+1)) ; 46 assert (isequal (C1, C2.matrix)) ; 47 48 end 49 fprintf ('.') ; 50 end 51 52 C = GB_mex_random (m, n, 100*(m*n), 1, seed) ; seed = seed + 1 ; 53 M = GB_mex_random (m, n, 4*(ni+nj), 0, seed) ; seed = seed + 1 ; 54 A = GB_mex_random (m, n, m+n, 1, seed) ; seed = seed + 1 ; 55 56 [C3,c1] = GB_mex_subassign (C, M, [ ], A, [ ], [ ], dclear, 'plus') ; 57 cin = complex (0,0) ; 58 c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ; 59 assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ; 60 61 [C3,c1] = GB_mex_subassign (C, [ ], [ ], A, [ ], [ ], dclear, 'plus') ; 62 cin = complex (0,0) ; 63 c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ; 64 assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ; 65 66 clear S 67 S.matrix = sparse (1i * ones (m,n)) ; 68 S.pattern = false (m,n) ; 69 cin = complex (1,1) ; 70 M = sparse (true (m,n)) ; 71 C2 = GB_mex_subassign (S, M, [ ], sparse (cin), ... 72 [ ], [ ], struct ('mask', 'structural')) ; 73 C1 = sparse (ones (m,n)) ; 74 C1 (:,:) = cin ; 75 assert (norm (C1-C2.matrix, 1) < 1e-12) 76 77 end 78end 79 80fprintf ('\ntestc7: all complex assign C(I,J)=A tests passed\n') ; 81 82