File: test155.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 (79 lines) | stat: -rw-r--r-- 2,262 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
67
68
69
70
71
72
73
74
75
76
77
78
79
function test155
%TEST155 test GrB_*_setElement and GrB_*_removeElement

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

rng ('default') ;
mlist  = [ 1  1  10  20    5  ] ;
nlist  = [ 1 10   1  10    5  ]  ;
nzlist = [ 5 100 100 1000  100] ;

for trial = 1:4

    % fprintf ('trial: %d\n', trial) ;
    m = mlist (trial) ;
    n = nlist (trial) ;
    nz = nzlist (trial) ;
    I = irand (1, m, nz, 1) ;
    J = irand (1, n, nz, 1) ;
    X = rand (nz, 1) ;
    Action = rand (nz, 1) ; % > 0.4) ;

    %---------------------------------------------------------------------------
    % starting with an empty matrix:
    %---------------------------------------------------------------------------

    % do the work with built-in methods
    C1 = sparse (m, n) ;
    for k = 1:nz
        if (Action (k) <= 0.4)
            C1 (I (k), J (k)) = sparse (0) ;
        else
            C1 (I (k), J (k)) = sparse (X (k)) ;
        end
    end

    % do the work in GraphBLAS (default input matrix)
    C2 = GB_mex_edit (sparse (m, n), I, J, X, Action) ;
    assert (isequal (C1, C2)) ;

    % do the work in GraphBLAS (all hyper / csc/csr cases)
    clear C0
    for is_hyper = 0:1
        for is_csc = 0:1
            C0.matrix = sparse (m, n) ;
            C0.is_hyper = is_hyper ;
            C0.is_csc = is_csc ;
            C2 = GB_mex_edit (C0, I, J, X, Action) ;
            assert (isequal (C1, C2)) ;
        end
    end

    %---------------------------------------------------------------------------
    % starting with a full matrix:
    %---------------------------------------------------------------------------

    % do the work with built-in methods
    C1 = rand (m, n) ;
    C1_start = C1 ;
    for k = 1:nz
        if (Action (k) <= 0.4)
            C1 (I (k), J (k)) = sparse (0) ;
        else
            C1 (I (k), J (k)) = sparse (X (k)) ;
        end
    end

    % do the work in GraphBLAS, testing all sparsity control options
    C0.matrix = C1_start ;
    for sparsity_control = 1:15
        C0.sparsity = sparsity_control ;
        C2 = GB_mex_edit (C0, I, J, X, Action) ;
        assert (isequal (C1, C2)) ;
    end

end

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