1function testc2(quick) 2%TESTC2 test complex A*B, A'*B, A*B', A'*B', A+B 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7rng ('default') ; 8 9if (nargin < 1) 10 quick = 0 ; 11end 12if (quick) 13 nlist = [1 4] ; 14else 15 nlist = [1 5 10 100] ; 16end 17 18maxerr = 0 ; 19for m = nlist 20 for n = nlist 21 for k = nlist 22 A = GB_mex_random (k, m, m*5, 1, 1) ; 23 B = GB_mex_random (k, n, n*5, 1, 2) ; 24 C = GB_mex_AdotB (A, B) ; 25 C2 = A'*B ; 26 err = norm (C-C2,1) ; 27 maxerr = max (maxerr, err) ; 28 assert (err < 1e-12) 29 end 30 end 31end 32fprintf ('All complex A''*B tests passed, maxerr %g\n', maxerr) ; 33 34maxerr = 0 ; 35for m = nlist 36 for n = nlist 37 A = GB_mex_random (m, n, m*5, 1, 1) ; 38 B = GB_mex_random (m, n, n*5, 1, 2) ; 39 C = GB_mex_AplusB (A, B, 'plus') ; 40 C2 = A + B ; 41 err = norm (C-C2,1) ; 42 maxerr = max (maxerr, err) ; 43 assert (err < 1e-12) 44 end 45end 46fprintf ('All complex A+B tests passed, maxerr %g\n', maxerr) ; 47 48semiring.multiply = 'times' ; 49semiring.add = 'plus' ; 50semiring.class = 'complex' ; 51dtn.inp0 = 'tran' ; 52 53anum = [0 1001 1003 1004] ; 54algos = {'auto', 'gustavson', 'dot', 'hash'} ; 55 56seed = 1 ; 57 58maxerr = 0 ; 59for m = nlist 60 for n = nlist 61 for k = nlist 62 for at = 0:1 63 for bt = 0:1 64 if (at) 65 A = GB_mex_random (k, m, m*5, 1, seed) ; 66 else 67 A = GB_mex_random (m, k, m*5, 1, seed) ; 68 end 69 seed = seed + 1 ; 70 if (bt) 71 B = GB_mex_random (n, k, m*5, 1, seed) ; 72 else 73 B = GB_mex_random (k, n, m*5, 1, seed) ; 74 end 75 seed = seed + 1 ; 76 77 if (m == 100 & k > 3 & n > 3) 78 na = size (A,1) ; 79 A (:,1) = 1i * rand (na,1) ; 80 A (:,2:3) = 0 ; 81 A (1,3) = 1 ; 82 nb = size (B,2) ; 83 B (1,:) = 1i * rand (1,nb) ; 84 B (:,2:3) = 0 ; 85 B (2,3) = 4 ; 86 end 87 88 for aa = 1:length(algos) 89 90 C = GB_mex_AxB (A, B, at, bt, anum (aa)) ; 91 92 desc = struct ; 93 if (at) 94 desc.inp0 = 'tran' ; 95 end 96 if (bt) 97 desc.inp1 = 'tran' ; 98 end 99 desc.algo = algos {aa} ; 100 101 if (at) 102 if (bt) 103 C2 = A'*B' ; 104 else 105 C2 = A'*B ; 106 end 107 else 108 if (bt) 109 C2 = A*B' ; 110 else 111 C2 = A*B ; 112 end 113 end 114 err = norm (C-C2,1) ; 115 maxerr = max (maxerr, err) ; 116 assert (err < 1e-12) 117 118 end 119 120 if (at && ~bt) 121 M = sparse (m, n) ; 122 M(1,1) = 1 ; 123 C2 = GB_mex_AdotB (A, B, M, false) ; 124 C3 = GB_mex_AdotB (A, B, M, true) ; 125 C0 = (A'*B) .* M ; 126 assert (norm (C0-C2,1) < 1e-12) ; 127 assert (norm (C0-C3,1) < 1e-12) ; 128 end 129 end 130 end 131 end 132 end 133end 134 135fprintf ('testc2: all complex A*B, A''*B, A*B'', A''*B'' tests passed, maxerr %g\n', maxerr) ; 136 137 138