1function test132
2%TEST132 test GrB_*_setElement and GrB_*_*build
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7% simplified from test45
8
9fprintf ('\ntest132 ------------------ testing GrB_setElement and _build\n') ;
10
11% debug_on ;
12
13rng ('default') ;
14A = sparse (rand (3,2)) ;
15
16C = GB_mex_setElement (A, uint64(0), uint64(0), 42.1, true) ;
17
18A = rand (3,2) ;
19A (2,2) = 0 ;
20A = sparse (A)  ;
21
22C = GB_mex_setElement (A, uint64(1), uint64(1), 99, true) ;
23GB_spok (C.matrix) ;
24
25A = sprand (67, 67, 0.1) ;
26
27[m n] = size (A) ;
28
29ntuples = 1000 ;
30A1 = A ;
31I = 1 + floor (m * rand (ntuples, 1)) ;
32J = 1 + floor (n * rand (ntuples, 1)) ;
33X = 100 * rand (ntuples, 1) ;
34I0 = uint64 (I)-1 ;
35J0 = uint64 (J)-1 ;
36
37for k = 1:ntuples
38    A1 (I (k), J (k)) =  X (k) ;
39end
40
41A2 = A ;
42A3 = GB_mex_setElement (A2, I0, J0, X, true) ;
43assert (GB_spok (A3.matrix) == 1)
44
45assert (isequal (A3.matrix, A1)) ;
46
47ntuples = 10 ;
48I = (m * ones (ntuples, 1)) ;
49J = (n * ones (ntuples, 1)) ;
50I0 = uint64 (I)-1 ;
51J0 = uint64 (J)-1 ;
52X = pi * ones (ntuples, 1) ;
53
54A (m,n) = 0 ;
55A (:, 5:67) = 0 ;
56
57A1 = A ;
58for k = 1:ntuples
59    A1 (I (k), J (k)) =  X (k) ;
60end
61
62clear A2
63A2.matrix = A ;
64A2.is_hyper = true ;
65A3 = GB_mex_setElement (A2, I0, J0, X, true) ;
66assert (GB_spok (A3.matrix) == 1)
67assert (isequal (A3.matrix, A1)) ;
68
69fprintf ('\ntest132: all tests passed\n') ;
70
71