File: testc7.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 (88 lines) | stat: -rw-r--r-- 2,884 bytes parent folder | download | duplicates (2)
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
function testc7(use_builtin)
%TESTC7 test complex assign

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

fprintf ('\ntestc7: all complex assign C(I,J)=A --------------------------\n') ;
rng ('default')

if (nargin < 1)
    use_builtin = true ;
end
GB_builtin_complex_set (use_builtin) ;

dclear.outp = 'replace' ;
dclear.mask = 'complement' ;
tol = 1e-13 ;

seed = 1 ;
for m = [1 5 10 50]
    for n = [1 5 10 50]
        seed = seed + 1 ;
        C = GB_mex_random (m, n, 10*(m+n), 1, seed) ;
        for ni = 1:m
            for nj = 1:n
                I = randperm (m, ni) ;
                J = randperm (n, nj) ;
                seed = seed + 1 ;
                A = GB_mex_random (ni, nj, 2*(ni+nj), 1, seed) ;
                seed = seed + 1 ;
                M = GB_mex_random (ni, nj, 4*(ni+nj), 0, seed) ;
                C1 = C ;
                C1 (I,J) = A ;

                I0 = uint64 (I-1) ;
                J0 = uint64 (J-1) ;

                C2 = GB_mex_subassign (C, [ ], [ ], A, I0, J0, []) ;
                assert (isequal (C1, C2.matrix)) ;

                [C3,c1] = GB_mex_subassign (C, M, [ ], A, I0, J0, [], 'plus') ;
                cin = complex (0,0) ;
                c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ;
                assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ;

                C1 = C ;
                C1 (I,J) = C1 (I,J) + A ;

                C2 = GB_mex_subassign (C, [ ], 'plus', A, I0, J0, []) ;
                assert (norm (C1 - C2.matrix, 1) <= tol * (norm (C1,1)+1)) ;
                assert (isequal (C1, C2.matrix)) ;

            end
            fprintf ('.') ;
        end

        C = GB_mex_random (m, n, 100*(m*n), 1, seed) ; seed = seed + 1 ;
        M = GB_mex_random (m, n, 4*(ni+nj), 0, seed) ; seed = seed + 1 ;
        A = GB_mex_random (m, n, m+n, 1, seed) ;       seed = seed + 1 ;

        [C3,c1] = GB_mex_subassign (C, M, [ ], A, [ ], [ ], dclear, 'plus') ;
        cin = complex (0,0) ;
        c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ;
        assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ;

        [C3,c1] = GB_mex_subassign (C, [ ], [ ], A, [ ], [ ], dclear, 'plus') ;
        cin = complex (0,0) ;
        c2 = GB_mex_reduce_to_scalar (cin, '', 'plus', C3) ;
        assert (abs (c1-c2) <= tol * (abs (c1) + 1)) ;

        clear S
        S.matrix = sparse (1i * ones (m,n)) ;
        S.pattern = false (m,n) ;
        cin = complex (1,1) ;
        M = sparse (true (m,n)) ;
        C2 = GB_mex_subassign (S, M, [ ], sparse (cin), ...
            [ ], [ ], struct ('mask', 'structural')) ;
        C1 = sparse (ones (m,n)) ;
        C1 (:,:) = cin ;
        assert (norm (C1-C2.matrix, 1) < 1e-12)

    end
end

fprintf ('\ntestc7: all complex assign C(I,J)=A tests passed\n') ;

GB_builtin_complex_set (true) ;