File: gbtest7.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 (86 lines) | stat: -rw-r--r-- 1,846 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
84
85
86
function gbtest7
%GBTEST7 test GrB.build

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

rng ('default') ;

n = 5 ;
A = sprand (n, n, 0.5) ;
A (n,n) = 5 ;

[i, j, x] = find (A) ;
[m, n] = size (A) ;

G = GrB.build (i, j, x, m, n) ;
S = sparse   (i, j, x, m, n) ;
assert (gbtest_eq (S, G)) ;

G = GrB.build (i, j, x, m, n, '') ;
assert (gbtest_eq (S, G)) ;

G = GrB.build (i, j, x, m, n, 'ignore') ;
assert (gbtest_eq (S, G)) ;

% add some duplicates
ii = [i ; i] ;
jj = [j ; j] ;
xx = [x ; 2*x] ;
ok = false ;
try
    % no duplicates are tolerated
    G = GrB.build (ii, jj, xx, m, n, '') ;
catch
    ok = true ;
end
assert (ok) ;

% duplicates are ignored
G = GrB.build (ii, jj, xx, m, n, 'ignore') ;
assert (gbtest_eq (2*S, G)) ;

% duplicates are summed
G = GrB.build (ii, jj, xx, m, n) ;
assert (gbtest_eq (3*S, G)) ;

d.kind = 'GrB' ;
G = GrB.build (i, j, x, m, n, d) ;
assert (gbtest_eq (S, G)) ;

d.kind = 'sparse' ;
G = GrB.build (i, j, x, m, n, d) ;
assert (gbtest_eq (S, G))

i0 = int64 (i) - 1 ;
j0 = int64 (j) - 1 ;

G = GrB.build (i0, j0, x, struct ('base', 'zero-based')) ;
assert (gbtest_eq (S, G)) ;

G = GrB.build (1:3, 1:3, [1 1 1]) ;
assert (gbtest_eq (speye (3), G)) ;

G = GrB.build (1, 1, [1 2 3]) ;
assert (isequal (sparse (6), G)) ;

G = GrB.build (1:3, 1:3, 1) ;
assert (isequal (speye (3), G)) ;

types = gbtest_types ;
for k = 1: length(types)
    type = types {k} ;
    X = gbtest_cast (1, type) ;
    G = GrB.build (1:3, 1:3, X) ;
    S = gbtest_cast (eye (3, 3), type) ;
    assert (gbtest_eq (S, G)) ;
    assert (isequal (GrB.type (G), type)) ;

    % build an iso matrix
    G = GrB.build (1:3, 1:3, X, 3, 3, '1st') ;
    assert (gbtest_eq (S, G)) ;
    assert (isequal (GrB.type (G), type)) ;
end

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