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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
function test90
%TEST90 test AxB with user-defined semirings: plus_rdiv and plus_rdiv2
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('\n -------------- A*B plus_rdiv (user-defined semiring)\n') ;
GrB.burble (1) ;
% 1001: Gustavson
% 1003: dot
% 1004: hash
% 1005: saxpy
rng ('default') ;
for N = [10 100] % 1000]
% create the problem
A = sprand (4*N, 5*N, 0.01) ;
B = sprand (5*N, 3*N, 0.01) ;
[i j x] = find (A) ;
[m n] = size (A) ;
X = sparse (i, j, 1./x, m, n) ;
clear i j x
C1 = X*B ;
C2 = GB_mex_rdiv (A, B) ;
assert (norm (C1-C2,1) / norm (C1,1) < 1e-10) ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
cprint = (N <= 10) ;
C2 = GB_mex_rdiv (A, B, method, cprint) ;
assert (norm (C1-C2,1) / norm (C1,1) < 1e-10) ;
end
% try rdiv2, which typecasts B to single precision first
C3 = GB_mex_rdiv2 (A, B) ;
assert (norm (C1-C3,1) / norm (C1,1) < 1e-5) ;
[i j x] = find (B) ;
[m n] = size (B) ;
Y = sparse (i, j, 1./x, m, n) ;
C4 = A*Y ;
% try rdiv2, with flipxy, which inverts A instead of B
C5 = GB_mex_rdiv2 (A, B, false, false, 0, 1) ;
assert (norm (C4-C5,1) / norm (C4,1) < 1e-5) ;
%--------------------------------------------------------------------------
% fprintf ('\nextensive tests:\n') ;
A = sprand (n, n, 0.01) ;
B = sprand (n, n, 0.01) ;
[i j x] = find (A) ;
X = sparse (i, j, 1./x, n, n) ;
[i j x] = find (B) ;
Y = sparse (i, j, 1./x, n, n) ;
flipxy = 0 ;
at = 0 ;
bt = 0 ;
C0 = X*B ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 0 ;
at = 1 ;
bt = 0 ;
C0 = X'*B ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 0 ;
at = 0 ;
bt = 1 ;
C0 = X*B' ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 0 ;
at = 1 ;
bt = 1 ;
C0 = X'*B' ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 1 ;
at = 0 ;
bt = 0 ;
C0 = A*Y ;
for method = [1001 1003 1004 1005]
fprintf ('method: %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 1 ;
at = 1 ;
bt = 0 ;
C0 = A'*Y ;
for method = [1001 1003 1004 1005]
fprintf ('method %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 1 ;
at = 0 ;
bt = 1 ;
C0 = A*Y' ;
for method = [1001 1003 1004 1005]
fprintf ('method %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
flipxy = 1 ;
at = 1 ;
bt = 1 ;
C0 = A'*Y' ;
for method = [1001 1003 1004 1005]
fprintf ('method %d\n', method) ;
C5 = GB_mex_rdiv2 (A, B, at, bt, method, flipxy) ;
assert (norm (C0-C5,1) / norm (C5,1) < 1e-5) ;
end
end
GrB.burble (0) ;
fprintf ('\ntest90: all tests passed\n') ;
|