1function test130
2%TEST130 test GrB_apply (hypersparse cases)
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest130: quick GrB_apply tests\n') ;
8
9rng ('default') ;
10
11m = 8 ;
12n = 4 ;
13dt = struct ('inp0', 'tran') ;
14dr = struct ('outp', 'replace') ;
15
16    aclass = 'double' ;
17
18    A   = GB_spec_random (m, n, 0.3, 100, aclass) ;
19    Cin = GB_spec_random (m, n, 0.3, 100, aclass) ;
20    B   = GB_spec_random (n, m, 0.3, 100, aclass) ;
21    cin = GB_mex_cast (0, aclass) ;
22    Mask = GB_random_mask (m, n, 0.5, true, false) ;
23
24    if (isequal (aclass, 'double'))
25        hrange = [0 1] ;
26        crange = [0 1] ;
27    else
28        hrange = 0 ;
29        crange = 1 ;
30    end
31
32    for A_is_hyper = hrange
33    for A_is_csc   = crange
34    for C_is_hyper = hrange
35    for C_is_csc   = crange
36    for M_is_hyper = hrange
37    for M_is_csc   = crange
38
39    A.is_csc    = A_is_csc ; A.is_hyper    = A_is_hyper ;
40    Cin.is_csc  = C_is_csc ; Cin.is_hyper  = C_is_hyper ;
41    B.is_csc    = A_is_csc ; B.is_hyper    = A_is_hyper ;
42    Mask.is_csc = M_is_csc ; Mask.is_hyper = M_is_hyper ;
43
44
45        op.opname = 'ainv' ;
46
47        fprintf ('.') ;
48
49            op.optype = 'double' ;
50
51            % no mask
52            C1 = GB_spec_apply (Cin, [], [], op, A, []) ;
53            C2 = GB_mex_apply  (Cin, [], [], op, A, []) ;
54            GB_spec_compare (C1, C2) ;
55
56            % no mask, with accum
57            C1 = GB_spec_apply (Cin, [], 'plus', op, A, []) ;
58            C2 = GB_mex_apply  (Cin, [], 'plus', op, A, []) ;
59            GB_spec_compare (C1, C2) ;
60
61            % with mask
62            C1 = GB_spec_apply (Cin, Mask, [], op, A, []) ;
63            C2 = GB_mex_apply  (Cin, Mask, [], op, A, []) ;
64            GB_spec_compare (C1, C2) ;
65
66            % with mask and accum
67            C1 = GB_spec_apply (Cin, Mask, 'plus', op, A, []) ;
68            C2 = GB_mex_apply  (Cin, Mask, 'plus', op, A, []) ;
69            GB_spec_compare (C1, C2) ;
70
71            Cmask = spones (GB_mex_cast (full (Cin.matrix), Cin.class)) ;
72
73            % with C == mask, and outp = replace
74            C1 = GB_spec_apply (Cin, Cmask, [], op, A, dr) ;
75            C2 = GB_mex_apply_maskalias (Cin,        [], op, A, dr) ;
76            GB_spec_compare (C1, C2) ;
77
78            % with C == mask and accum, and outp = replace
79            C1 = GB_spec_apply (Cin, Cmask, 'plus', op, A, dr) ;
80            C2 = GB_mex_apply_maskalias (Cin,        'plus', op, A, dr) ;
81            GB_spec_compare (C1, C2) ;
82
83            % no mask, transpose
84            C1 = GB_spec_apply (Cin, [], [], op, B, dt) ;
85            C2 = GB_mex_apply  (Cin, [], [], op, B, dt) ;
86            GB_spec_compare (C1, C2) ;
87
88            % no mask, with accum, transpose
89            C1 = GB_spec_apply (Cin, [], 'plus', op, B, dt) ;
90            C2 = GB_mex_apply  (Cin, [], 'plus', op, B, dt) ;
91            GB_spec_compare (C1, C2) ;
92
93            % with mask, transpose
94            C1 = GB_spec_apply (Cin, Mask, [], op, B, dt) ;
95            C2 = GB_mex_apply  (Cin, Mask, [], op, B, dt) ;
96            GB_spec_compare (C1, C2) ;
97
98            % with mask and accum, transpose
99            C1 = GB_spec_apply (Cin, Mask, 'plus', op, B, dt) ;
100            C2 = GB_mex_apply  (Cin, Mask, 'plus', op, B, dt) ;
101            GB_spec_compare (C1, C2) ;
102
103    end
104    end
105    end
106    end
107    end
108    end
109    fprintf ('\n') ;
110
111
112fprintf ('\ntest130: all tests passed\n') ;
113
114