1function test17
2%TEST17 test GrB_*_extractElement
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\n ------------ testing GrB_extractElement\n') ;
8
9[~, ~, ~, types, ~, ~] = GB_spec_opsall ;
10types = types.all ;
11
12rng ('default') ;
13
14% type of the output X
15for k1 = 1:length (types)
16    xtype = types {k1}  ;
17    fprintf ('\n%-14s ', xtype) ;
18
19    % type of the matrix A
20    for k2 = 1:length (types)
21        atype = types {k2}  ;
22        fprintf ('.') ;
23
24        % create a matrix
25        for m = [1 10] % [1 10 25 50]
26            for n = [1 10] % [1 10 25 50]
27                clear A
28                A.matrix = 100 * sprandn (m, n, 0.1) ;
29                A.matrix (1,1) = pi ;
30                A.class = atype ;
31
32                clear B
33                B.matrix = 100 * sprandn (m*n, 1, 0.1) ;
34                B.matrix (1,1) = sparse (0) ;
35                B.class = atype ;
36
37                for A_is_hyper = 0:1
38                for A_is_csc   = 0:1
39                A.is_hyper = A_is_hyper ;
40                A.is_csc   = A_is_csc   ;
41                for i = 0:m-1
42                    iu = uint64 (i) ;
43                    for j = 0:n-1
44                        ju = uint64 (j) ;
45                        x1 = GB_mex_Matrix_extractElement  (A, iu, ju, xtype) ;
46                        x2 = GB_spec_Matrix_extractElement (A, i, j, xtype) ;
47                        assert (isequal (x1,x2))
48                    end
49                end
50                end
51                end
52
53                for i = 0:(m*n)-1
54                    iu = uint64 (i) ;
55                    x1 = GB_mex_Vector_extractElement  (B, iu, xtype) ;
56                    x2 = GB_spec_Vector_extractElement (B, i, xtype) ;
57                    assert (isequal (x1,x2))
58                end
59            end
60        end
61    end
62end
63
64fprintf ('\ntest17: all tests passed\n') ;
65
66