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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
function test142
%TEST142 test GrB_assign for dense matrices
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
[binops, ~, ~, types, ~, ~] = GB_spec_opsall ;
binops = binops.all ;
types = types.all ;
fprintf ('test142 ------------ GrB_assign with dense matrices\n') ;
m = 10 ;
n = 12 ;
rng ('default') ;
M = sprand (m, n, 0.5) ;
Amat2 = sparse (2 * rand (m,n)) ;
Bmat2 = sparse (2 * sprand (m,n, 0.5)) ;
Cmat2 = sparse (2 * rand (m,n)) ;
Amat = 50 * Amat2 ;
Bmat = 50 * Bmat2 ;
Cmat = 50 * Cmat2 ;
Smat = sparse (m,n) ;
Xmat = sparse (pi) ;
desc.mask = 'structural' ;
drep.outp = 'replace' ;
A.matrix = Amat ; A.class = 'see below' ;
B.matrix = Bmat ; B.class = 'see below' ;
C.matrix = Cmat ; C.class = 'see below' ;
S.matrix = Smat ; S.class = 'see below' ;
X.matrix = Xmat ; X.class = 'see below' ;
Bmask = logical (Bmat) ;
for k1 = 1:length (types)
type = types {k1} ;
fprintf ('%s ', type) ;
A.class = type ;
for k3 = 1:3
if (k3 == 1)
X.class = type ;
B.class = type ;
C.class = 'logical' ;
S.class = 'logical' ;
elseif (k3 == 2)
X.class = type ;
B.class = type ;
C.class = type ;
S.class = type ;
else
X.class = 'int8' ;
B.class = 'int8' ;
C.class = type ;
S.class = type ;
end
%---------------------------------------
% C<M> = A where A is dense
%---------------------------------------
C0 = GB_spec_assign (C, M, [ ], A, [ ], [ ], [ ], false) ;
C1 = GB_mex_assign (C, M, [ ], A, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<M> = B where B is sparse
%---------------------------------------
C0 = GB_spec_assign (C, M, [ ], B, [ ], [ ], [ ], false) ;
C1 = GB_mex_assign (C, M, [ ], B, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<M> = A where A is dense and C starts empty
%---------------------------------------
C0 = GB_spec_assign (S, M, [ ], A, [ ], [ ], desc, false) ;
C1 = GB_mex_assign (S, M, [ ], A, [ ], [ ], desc) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<B> = B where B is sparse
%---------------------------------------
C0 = GB_spec_assign (C, Bmask, [ ], B, [ ], [ ], desc, false) ;
C1 = GB_mex_assign_alias_mask (C, B, desc) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<M> = x where C is dense
%---------------------------------------
C0 = GB_spec_assign (C, M, [ ], X, [ ], [ ], [ ], true) ;
C1 = GB_mex_assign (C, M, [ ], X, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<M> = x where C is dense
%---------------------------------------
C0 = GB_spec_assign (C, M, [ ], X, [ ], [ ], desc, true) ;
C1 = GB_mex_assign (C, M, [ ], X, [ ], [ ], desc) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<M,struct> = x
%---------------------------------------
C0 = GB_spec_assign (S, M, [ ], X, [ ], [ ], desc, true) ;
C1 = GB_mex_assign (S, M, [ ], X, [ ], [ ], desc) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C = x
%---------------------------------------
C0 = GB_spec_assign (S, [ ], [ ], X, [ ], [ ], [ ], true) ;
C1 = GB_mex_assign (S, [ ], [ ], X, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1) ;
%---------------------------------------
% with accum operators
%---------------------------------------
for k2 = 1:length(binops)
binop = binops {k2} ;
tol = 0 ;
switch (binop)
case { 'pow', 'atan2', 'hypot', 'remainder' }
A.matrix = Amat2 ;
B.matrix = Bmat2 ;
C.matrix = Cmat2 ;
if (test_contains (type, 'single'))
tol = 1e-5 ;
elseif (test_contains (type, 'double'))
tol = 1e-12 ;
end
otherwise
A.matrix = Amat ;
B.matrix = Bmat ;
C.matrix = Cmat ;
end
accum.opname = binop ;
accum.optype = type ;
try
GB_spec_operator (accum) ;
catch
continue
end
if (GB_spec_is_positional (accum))
continue ;
end
%---------------------------------------
% C += A where A is dense
%---------------------------------------
C0 = GB_spec_assign (C, [ ], accum, A, [ ], [ ], [ ], false) ;
C1 = GB_mex_assign (C, [ ], accum, A, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1, 0, tol) ;
%---------------------------------------
% C += B where B is sparse
%---------------------------------------
C0 = GB_spec_assign (C, [ ], accum, B, [ ], [ ], [ ], false) ;
C1 = GB_mex_assign (C, [ ], accum, B, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1, 0, tol) ;
%---------------------------------------
% C += x
%---------------------------------------
C0 = GB_spec_assign (C, [ ], accum, X, [ ], [ ], [ ], true) ;
C1 = GB_mex_assign (C, [ ], accum, X, [ ], [ ], [ ]) ;
GB_spec_compare (C0, C1, 0, tol) ;
%---------------------------------------
% C<replace> += x
%---------------------------------------
C0 = GB_spec_assign (C, [ ], accum, X, [ ], [ ], drep, true) ;
C1 = GB_mex_subassign (C, [ ], accum, X, [ ], [ ], drep) ;
GB_spec_compare (C0, C1, 0, tol) ;
end
end
end
fprintf ('\ntest142: all tests passed\n') ;
|