1function test148 2%TEST148 eWiseAdd with aliases 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('test148 ---------------eWiseAdd with alias\n') ; 8 9rng ('default') ; 10 11n = 5 ; 12C = sprand (n, n, 0.5) ; 13A = sprand (n, n, 0.5) ; 14M = sprand (n, n, 0.5) ; 15 16C0 = C + A + A ; 17C1 = GB_mex_Matrix_eWiseAdd (C, [ ], 'plus', 'plus', A, A, [ ]) ; 18assert (norm (C0 - C1.matrix, 1) < 1e-12) ; 19 20C2 = GB_mex_ewise_alias2 (C, 'plus', A, [ ]) ; 21assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 22 23C0 = C + A ; 24C2 = GB_mex_ewise_alias1 (C, 'plus', A, [ ]) ; 25assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 26 27C2 = GB_mex_ewise_alias3 (C, 'plus', A, [ ]) ; 28assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 29 30C = sparse (rand (n)) ; 31A = sparse (rand (n)) ; 32 33C0 = C + A + A ; 34C1 = GB_mex_Matrix_eWiseAdd (C, [ ], 'plus', 'plus', A, A, [ ]) ; 35assert (norm (C0 - C1.matrix, 1) < 1e-12) ; 36 37C2 = GB_mex_ewise_alias2 (C, 'plus', A, [ ]) ; 38assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 39 40C0 = C + A ; 41C2 = GB_mex_ewise_alias1 (C, 'plus', A, [ ]) ; 42assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 43 44C2 = GB_mex_ewise_alias3 (C, 'plus', A, [ ]) ; 45assert (norm (C0 - C2.matrix, 1) < 1e-12) ; 46 47desc = struct ('mask', 'structural') ; 48 49C1 = GB_mex_Matrix_eWiseAdd (C, M, [ ], 'plus', M, M, desc) ; 50C2 = GB_mex_ewise_alias4 (C, M, 'plus', desc) ; 51assert (norm (C1.matrix - C2.matrix, 1) < 1e-12) ; 52 53M = sparse (true (n)) ; 54C1 = GB_mex_Matrix_eWiseAdd (C, M, [ ], 'plus', M, M, desc) ; 55C2 = GB_mex_ewise_alias4 (C, M, 'plus', desc) ; 56assert (norm (C1.matrix - C2.matrix, 1) < 1e-12) ; 57 58% #define USAGE "C = GB_mex_ewise_alias5 (C, M, op, A, desc)" 59 60C1 = GB_mex_Matrix_eWiseAdd (C, M, [ ], 'plus', A, M, desc) ; 61C2 = GB_mex_ewise_alias5 (C, M, 'plus', A, desc) ; 62assert (norm (C1.matrix - C2.matrix, 1) < 1e-12) ; 63 64% C<M> = A+M 65A = sparse (rand (n)) ; 66M = sprand (n, n, 0.05) ; 67C1 = GB_mex_Matrix_eWiseAdd (C, M, [ ], 'plus', A, M, desc) ; 68C2 = GB_mex_ewise_alias5 (C, M, 'plus', A, desc) ; 69assert (norm (C1.matrix - C2.matrix, 1) < 1e-12) ; 70 71% C<M> = M+A 72C1 = GB_mex_Matrix_eWiseAdd (C, M, [ ], 'plus', M, A, desc) ; 73C2 = GB_mex_ewise_alias6 (C, M, 'plus', A, desc) ; 74assert (norm (C1.matrix - C2.matrix, 1) < 1e-12) ; 75 76fprintf ('test148: all tests passed\n') ; 77