1function test128
2%TEST128 test eWiseMult and eWiseAdd, special cases
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest128: test eWiseMult and eWiseAdd, special cases\n') ;
8rng ('default') ;
9
10m = 100 ;
11n = 100 ;
12
13Mmat = sparse (m,n) ;
14Mmat (1,:) = 1 ;
15
16Amat = sparse (rand (m,n)) ;
17Amat (:, 2) = 0 ;
18Amat (:, 5) = 0 ;
19Amat (1, 5) = 1 ;
20Amat (2, 6) = 0 ;
21
22Bmat = sparse (rand (m,n)) ;
23Bmat (:, 3:4) = 0 ;
24Bmat (:, 6) = 0 ;
25Bmat (1, 6) = 1 ;
26Amat (2, 5) = 0 ;
27
28clear M
29M.matrix  = Mmat ;
30M.pattern = logical (spones (Mmat)) ;
31M.class = 'logical' ;
32
33clear A
34A.matrix  = Amat ;
35A.pattern = logical (spones (Amat)) ;
36A.class = 'double' ;
37
38clear B
39B.matrix  = Bmat ;
40B.pattern = logical (spones (Bmat)) ;
41B.class = 'double' ;
42
43S = sparse (m,n) ;
44X = sparse (rand (m,n)) ;
45
46for B_hyper = 0:1
47    for A_hyper = 0:1
48        A.is_hyper = A_hyper ;
49        B.is_hyper = B_hyper ;
50
51        for M_hyper = 0:1
52            M.is_hyper = M_hyper ;
53
54            C0 = Amat .* Bmat .* Mmat ;
55            C1 = GB_spec_Matrix_eWiseMult (S, M, [ ], 'times', A, B, [ ]) ;
56            C2 = GB_mex_Matrix_eWiseMult  (S, M, [ ], 'times', A, B, [ ]) ;
57            C3 = GB_mex_Matrix_eWiseMult  (S, M, [ ], 'times', B, A, [ ]) ;
58            GB_spec_compare (C1, C2) ;
59            GB_spec_compare (C1, C3) ;
60            assert (isequal (C0, C2.matrix)) ;
61
62            C0 = (Amat + Bmat) .* Mmat ;
63            C1 = GB_spec_Matrix_eWiseAdd (S, M, [ ], 'plus', A, B, [ ]) ;
64            C2 = GB_mex_Matrix_eWiseAdd  (S, M, [ ], 'plus', A, B, [ ]) ;
65            C3 = GB_mex_Matrix_eWiseAdd  (S, M, [ ], 'plus', B, A, [ ]) ;
66            GB_spec_compare (C1, C2) ;
67            GB_spec_compare (C1, C3) ;
68            assert (isequal (C0, C2.matrix)) ;
69
70            C1 = GB_spec_Matrix_eWiseMult (X, M, [ ], 'times', A, B, [ ]) ;
71            C2 = GB_mex_Matrix_eWiseMult  (X, M, [ ], 'times', A, B, [ ]) ;
72            GB_spec_compare (C1, C2) ;
73
74            C1 = GB_spec_Matrix_eWiseAdd (X, M, [ ], 'plus', A, B, [ ]) ;
75            C2 = GB_mex_Matrix_eWiseAdd  (X, M, [ ], 'plus', A, B, [ ]) ;
76            GB_spec_compare (C1, C2) ;
77
78        end
79
80        C0 = Amat .* Bmat ;
81        C1 = GB_spec_Matrix_eWiseMult (S, [ ], [ ], 'times', A, B, [ ]) ;
82        C2 = GB_mex_Matrix_eWiseMult  (S, [ ], [ ], 'times', A, B, [ ]) ;
83        C3 = GB_mex_Matrix_eWiseMult  (S, [ ], [ ], 'times', B, A, [ ]) ;
84        GB_spec_compare (C1, C2) ;
85        GB_spec_compare (C1, C3) ;
86        assert (isequal (C0, C2.matrix)) ;
87
88        C0 = Amat + Bmat ;
89        C1 = GB_spec_Matrix_eWiseAdd (S, [ ], [ ], 'plus', A, B, [ ]) ;
90        C2 = GB_mex_Matrix_eWiseAdd  (S, [ ], [ ], 'plus', A, B, [ ]) ;
91        C3 = GB_mex_Matrix_eWiseAdd  (S, [ ], [ ], 'plus', B, A, [ ]) ;
92        GB_spec_compare (C1, C2) ;
93        GB_spec_compare (C1, C3) ;
94        assert (isequal (C0, C2.matrix)) ;
95
96        C1 = GB_spec_Matrix_eWiseMult (X, [ ], [ ], 'times', A, B, [ ]) ;
97        C2 = GB_mex_Matrix_eWiseMult  (X, [ ], [ ], 'times', A, B, [ ]) ;
98        GB_spec_compare (C1, C2) ;
99
100        C1 = GB_spec_Matrix_eWiseAdd (X, [ ], [ ], 'plus', A, B, [ ]) ;
101        C2 = GB_mex_Matrix_eWiseAdd  (X, [ ], [ ], 'plus', A, B, [ ]) ;
102        GB_spec_compare (C1, C2) ;
103
104    end
105end
106
107fprintf ('test128: all tests passed\n') ;
108