File: gbtest11.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 (119 lines) | stat: -rw-r--r-- 2,660 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function gbtest11
%GBTEST11 test GrB, sparse

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

rng ('default') ;
A = 100 * rand (4) ;
A (1,1:2) = 0 %#ok<*NOPRT>
S = sparse (A)

  x1 = GrB (S)
  x2 = full (x1)
  x3 = double (x2)
  assert (gbtest_eq (S, x3))

% assert (gbtest_eq (S, double (full (GrB (S)))))

  x1 = GrB (S)
  x2 = full (x1)
  x3 = full (x2)
  x4 = double (x3)
  assert (gbtest_eq (S, x4))

% assert (gbtest_eq (S, double (full (full (GrB (S))))))

assert (gbtest_eq (S, double (full (double (full (GrB (S)))))))

S2 = double (GrB (full (double (full (GrB (S))))))
assert (norm (S-S2,1) == 0)
% S2 = 1*S2 ;
assert (gbtest_eq (S, S2))

S2 = double (GrB (double (GrB (full (double (full (GrB (S))))))))
assert (gbtest_eq (S, S2))

S = logical (S) ;
assert (gbtest_eq (S, full (GrB (S))))

X = int8 (A)
G = GrB (X)
assert (gbtest_eq (X, full (int8 (G))))
assert (gbtest_eq (X, int8 (full (G))))

X = int16 (A)
G = GrB (X)
assert (gbtest_eq (X, full (int16 (G))))
assert (gbtest_eq (X, int16 (full (G))))

X = int32 (A)
G = GrB (X)
assert (gbtest_eq (X, full (int32 (G))))
assert (gbtest_eq (X, int32 (full (G))))

X = int64 (A)
G = GrB (X)
assert (gbtest_eq (X, full (int64 (G))))
assert (gbtest_eq (X, int64 (full (G))))

X = uint8 (A)
G = GrB (X)
assert (gbtest_eq (X, full (uint8 (G))))
assert (gbtest_eq (X, uint8 (full (G))))

X = uint16 (A)
G = GrB (X)
assert (gbtest_eq (X, full (uint16 (G))))
assert (gbtest_eq (X, uint16 (full (G))))

X = uint32 (A)
G = GrB (X)
assert (gbtest_eq (X, full (uint32 (G))))
assert (gbtest_eq (X, uint32 (full (G))))

X = uint64 (A)
G = GrB (X)
full (G)
assert (gbtest_eq (X, full (uint64 (G))))
assert (gbtest_eq (X, uint64 (full (G))))

B = 100 * rand (4) ;
B (1,[1 3]) = 0 ;

have_octave = gb_octave ;
X = complex (A)
G = GrB (X)
if (have_octave)
    % the octave7, full(...) function converts its result to real if the
    % imaginary part is zero, but MATLAB and GraphBLAS return as complex.
    assert (gbtest_eq (X, G)) ;
else
    assert (gbtest_eq (X, full (complex (G))))
    assert (gbtest_eq (X, complex (full (G))))
end

X = complex (A,B)
G = GrB (X)
assert (gbtest_eq (X, full (complex (G))))
assert (gbtest_eq (X, complex (full (G))))

X = rand (4) ;
Y = GrB (X) ;
Z = sparse (Y) ;
W = sparse (Z) ;
assert (gbtest_eq (X, Z)) ;
assert (gbtest_eq (X, Y)) ;
assert (gbtest_eq (X, W)) ;

S = struct (Y) ;
Z = GrB (S) ;
assert (gbtest_eq (Z, Y)) ;

assert (GrB.isfull (Z)) ;
assert (GrB.isfull (double (Z))) ;
assert (~GrB.isfull (speye (3))) ;
assert (~GrB.isfull (GrB (speye (3)))) ;

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