File: test173.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (73 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (3)
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
function test173
%TEST173 test GrB_assign C<A>=A

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

types = { 'logical', 'double', 'double complex' } ;

m = 10 ;
n = 14 ;

rng ('default') ;

desc.mask = 'structural' ;

for k = 1:length (types)

    ctype = types {k} ;
    fprintf ('%s, ', ctype) ;

    for d = [0.5 inf]

        C = GB_spec_random (m, n, d, 100, ctype) ;
        C = GB_spec_matrix (C) ;
        C.matrix = sparse (C.matrix) ;

        A = GB_spec_random (m, n, 0.5, 100, ctype) ;
        A.matrix = sparse (A.matrix) ;
        A_nonzero = full (A.matrix ~= 0) ;

        A_dense = GB_spec_random (m, n, inf, 100, ctype) ;
        A_dense = GB_spec_matrix (A_dense) ;
        A_dense.matrix = sparse (A_dense.matrix) ;
        A_dense_nonzero = full (A_dense.matrix ~= 0) ;

        for C_sparsity = 1:15
            C.sparsity = C_sparsity ;

            for A_sparsity = 1:15
                A.sparsity = A_sparsity ;
                A_dense.sparsity = A_sparsity ;

                % C<A> = A
                C1 = GB_mex_assign_alias_mask (C, A, [ ]) ;
                C2 = full (C.matrix) ;
                C2 (A_nonzero) = full (A.matrix (A_nonzero)) ;
                err = norm (double (C2) - double (C1.matrix), 1) ;
                assert (err == 0) ;

                % C<A,struct> = A
                B = A ;
                B.matrix = sparse (B.matrix) ;
                C3 = GB_mex_assign_alias_mask (C, B, desc) ;
                err = norm (double (C2) - double (C3.matrix), 1) ;
                assert (err == 0) ;

                % C<A,struct> = A where A is dense
                C1 = GB_mex_assign_alias_mask (C, A_dense, desc) ;
                err = norm (double (A_dense.matrix) - double (C1.matrix), 1) ;
                assert (err == 0) ;

                % C<A> = A where A is dense
                C1 = GB_mex_assign_alias_mask (C, A_dense, [ ]) ;
                err = norm (double (A_dense.matrix) - double (C1.matrix), 1) ;
                assert (err == 0) ;

            end
        end
    end
end

fprintf ('\ntest173: all tests passed\n') ;