File: test132.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 (75 lines) | stat: -rw-r--r-- 1,607 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
function test132
%TEST132 test GrB_*_setElement and GrB_*_*build

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

% simplified from test45

fprintf ('\ntest132 ------------------ testing GrB_setElement and _build\n') ;

% debug_on ;

rng ('default') ;
A = sparse (rand (3,2)) ;

C = GB_mex_setElement (A, uint64(0), uint64(0), 42.1, true) ;

A = rand (3,2) ;
A (2,2) = 0 ;
A = sparse (A)  ;

C = GB_mex_setElement (A, uint64(1), uint64(1), 99, true) ;
GB_spok (C.matrix) ;

A = sprand (67, 67, 0.1) ;

[m n] = size (A) ;

ntuples = 1000 ;
C1 = A ;
I = 1 + floor (m * rand (ntuples, 1)) ;
J = 1 + floor (n * rand (ntuples, 1)) ;
X = 100 * rand (ntuples, 1) ;
I0 = uint64 (I)-1 ;
J0 = uint64 (J)-1 ;

for k = 1:ntuples
    C1 (I (k), J (k)) =  X (k) ;
end

A2 = A ;
C3 = GB_mex_setElement (A2, I0, J0, X, true) ;
C4 = GB_mex_setElement (A2, I0, J0, X, true, true) ;
assert (GB_spok (C3.matrix) == 1)
assert (GB_spok (C4.matrix) == 1)

assert (isequal (C3.matrix, C1)) ;
assert (isequal (C4.matrix, C1)) ;

ntuples = 10 ;
I = (m * ones (ntuples, 1)) ;
J = (n * ones (ntuples, 1)) ;
I0 = uint64 (I)-1 ;
J0 = uint64 (J)-1 ;
X = pi * ones (ntuples, 1) ;

A (m,n) = 0 ;
A (:, 5:67) = 0 ;

C1 = A ;
for k = 1:ntuples
    C1 (I (k), J (k)) =  X (k) ;
end

clear A2
A2.matrix = A ;
A2.is_hyper = true ;
C3 = GB_mex_setElement (A2, I0, J0, X, true) ;
C4 = GB_mex_setElement (A2, I0, J0, X, true) ;
assert (GB_spok (C3.matrix) == 1)
assert (isequal (C3.matrix, C1)) ;
assert (isequal (C4.matrix, C1)) ;

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