1function test126
2%TEST126 test GrB_reduce to vector on a very sparse matrix
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test126:  test GrB_reduce to vector on a very sparse matrix\n') ;
8rng ('default') ;
9
10n = 1000 ;
11A = sprand (n, n, 0.1) ;
12huge = 1e9 ;
13A (huge, 2) = 42 ;
14
15tic
16row = sum (A,1) ;
17tm1 = toc ;
18
19nrm = full (sum (row)) ;
20
21tic
22col = sum (A,2) ;
23tm2 = toc ;
24
25s = sparse (huge, 1) ;
26tic
27w = GB_mex_reduce_to_vector (s, [ ], [ ], 'plus', A, [ ]) ;
28tg1 = grbresults ;
29assert (norm (col - w.matrix, 1) / nrm < 1e-12)
30
31dtn.inp0 = 'tran' ;
32s = sparse (n, 1) ;
33tic
34w = GB_mex_reduce_to_vector (s, [ ], [ ], 'plus', A, dtn) ;
35tg2 = grbresults ;
36assert (norm (row' - w.matrix, 1) / nrm < 1e-12)
37
38fprintf ('reduce each vector: MATLAB %g GrB %g speedup %g\n', ...
39    tm1, tg1, tm1/tg1) ;
40
41fprintf ('reduce each index:  MATLAB %g GrB %g speedup %g\n', ...
42    tm2, tg2, tm2/tg2) ;
43
44fprintf ('test126: all tests passed\n') ;
45