1function testc1 2%TESTC1 test complex operators 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7rng 'default' 8 9A = sparse (rand (2) + 1i * rand (2)) ; 10C = GB_mex_dump (A,0) ; 11GB_spec_compare (C, A) ; 12 13B = sparse (rand (2) + 1i * rand (2)) ; 14 15A = full (A) ; 16B = full (B) ; 17 18C1 = GB_mex_op ('plus', A, B, 1) ; 19C2 = A+B ; 20 21assert (isequal (C1,C2)) ; 22 23E = rand (2) ; 24F = rand (2) ; 25 26C1 = GB_mex_op ('complex', E, F, 1) ; 27C2 = complex (E,F) ; 28assert (isequal (C1,C2)) ; 29 30[complex_binary complex_unary] = GB_user_opsall ; 31 32A (2,1) = B (2,1) ; 33 34% create some complex test matrices 35 36for m = [1 5 10 50 100 ] 37 for n = [ 1 5 10 50 100 ] 38 39 for akind = 1:5 40 switch (akind) 41 case 1 42 A = complex (zeros (m,n), 0) ; 43 case 2 44 A = complex (ones (m,n), 0) ; 45 case 3 46 A = complex (-ones (m,n), ones(m,n)) ; 47 case 4 48 x = full (sprand(m,n,0.3)) ; 49 y = full (sprand(m,n,0.3)) ; 50 A = complex (x,y) ; 51 case 5 52 A = complex (rand (m,n), rand (m,n)) ; 53 end 54 55 % test unary ops with complex x 56 for k = 1:length (complex_unary) 57 op = complex_unary {k} ; 58 C1 = GB_mex_op (op, A, '',1) ; 59 [C2 tol] = GB_user_op (op, A) ; 60 GB_complex_compare (C1, C2, tol) ; 61 end 62 63 for bkind = 1:6 64 switch (bkind) 65 case 1 66 B = complex (zeros (m,n), 0) ; 67 case 2 68 B = complex (ones (m,n), 0) ; 69 case 3 70 B = complex (-ones (m,n), ones(m,n)) ; 71 case 4 72 x = full (sprand(m,n,0.3)) ; 73 y = full (sprand(m,n,0.3)) ; 74 B = complex (x,y) ; 75 case 5 76 B = complex (rand (m,n), rand (m,n)) ; 77 case 6 78 B = A ; 79 end 80 81 % test all but the last one, 'complex', which requires 82 % x,y real 83 for k = 1:length (complex_binary)-1 84 op = complex_binary {k} ; 85 C1 = GB_mex_op (op, A, B, 1) ; 86 [C2 tol] = GB_user_op (op, A, B) ; 87 GB_complex_compare (C1, C2, tol) ; 88 end 89 90 % test complex(A,B) 91 C1 = GB_mex_op ('complex', real (A), real (B), 1) ; 92 C2 = GB_user_op ('complex', real (A), real (B)) ; 93 assert (isequal (C1, C2)) 94 95 end 96 end 97 end 98end 99 100fprintf ('testc1: all complex operator tests passed\n') ; 101 102