1function test72
2%TEST72 special cases for mxm, ewise, ...
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\n--------------test72: special cases\n') ;
8
9rng ('default') ;
10clear
11
12dnt = struct ( 'inp1', 'tran' ) ;
13dtn = struct ( 'inp0', 'tran' ) ;
14dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ;
15
16n = 20 ;
17p = randperm (n) ;
18A = speye (n) ;
19A = A (p,p) ;
20B = sprand (n, n, 0.2) ;
21Z = sparse (n, n) ;
22
23semiring.multiply = 'times' ;
24semiring.add = 'plus' ;
25semiring.class = 'double' ;
26
27Mask = sparse (ones (n)) ;
28C0 = GB_spec_mxm (Z, Mask, [ ], semiring, A, B, dtt);
29C1 = GB_mex_mxm  (Z, Mask, [ ], semiring, A, B, dtt);
30
31C2 = (A'*B') .* Mask ;
32GB_spec_compare (C0, C1, 0) ;
33assert (isequal (C2, C0.matrix)) ;
34
35M = GB_mex_Matrix_eWiseAdd (Z, [ ], [ ], 'minus', Mask, Mask, [ ]) ;
36C0 = GB_spec_mxm (Z, M.matrix, [ ], semiring, A, B, dtn);
37C1 = GB_mex_mxm  (Z, M.matrix, [ ], semiring, A, B, dtn);
38GB_spec_compare (C0, C1, 0) ;
39assert (isequal (Z, sparse (C0.matrix))) ;
40
41n = 500 ;
42% n = 4 ;
43A = speye (n) ;
44% A = sparse (rand (n)) ;
45B = sparse (rand (n)) ;
46Z = sparse (n,n) ;
47
48C0 = GB_mex_Matrix_eWiseMult  (Z, [ ], [ ], 'times', A, B, [ ]) ;
49C1 = A .* B ;
50assert (isequal (C1, sparse (C0.matrix))) ;
51
52C0 = GB_mex_Matrix_eWiseMult  (Z, [ ], [ ], 'times', B, A, [ ]) ;
53C1 = B .* A ;
54assert (isequal (C1, sparse (C0.matrix))) ;
55
56A = logical (A) ;
57C0 = GB_mex_Matrix_eWiseMult  (Z, [ ], [ ], 'times', A, B, [ ]) ;
58C1 = double (A) .* B ;
59assert (isequal (C1, sparse (C0.matrix))) ;
60
61C0 = GB_mex_Matrix_eWiseMult  (Z, [ ], [ ], 'times', B, A, [ ]) ;
62C1 = B .* double (A) ;
63assert (isequal (C1, sparse (C0.matrix))) ;
64
65M = sprand (n, n, 0.01) ;
66C0 = GB_mex_mxm  (Z, M, [ ], semiring, A, B, dnt) ;
67C1 = (A*B') .* spones (M) ;
68assert (isequal (C1, sparse (C0.matrix))) ;
69
70fprintf ('test72: all tests passed\n') ;
71