1function test55 2%TEST55 test GxB_subassign, illustrate duplicate indices, MATLAB vs GraphBLAS 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7% MATLAB and GraphBLAS differ on how repeated indices are handled 8% 9% MATLAB: last value, no accumulation 10% GraphBLAS: not defined, SuiteSparse:GraphBLAS accumulates 11 12A = magic (5) 13 14A ([2 2], [4 5]) 15 16B = [1000 800 ; 60000 2000 ] 17% B (1,1) = nan 18 19i = [2 2] 20j = [4 5] 21 22C1 = A ; 23C1 ([2 2], [4 5]) = A ([2 2], [4 5]) + B 24 25a = sparse (A) 26b = sparse (B) 27i0 = uint64 (i-1) 28j0 = uint64 (j-1) 29 30C2 = GB_mex_subassign (a, [], 'plus', b, i0, j0) 31 32C1 33full (C2.matrix) 34 35c = sparse ([ 1 2 3 4 5 ]) 36i = uint64 (0) 37j = uint64 ([ 0 0 4 ]) 38a = sparse ([ 10 100 1000]) 39e = GB_mex_subassign (c, [], 'plus', a, i, j) 40e = full (e.matrix) 41 42ac = accumarray (double (j+1)', full(a)')' 43e2 = c ; 44e2 (i+1, :) = e2 (i+1, :) + ac 45e2 = full (e2) 46 47e2 = c ; 48e2 (i+1,j+1) = e2 (i+1,j+1) + a 49e2 = full (e2) 50 51a = sparse ([ 1000 1000 1000]) 52e = GB_mex_subassign (c, [], 'plus', a, i, j) 53e = full (e.matrix) 54 55e2 = c ; 56e2 (i+1,j+1) = e2 (i+1,j+1) + a 57e2 = full (e2) 58 59 60e2 = c ; 61e2 (i+1,j+1) = e2 (i+1,j+1) + 1000 62e2 = full (e2) 63 64 65a = sparse ([ 1000 1000 1000]) 66e = GB_mex_subassign (c, [], '', a, i, j) 67e = full (e.matrix) 68 69e2 = c ; 70e2 (i+1,j+1) = a 71e2 = full (e2) 72 73e2 = c ; 74e2 (i+1,j+1) = 1000 75e2 = full (e2) 76 77fprintf ('\ntest55: all tests passed\n') ; 78 79