File: test135.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (114 lines) | stat: -rw-r--r-- 2,600 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function test135
%TEST135 reduce-to-scalar, built-in monoids with terminal values

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

fprintf ('test135: reduce to scalar\n') ;

rng ('default') ;

n = 10e6 ;

[save_nthreads, save_chunk] = nthreads_get ;
nthreads_max = feature_numcores

%-------------------------------------------------------------------------------
fprintf ('================== int8 min:\n') ;

X = rand (n,1) ;
X = (256 * X) - 128 ;
X = int8 (X) ;
s = int8 (inf) ;
tic
c0 = min (X) ;
tm = toc ;
fprintf ('built-in: %g sec\n', tm) ;

A.matrix = sparse (double (X)) ;
A.pattern = logical (spones (X)) ;
A.class = 'int8' ;

nthreads_set (1,1) ;
tic
c1 = GB_mex_reduce_to_scalar (s, [ ], 'min', A) ;
t1 = toc ;
assert (c1 == c0) ;
fprintf ('1 thread  %g sec\n', t1) ;

nthreads_set (nthreads_max,1) ;
tic
c2 = GB_mex_reduce_to_scalar (s, [ ], 'min', A) ;
t2 = toc ;
assert (c2 == c0) ;
fprintf ('%d threads %g sec\n', nthreads_max, t2) ;

%-------------------------------------------------------------------------------
fprintf ('================== double min:\n') ;

X = sparse (rand (n,1)) ;

A.matrix = X ;
A.pattern = logical (spones (X)) ;
A.class = 'double' ;

tic
c0 = min (X) ;
tm = toc ;
fprintf ('built-in: %g sec\n', tm) ;

s = double (inf) ;

nthreads_set (1,1) ;
tic
c1 = GB_mex_reduce_to_scalar (s, [ ], 'min', A) ;
t1 = toc ;
assert (c1 == c0) ;
fprintf ('1 thread  %g sec\n', t1) ;

nthreads_set (nthreads_max,1) ;
tic
c2 = GB_mex_reduce_to_scalar (s, [ ], 'min', A) ;
t2 = toc ;
assert (c2 == c0) ;
fprintf ('%d threads %g sec\n', nthreads_max, t2) ;

%-------------------------------------------------------------------------------
fprintf ('================== double sum:\n') ;

X = rand (n,1) ;
tic
c0 = sum (X) ;
tm = toc ;
fprintf ('built-in: %g sec (full)\n', tm) ;

X = sparse (X) ;

A.matrix = X ;
A.pattern = logical (spones (X)) ;
A.class = 'double' ;

tic
c0 = full (sum (X)) ;
tm = toc ;
fprintf ('built-in: %g sec (sparse)\n', tm) ;

s = double (inf) ;

nthreads_set (1,1) ;
tic
c1 = GB_mex_reduce_to_scalar (s, [ ], 'plus', A) ;
t1 = toc ;
assert (norm (c1 - c0) / norm (c0) < 1e-12) ;
fprintf ('1 thread  %g sec\n', t1) ;

nthreads_set (nthreads_max,1) ;
tic
c2 = GB_mex_reduce_to_scalar (s, [ ], 'plus', A) ;
t2 = toc ;
assert (norm (c2 - c0) / norm (c0) < 1e-12) ;
fprintf ('%d threads %g sec\n', nthreads_max, t2) ;

%-------------------------------------------------------------------------------
nthreads_set (save_nthreads, save_chunk) ;
fprintf ('test135: all tests passed\n') ;