1function test46b
2%TEST46B performance test of GrB_assign
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\n--------------performance test GB_mex_assign\n') ;
8
9[save save_chunk] = nthreads_get ;
10chunk = 4096 ;
11nthreads = feature ('numcores') ;
12nthreads_set (nthreads, chunk) ;
13
14dt = struct ('inp0', 'tran') ;
15
16rng ('default') ;
17
18A = sparse (rand (3,4)) ;
19I = uint64 (0:2) ;
20J = uint64 (0:3) ;
21C = A ;
22
23C0 = sprandn (length(I), length (J), 0.5) ;
24C1 = C ;
25C1 (I+1,J+1) = C0 ;
26CC = GB_mex_assign (C, [],[], C0, I, J, []) ;
27assert (isequal (C1, CC.matrix))
28
29C0 = sprandn (length(I), length (J), 0.5)' ;
30C1 = C ;
31C1 (I+1,J+1) = C0' ;
32CC = GB_mex_assign (C, [],[], C0, I, J, dt) ;
33assert (isequal (C1, CC.matrix))
34
35for trial = 1:100
36
37    for m = [1 10 100]
38        for n = [1 10 100]
39
40            C = sprandn (m, n, 0.1) ;
41
42            ni = double (irand (1, m)) ;
43            nj = double (irand (1, n)) ;
44            I = randperm (m) ;
45            J = randperm (n) ;
46            I = I (1:ni) ;
47            J = J (1:nj) ;
48            I0 = uint64 (I-1) ;
49            J0 = uint64 (J-1) ;
50
51            A = sprandn (ni, nj, 0.1) ;
52
53            C1 = C ;
54            C1 (I,J) = A ;
55            C2 = GB_mex_assign (C, [], '', A, I0, J0, []) ;
56
57            C3 = C ;
58            C3 (I,J) = C3 (I,J) + A ;
59            C4 = GB_mex_assign (C, [], 'plus', A, I0, J0, []) ;
60
61            assert (isequal (C3, C4.matrix))
62        end
63    end
64end
65
66
67Prob = ssget (2662) ;
68A = Prob.A ;
69C = A ;
70C (1,1) = 1 ;
71[m n] = size (A) ;
72
73ni = 5500 ;
74nj = 7000 ;
75B = sprandn (ni, nj, 0.001) ;
76I = randperm (m) ; I = I (1:ni) ;
77J = randperm (n) ; J = J (1:nj) ;
78fprintf ('nnzB: %g\n', nnz (B)) ;
79
80fprintf ('MATLAB start:\n')
81tic
82C (I,J) = B ;
83toc
84
85I0 = uint64 (I-1) ;
86J0 = uint64 (J-1) ;
87
88C2 = A;
89C2 (1,1) =1 ;
90
91fprintf ('GraphBLAS start:\n')
92tic
93C3 = GB_mex_assign (C2, [], [], B, I0, J0, []) ;
94toc
95
96assert (isequal (C, C3.matrix)) ;
97
98A = Prob.A ;
99C = A ;
100C (1,1) = 1 ;
101
102fprintf ('MATLAB start:\n')
103tic
104C (I,J) = C (I,J) + B ;
105toc
106
107C2 = A ;
108C2 (1,1) = 1 ;
109
110fprintf ('GraphBLAS start:\n')
111tic
112C3 = GB_mex_assign (C2, [], 'plus', B, I0, J0, []) ;
113toc
114
115assert (isequal (C, C3.matrix)) ;
116
117nthreads_set (save, save_chunk) ;
118
119fprintf ('\ntest46b: all tests passed\n') ;
120