1function test36
2%TEST36 performance test of matrix subref
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest36 --------------------- performance of GB_Matrix_subref\n') ;
8
9[save save_chunk] = nthreads_get ;
10chunk = 4096 ;
11nthreads = feature ('numcores') ;
12nthreads_set (nthreads, chunk) ;
13
14rng ('default') ;
15n = 100e6 ;
16fprintf ('-------------------------- column vector (%d-by-1):\n', n) ;
17V = sprand (n, 1, 0.01) ;
18J = uint64 (0) ;
19[i j x] = find (V) ;
20nz = length (i) ;
21
22
23fprintf (' V(:,1): nnz (V) = %d\n', nnz (V)) ;
24    tic
25    C0 = V (:,1) ;
26    t0 = toc ;
27    tic
28    C1 = GB_mex_Matrix_subref (V, [ ], [ ]) ;
29    t1 = toc ;
30    assert (isequal (C0, C1)) ;
31    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
32
33fprintf (' V(50e6:80e6,1) explicit list:\n') ;
34I = uint64 (50e6:80e6) ;
35I1 = I+1 ;
36    tic
37    C0 = V (I1,1) ;
38    t0 = toc ;
39    tic
40    C1 = GB_mex_Matrix_subref (V, I, [ ]) ;
41    t1 = toc ;
42    assert (isequal (C0, C1)) ;
43    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
44
45fprintf (' V(50e6:80e6,1) colon:\n') ;
46clear I
47I.begin = 50e6-1 ; I.inc = 1 ; I.end = 80e6-1  ;
48% I1 = I+1 ;
49    tic
50    C0 = V (50e6:80e6,1) ;
51    t0 = toc ;
52    tic
53    C1 = GB_mex_Matrix_subref (V, I, [ ]) ;
54    t1 = toc ;
55    assert (isequal (C0, C1)) ;
56    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
57
58I1 = i (floor (nz/2)) ;
59I = uint64 (I1)-1 ;
60fprintf (' V(%d,1):\n', I1) ;
61
62    C0 = V (I1,1) ;
63    tic
64    C0 = V (I1,1) ;
65    t0 = toc ;
66    C1 = GB_mex_Matrix_subref (V, I, J) ;
67    tic
68    C1 = GB_mex_Matrix_subref (V, I, J) ;
69    t1 = toc ;
70    assert (isequal (C0, C1)) ;
71    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
72
73    tic
74    C0 = V (I1,1) ;
75    t0 = toc ;
76    tic
77    C1 = GB_mex_Matrix_subref (V, I, J) ;
78    t1 = toc ;
79    assert (isequal (C0, C1)) ;
80    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
81
82
83fprintf (' V( 100 entries ,1):\n') ;
84p = randperm (nz) ;
85I1 = i (p (1:100)) ;
86I = uint64 (I1)-1 ;
87
88    tic
89    C0 = V (I1,1) ;
90    t0 = toc ;
91    tic
92    C1 = GB_mex_Matrix_subref (V, I, [ ] ) ;
93    t1 = toc ;
94    assert (isequal (C0, C1)) ;
95    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
96
97
98fprintf (' V( 100 entries ,1:4):\n') ;
99V = [V V V V] ;
100
101    tic
102    C0 = V (I1,:) ;
103    t0 = toc ;
104    tic
105    C1 = GB_mex_Matrix_subref (V, I, [ ]) ;
106    t1 = toc ;
107    assert (isequal (C0, C1)) ;
108    fprintf ('MATLAB %0.6f GrB: %0.6f  speedup %g\n', t0, t1, t0/t1) ;
109
110nthreads_set (save, save_chunk) ;
111
112fprintf ('\ntest36: all tests passed\n') ;
113
114