1function test63 2%TEST63 test GraphBLAS binary operators 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7[binops, ~, ~, types, ~, ~] = GB_spec_opsall ; 8ops = binops.all ; 9types = types.all ; 10 11fprintf ('\n ---------------------------- testing GB_mex_op\n') ; 12 13rng ('default') ; 14 15n_operators = 0 ; 16for k2 = 1:length(ops) 17 mulop = ops {k2} ; 18 if (GB_spec_is_positional (mulop)) 19 continue 20 end 21 fprintf ('\n%-10s ', mulop) ; 22 23 for k1 = 1:length (types) 24 type = types {k1} ; 25 26 % create the op 27 clear op 28 op.opname = mulop ; 29 op.optype = type ; 30 31 try 32 GB_spec_operator (op) ; 33 catch 34 continue ; 35 end 36 37 switch (mulop) 38 case { 'pow' } 39 xlimits = [0, 5] ; 40 ylimits = [0, 5] ; 41 case { 'ldexp' } 42 xlimits = [-5, 5] ; 43 ylimits = [-5, 5] ; 44 otherwise 45 xlimits = [ ] ; 46 ylimits = [ ] ; 47 end 48 49 if (contains (type, 'single')) 50 tol = 1e-5 ; 51 elseif (contains (type, 'double')) 52 tol = 1e-12 ; 53 else 54 tol = 0 ; 55 end 56 57 fprintf ('.') ; 58 59 for m = [ 1:3:10 ]% 100] 60 for n = [1:3:10 ]% 100] 61 for hi = [-1:5 200] 62 for lo = [-3:5 100] 63 A = full ((hi*sprand (m,n,0.8)-lo) .* sprand (m,n,0.5)); 64 B = full ((hi*sprand (m,n,0.8)-lo) .* sprand (m,n,0.5)); 65 66 if (~isempty (xlimits)) 67 A = max (A, xlimits (1)) ; 68 A = min (A, xlimits (2)) ; 69 end 70 if (~isempty (ylimits)) 71 B = max (B, ylimits (1)) ; 72 B = min (B, ylimits (2)) ; 73 end 74 75 % use pure GraphBLAS 76 Z1 = GB_mex_op (op, A, B) ; 77 % use MATLAB as much as possible 78 Z2 = GB_spec_op (op, A, B) ; 79 % the results should either match perfectly 80 assert (isequal (isnan (Z1), isnan (Z2))) 81 assert (isequal (isfinite (Z1), isfinite (Z2))) 82 if (isequalwithequalnans (Z1, Z2)) 83 continue ; 84 else 85 % ... or within roundoff error 86 mask = isfinite (Z1) ; 87 err = norm (Z1 (mask) - Z2 (mask), inf) ; 88 err = err / max (1, norm (Z1 (mask), inf)) ; 89 assert (err < tol) ; 90 end 91 end 92 end 93 end 94 end 95 n_operators = n_operators + 1 ; 96 end 97end 98 99fprintf ('\nall tests passed\n') ; 100 101fprintf ('Number of built-in GraphBLAS operators: %d\n', n_operators) ; 102 103fprintf ('\ntest63: all tests passed\n') ; 104 105