1function test30b
2%TEST30B performance test GB_mex_assign, scalar expansionb
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7[save_nthreads save_chunk] = nthreads_get ;
8chunk = 4096 ;
9nthreads = feature ('numcores') ;
10nthreads_set (nthreads, chunk) ;
11
12Prob = ssget (2662) ;
13A = Prob.A ;
14
15[m n] = size (A) ;
16
17ni =  500 ;
18nj = 1000 ;
19I = randperm (m,ni) ;
20J = randperm (n,nj) ;
21I0 = uint64 (I-1) ;
22J0 = uint64 (J-1) ;
23
24scalar = sparse (pi) ;
25
26% tic/toc includes the mexFunction overhead of making a deep copy
27% of the input matrix.  MATLAB can modify C in place, as can GraphBLAS,
28% but GraphBLAS cannot safely do that through a mexFunction interface
29% to MATLAB.
30
31fprintf ('start GraphBLAS:\n') ;
32tic
33C2 = GB_mex_assign (A, [], [], scalar, I0, J0, []) ;
34toc
35t = grbresults
36
37C = A ;
38fprintf ('start MATLAB:\n') ;
39tic
40C (I,J) = scalar ;
41tm = toc
42
43fprintf ('GraphBLAS speedup over MATLAB: %g\n',  tm/t) ;
44
45assert (isequal (C, C2.matrix)) ;
46fprintf ('\ntest30b: all tests passed\n') ;
47
48nthreads_set (save_nthreads, save_chunk) ;
49
50