1function test115
2%TEST115 test GB_assign, scalar expansion and zombies, with duplicates
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8
9    n = 200 ;
10    C = sparse (rand (n)) ;
11    C (:,1) = sparse (rand (n,1) > 0.5) ;
12
13    ntrials = 10 ;
14
15    for k = 1:2:ntrials
16
17        % make some zombies
18        Work (k).A = sprandn (n, n, 0.1) ;
19        Work (k).I = [ ] ;
20        Work (k).J = [ ] ;
21        Work (k).Mask = sparse (ones (n)) ;
22        Work (k).accum = [ ] ;
23        Work (k).desc = [ ] ;
24        Work (k).scalar = 0 ;
25
26        % scalar expansion
27        Work (k+1).A = sparse (pi) ;
28        Work (k+1).I = uint64 (irand (1, n, n, 1) - 1) ;
29        Work (k+1).J = uint64 (irand (1, n, n, 1) - 1) ;
30        Work (k+1).Mask = sparse (ones (n)) ;
31        Work (k+1).accum = [ ] ;
32        Work (k+1).desc = [ ] ;
33        Work (k+1).scalar = 1 ;
34    end
35
36    C1 = GB_mex_assign  (C, Work) ;
37
38    C2 = C ;
39    for k = 1:ntrials
40        M = Work (k).Mask ;
41        A = Work (k).A ;
42        I = double (Work (k).I + 1) ;
43        J = double (Work (k).J + 1) ;
44        scalar = Work (k).scalar ;
45        C2 = GB_spec_subassign (C2, M, [ ], A, I, J, [ ], scalar) ;
46    end
47
48    GB_spec_compare (C1, C2) ;
49
50    for C_sparsity = [2 4]
51        for M_sparsity = [2 4]
52            C1 = GB_mex_assign (C, Work, [C_sparsity M_sparsity]) ;
53            GB_spec_compare (C1, C2) ;
54        end
55    end
56
57fprintf ('\ntest115: all tests passed\n') ;
58
59