1function test35
2%TEST35 test GrB_*_extractTuples
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\n test35 ---------------------- quick test of GrB_extractTuples\n') ;
8
9Prob = ssget ('HB/west0067') ;
10A = Prob.A ;
11[I1, J1, X1] = find (A) ;
12[I2, J2, X2] = GB_mex_extractTuples (A) ;
13assert (isequal (I1, double (I2+1)))
14assert (isequal (J1, double (J2+1)))
15assert (isequal (X1, X2))
16
17Prob = ssget (2662) ;
18A = Prob.A ;
19
20% add some dense columns
21n = size (A,2) ;
22J = randperm (n, 20) ;
23A (:,J) = 77 ;
24
25% warmup
26[I1, J1, X1] = find (A) ;
27tic
28[I1, J1, X1] = find (A) ;
29tm = toc ;
30fprintf ('MATLAB [i,j,x]=find(A) time: %g\n', tm) ;
31
32nthreads_max = 2*GB_mex_omp_max_threads ;
33save = nthreads_get ;
34
35t1 = 0 ;
36for nthreads = [1 2 4 8 16 20 32 40 64 128 260 256]
37    if (nthreads > nthreads_max)
38        break ;
39    end
40    nthreads_set (nthreads) ;
41    % warmup
42    [I2, J2, X2] = GB_mex_extractTuples (A) ;
43    % for timing
44    [I2, J2, X2] = GB_mex_extractTuples (A) ;
45    t = grbresults ;
46    if (nthreads == 1)
47        t1 = t ;
48    end
49    fprintf ('nthreads %3d speedup vs MATLAB: %10.4f  vs GrB: %10.4f\n', ...
50        nthreads, tm/t, t1/t) ;
51    assert (isequal (I1, double (I2+1)))
52    assert (isequal (J1, double (J2+1)))
53    assert (isequal (X1, X2))
54end
55
56nthreads_set (save) ;
57fprintf ('\ntest35: all tests passed\n') ;
58
59