File: test02.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 (78 lines) | stat: -rw-r--r-- 2,271 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
74
75
76
77
78
function test02
%TEST02 test GrB_*_dup

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

[~, ~, ~, types, ~, ~] = GB_spec_opsall ;
GB_builtin_complex_set (true) ;
types = types.all ;

rng ('default') ;
format long g

for k1 = 1:length (types)
    atype = types {k1} ;

    for is_hyper = 0:1
        for is_csc = 0:1

            % create a random A
            A = GB_spec_random (4, 4, 0.8, 128, atype, is_csc, is_hyper) ;
            A.matrix (1,1) = -1 ;
            A.pattern (1,1) = true ;
            A_matrix = full (A.matrix) ;
            A_pattern = full (A.pattern) ;
            assert (GB_spok (1*A.matrix) == 1) ;
            assert (GB_spok (A.pattern) == 1) ;

            for k2 = 1:length (types)
                ctype = types {k2} ;
                % typecast to type of C

                C = GB_mex_dup (A, ctype) ;
                C_matrix = full (C.matrix) ;
                C_pattern = full (GB_spones_mex (C.matrix)) ;
                assert (GB_spok (1*C.matrix) == 1) ;

                if (k1 == k2)
                    % also try another method
                    assert (isequal (A_pattern, C_pattern)) ;
                    assert (isequal (A.class, C.class)) ;

                    C2 = GB_mex_dup (A, ctype, 1) ;
                    C2_matrix = full (C2.matrix) ;
                    C2_pattern = full (GB_spones_mex (C2.matrix)) ;
                    assert (isequal (C, C2))  ;
                    assert (GB_spok (1*C2.matrix) == 1) ;
                end

            end
        end
    end
end

% try with both built-in and user-defined 'double complex' types:
for k = [false true]
    GB_builtin_complex_set (k) ;

    % duplicate a complex matrix (user-defined can't be typecasted)
    A = GB_mex_random (4, 4, 10, 1) ;
    assert (GB_spok (1*A) == 1) ;

    C = GB_mex_dup (A) ;
    % C_matrix = full (C.matrix) ;
    assert (isequal (A, C.matrix))  ;
    assert (GB_spok (1*C.matrix) == 1) ;

    C = GB_mex_dup (A, 'double complex', 1) ;
    % C_matrix = full (C.matrix) ;
    assert (isequal (A, C.matrix))  ;
    assert (GB_spok (1*C.matrix) == 1) ;
end

format

GB_builtin_complex_set (true) ;
fprintf ('test02: all typecast and copy tests passed\n') ;