File: test04.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 (66 lines) | stat: -rw-r--r-- 1,956 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
function test04
%TEST04 test and demo for accumulator/mask and transpose

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

fprintf ('\n-------------------- simple mask and transpose tests\n') ;

rng ('default') ;
C = rand (4)
Z = magic (4)
Mask = mod (Z,2) == 0

for C_replace = [false true]
    for Mask_comp = [false true]
        fprintf ('Use Mask.  C_replace: %d Mask_comp: %d\n', ...
            C_replace, Mask_comp) ;
        Cresult = GB_spec_mask (C, Mask, Z, C_replace, Mask_comp) ;
        % C2 =  apply_mask_sparse (C, Z, Mask, C_replace, Mask_comp) ;
        % assert (isequal (Cresult, C2))

        D = [ ] ;
        if (Mask_comp)
            D.mask = 'complement' ;
        end
        if (C_replace)
            D.outp = 'replace' ;
        end

        A = Z ;
        fprintf ('C3 <Mask> = C + A'' :\n') ;
        C3 = GB_spec_transpose (C, Mask, 'plus', A, D) ;
        C5 = GB_mex_transpose  (sparse(C), sparse(Mask), 'plus', sparse(A), D);
        assert (isequal (C3.matrix, C5.matrix))

    end
end

for C_replace = [false true]
    for Mask_comp = [false true]
        fprintf ('No Mask.  C_replace: %d Mask_comp: %d\n', ...
            C_replace, Mask_comp) ;
        Cresult = GB_spec_mask (C, [ ], Z, C_replace, Mask_comp) ;
        % C2 = apply_mask_sparse  (C, Z, [ ], C_replace, Mask_comp) ;
        % assert (isequal (Cresult, C2))

        D = [ ] ;
        if (Mask_comp)
            D.mask = 'complement' ;
        end
        if (C_replace)
            D.outp = 'replace' ;
        end

        A = Z ;
        fprintf ('C3 <no mask complement:%d replace:%d> = C + A'' :\n', ...
            Mask_comp, C_replace) ;
D
        C3 = GB_spec_transpose (C, [ ], 'plus', A, D) ;
        C5 = GB_mex_transpose  (sparse(C), [ ], 'plus', sparse(A), D);
        assert (isequal (C3.matrix, C5.matrix))
    end
end

fprintf ('\ntest04: all tests passed\n') ;