1function test155
2%TEST155 test GrB_*_setElement and GrB_*_removeElement
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8mlist  = [ 1  1  10  20    5  ] ;
9nlist  = [ 1 10   1  10    5  ]  ;
10nzlist = [ 5 100 100 1000  100] ;
11
12for trial = 1:4
13
14    % fprintf ('trial: %d\n', trial) ;
15    m = mlist (trial) ;
16    n = nlist (trial) ;
17    nz = nzlist (trial) ;
18    I = irand (1, m, nz, 1) ;
19    J = irand (1, n, nz, 1) ;
20    X = rand (nz, 1) ;
21    Action = double (rand (nz, 1) > 0.4) ;
22
23    %---------------------------------------------------------------------------
24    % starting with an empty matrix:
25    %---------------------------------------------------------------------------
26
27    % do the work in MATLAB
28    C1 = sparse (m, n) ;
29    for k = 1:nz
30        if (Action (k) == 0)
31            C1 (I (k), J (k)) = sparse (0) ;
32        else
33            C1 (I (k), J (k)) = sparse (X (k)) ;
34        end
35    end
36
37    % do the work in GraphBLAS (default input matrix)
38    C2 = GB_mex_edit (sparse (m, n), I, J, X, Action) ;
39    assert (isequal (C1, C2)) ;
40
41    % do the work in GraphBLAS (all hyper / csc/csr cases)
42    clear C0
43    for is_hyper = 0:1
44        for is_csc = 0:1
45            C0.matrix = sparse (m, n) ;
46            C0.is_hyper = is_hyper ;
47            C0.is_csc = is_csc ;
48            C2 = GB_mex_edit (C0, I, J, X, Action) ;
49            assert (isequal (C1, C2)) ;
50        end
51    end
52
53    %---------------------------------------------------------------------------
54    % starting with a full matrix:
55    %---------------------------------------------------------------------------
56
57    % do the work in MATLAB
58    C1 = rand (m, n) ;
59    C1_start = C1 ;
60    for k = 1:nz
61        if (Action (k) == 0)
62            C1 (I (k), J (k)) = sparse (0) ;
63        else
64            C1 (I (k), J (k)) = sparse (X (k)) ;
65        end
66    end
67
68    % do the work in GraphBLAS, testing all sparsity control options
69    C0.matrix = C1_start ;
70    for sparsity_control = 1:15
71        C0.sparsity = sparsity_control ;
72        C2 = GB_mex_edit (C0, I, J, X, Action) ;
73        assert (isequal (C1, C2)) ;
74    end
75
76end
77
78fprintf ('test155: all tests passed\n') ;
79
80