1function test08
2%TEST08 test GxB_subassign
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7rng ('default') ;
8C = sparse (rand (5,4)) ;
9A = 100 * sparse (magic (2)) ;
10
11I = [2 3] ;
12J = [3 4] ;
13
14C2 = C ;
15C2 (I,J) = A  ;
16
17% full (C)
18% full (C2)
19
20I0 = uint64 (I-1) ;
21J0 = uint64 (J-1) ;
22
23C3 = GB_mex_subassign (C, [ ], '', A, I0, J0, [ ]) ;
24% C3.matrix
25% full (C3.matrix)
26assert (isequal (C3.matrix, C2))
27
28
29C = sparse ([1 2 ;
30             0 3]) ;
31A = sparse (11) ;
32I0 = uint64 (1) ;
33J0 = uint64 (0) ;
34C3 = GB_mex_subassign (C, [ ], '', A, I0, J0, [ ]) ;
35C2 = C ;
36C2 (2,1) = 11 ;
37
38
39C = sparse (rand (4)) ;
40A = sparse (0) ;
41C2 = C ;
42C2 (1,1) = A ;
43C3 = GB_mex_subassign (C, [ ], '', A, uint64(0), uint64(0), [ ]) ;
44assert (isequal (C3.matrix, C2))
45
46w = load ('../Demo/Matrix/west0067') ;
47A = sparse (w (:,1)+1, w (:,2)+1, w (:,3)) ;
48
49[m n] = size (A) ;
50
51for trial = 1:1000
52
53    % fprintf ('.') ;
54
55    ni = max (1, floor (m * rand (1)))  ;
56    nj = max (1, floor (n * rand (1)))  ;
57    % ni = 3 ;
58    % nj = 3 ;
59    I = randperm (m) ;
60    I = I (1:ni) ;
61    J = randperm (n) ;
62    J = J (1:nj) ;
63
64    I0 = uint64 (I-1) ;
65    J0 = uint64 (J-1) ;
66
67    B = sprandn (ni, nj, 0.1) ;
68
69    C1 = A ;
70    C1 (I,J) = B ;
71
72    C2 = GB_mex_subassign (A, [ ], '', B, I0, J0, [ ]) ;
73
74    assert (isequal (C2.matrix, C1)) ;
75
76end
77
78fprintf ('\ntest08: all tests passed\n') ;
79
80