1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
function gbtest117
%GBTEST117 test idxunop in GrB.apply2
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
rng ('default') ;
m = 6 ;
n = 4 ;
A = GrB.random (m, n, 0.5) ;
[i,j,x] = find (A) ;
for k = -6:6
% tril j <= (i + thunk)
C1 = GrB.apply2 ('tril', A, k) ;
x = (j <= (i + k)) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% triu j >= (i + thunk)
C1 = GrB.apply2 ('triu', A, k) ;
x = (j >= (i + k)) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% diag j == (i + thunk)
C1 = GrB.apply2 ('diag', A, k) ;
x = (j == (i + k)) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% offdiag j != (i + thunk)
C1 = GrB.apply2 ('offdiag', A, k) ;
x = (j ~= (i + k)) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% diagindex j - (i + thunk)
C1 = GrB.apply2 ('diagindex', A, k) ;
x = int64 (j - (i + k)) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% rowindex i + thunk
C1 = GrB.apply2 ('rowindex', A, k) ;
x = int64 (i + k) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% rowle i <= thunk
C1 = GrB.apply2 ('rowle', A, k) ;
x = i <= k ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% rowgt i > thunk
C1 = GrB.apply2 ('rowgt', A, k) ;
x = i > k ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% colindex j + thunk
C1 = GrB.apply2 ('colindex', A, k) ;
x = int64 (j + k) ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% colle j <= thunk
C1 = GrB.apply2 ('colle', A, k) ;
x = j <= k ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
% colgt j > thunk
C1 = GrB.apply2 ('colgt', A, k) ;
x = j > k ;
C2 = GrB.build (i, j, x, m, n) ;
assert (isequal (C1, C2))
end
% diagindex j - (i + thunk)
C1 = GrB.apply2 ('diagindex', 0, 3) ;
assert (C1 == -3) ;
C1 = GrB.apply2 ('diagindex', 1, 0) ;
assert (C1 == 0) ;
fprintf ('gbtest117: all tests passed\n') ;
|