1function test82
2%TEST82 test GrB_Matrix_extract with index range (hypersparse)
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test82: test GrB_Matrix_extract with index range (hypersparse)\n') ;
8
9rng ('default') ;
10
11n = 100 ;
12A = GB_spec_random (n, n, 0.02, 100, 'double', true, true) ;
13
14I.begin = 0 ;
15I.inc = 0 ;
16I.end = 0 ;
17
18J.begin = 0 ;
19J.end = 9 ;
20
21C1 = A.matrix (1:0:1, 1:10) ;
22S = sparse (0,10) ;
23C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, I, J, [ ]) ;
24
25assert (isequal (C1, C2.matrix)) ;
26
27C1 = A.matrix (1:10, 1:0:1) ;
28S = sparse (10,0) ;
29C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, J, I, [ ]) ;
30assert (isequal (C1, C2.matrix)) ;
31
32for k = 1:n
33    K.begin = k-1 ;
34    K.inc = 1 ;
35    K.end = k-1 ;
36    C1 = A.matrix (1:10, k) ;
37    S = sparse (10,1) ;
38    C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, J, K, [ ]) ;
39    assert (isequal (C1, C2.matrix)) ;
40end
41
42B = GB_spec_random (n, n, 0.2, 100, 'double', true, true) ;
43
44% I not contiguous, with duplicates, but no sort needed
45I1 = [1 3 4 30 30 50 50 50 99 99 99 100] ;
46I0 = uint64 (I1) - 1 ;
47ni = length (I1) ;
48S = sparse (ni,1) ;
49
50for j = 1:n
51    C1 = B.matrix (I1, j) ;
52    J0 = uint64 (j)-1 ;
53    C2 = GB_mex_Matrix_extract (S, [ ], [ ], B, I0, J0, [ ]) ;
54    assert (isequal (C1, C2.matrix)) ;
55end
56
57% A hypersparse, but C is not.
58d = sum (spones (A.matrix)) ;
59j = find (d > 0, 1, 'first') ;
60
61nJ = 1000 ;
62J1 = j * ones (1, nJ) ;
63J0 = uint64 (J1) - 1 ;
64
65C1 = A.matrix (:, J1) ;
66S = sparse (n, nJ) ;
67C2 = GB_mex_Matrix_extract (S, [ ], [ ], A, [ ], J0, [ ]) ;
68assert (isequal (C1, C2.matrix)) ;
69
70fprintf ('\ntest82: all tests passed\n') ;
71
72
73