1function test184
2%TEST184 test special cases for mxm, transpose, and build
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8nthreads = nthreads_set ;
9
10semiring.add = 'plus' ;
11semiring.multiply = 'times' ;
12semiring.class = 'double' ;
13dtn = struct ('inp0', 'tran') ;
14
15A = sprand (0, 10, 1) ;
16B = sprand (0, 10, 1) ;
17Cin = sparse (10, 10) ;
18C1 = A'*B ;
19C2 = GB_mex_mxm (Cin, [ ], [ ], semiring, A, B, dtn)
20
21%----------------------------------------------------------------------
22
23m = 1201 ;
24n = 4 ;
25k = 26 ;
26d = 0.02 ;
27A = sprand (m, n, d) ;
28B = sprand (m, k, 1.0) ;
29
30C1 = A'*B ;
31Cin = sparse (n, k) ;
32
33C2 = GB_mex_mxm (Cin, [ ], [ ], semiring, A, B, dtn) ;
34
35assert (norm (C1 - C2.matrix, 1) < 1e-12)
36
37m = 1048576 ;
38n = 20 ;
39d = 0.0031119 ;
40A = sprand (m, n, d) ;
41B = sprand (m, n, d) ;
42
43C1 = A'*B ;
44Cin = sparse (n, n) ;
45
46C2 = GB_mex_mxm (Cin, [ ], [ ], semiring, A, B, dtn) ;
47
48assert (norm (C1 - C2.matrix, 1) < 1e-12)
49
50%----------------------------------------------------------------------
51
52n = 1 ;
53m = 400 ;
54k = 4000 ;
55nthreads_set (1) ;
56A = sprand (m, k, 0.5) ;
57B = sprand (k, n, 0.5) ;
58
59C1 = A*B ;
60Cin = sparse (m, n) ;
61
62C2 = GB_mex_mxm (Cin, [ ], [ ], semiring, A, B, [ ]) ;
63err = norm (C1 - C2.matrix, 1) ;
64assert (err < 1e-10)
65
66%----------------------------------------------------------------------
67
68nthreads_set (4) ;
69m = 262144 ;
70n = 1048576 ;
71d = 4e-6 ;
72A = sprand (m, n, d) ;
73Cin = sparse (n, m) ;
74
75C1 = A' ;
76C2 = GB_mex_transpose (Cin, [ ], [ ], A, [ ]) ;
77
78assert (norm (C1 - C2.matrix, 1) < 1e-12)
79
80[I,J,X] = find (A) ;
81[m,n] = size (A) ;
82nz = length (I) ;
83I = I (randperm (nz)) ;
84J = J (randperm (nz)) ;
85X = X (randperm (nz)) ;
86I0 = uint64 (I) - 1 ;
87J0 = uint64 (J) - 1 ;
88
89A1 = sparse (I, J, X, m, n) ;
90A2 = GB_mex_Matrix_build (I0, J0, X, m, n, [ ]) ;
91
92assert (norm (A1 - A2.matrix, 1) < 1e-12)
93
94%----------------------------------------------------------------------
95
96v1 = sparse (I, 1, X, m, 1) ;
97v2 = GB_mex_Vector_build (I0, X, m, [ ]) ;
98assert (norm (v1 - v2.matrix, 1) / norm (v1,1) < 1e-12)
99
100%----------------------------------------------------------------------
101
102% restore # of threads
103nthreads_set (nthreads) ;
104
105fprintf ('\ntest184: all tests passed\n') ;
106
107