File: test31.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 (93 lines) | stat: -rw-r--r-- 2,321 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function test31
%TEST31 test GrB_transpose

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

fprintf ('\n------------------- simple tests of GB_mex_transpose\n') ;

rng ('default') ;
A = sprand (4, 3, 0.4) ;
% full (A)
% full (A')
C = GB_mex_transpose (sparse (3,4), [ ], [ ], A) ;
assert (GB_spok (C.matrix) == 1) ;
assert (isequal (C.matrix,A')) ;

% C = A
D = struct ('inp0', 'tran') ;
C = GB_mex_transpose (sparse(4,3), [ ], [ ], A, D) ;
assert (isequal (C.matrix,A)) ;

% C = A'
C = GB_mex_transpose (sparse(3,4), [ ], [ ], A) ;
assert (isequal (C.matrix,A')) ;

Cin = sprand (4, 3, 0.5) ;
Cin2 = Cin' ;

% C = A'
C = GB_mex_transpose (Cin2, [ ], [ ], A) ;
assert (isequal (C.matrix,A')) ;

% C = Cin2+A'
C = GB_mex_transpose (Cin2, [ ], 'plus', A) ;
assert (isequal (C.matrix,Cin2+A')) ;

% C = Cin+A
D = struct ('inp0', 'tran') ;
C = GB_mex_transpose (Cin, [ ], 'plus', A, D) ;
assert (isequal (C.matrix,Cin+A)) ;

ops = {
    'first',
    'second',
    'pair',
    'oneb', % same as pair
    'min',
    'max',
    'plus',
    'minus',
    'times',
    'div',   } ;

for k = 1:length(ops)
    op = ops {k} ;

    % C = op (Cin2,A')
    D = struct ;
    C = GB_mex_transpose  (Cin2, [ ], op, A, D)  ;
    S = GB_spec_transpose (Cin2, [ ], op, A, D)  ;
    assert (isequal (C.matrix, sparse (S.matrix))) ;
    assert (isequal (GB_spones_mex (C.matrix), sparse (S.pattern))) ;

    % C = A', ignore the op
    D = struct ('outp', 'replace') ;
    C = GB_mex_transpose  (Cin2, [ ], op, A, D) ;
    S = GB_spec_transpose (Cin2, [ ], op, A, D) ;
    assert (isequal (GB_spones_mex (C.matrix), sparse (S.pattern))) ;

    % C = A, ignore the op
    D = struct ('inp0', 'tran', 'outp', 'replace') ;
    C = GB_mex_transpose  (Cin, [ ], op, A, D) ;
    S = GB_spec_transpose (Cin, [ ], op, A, D) ;
    assert (isequal (GB_spones_mex (C.matrix), sparse (S.pattern))) ;

    % C = op (Cin,A)
    D = struct ('inp0', 'tran') ;
    C = GB_mex_transpose  (Cin, [ ], op, A, D) ;
    S = GB_spec_transpose (Cin, [ ], op, A, D) ;
    assert (isequal (GB_spones_mex (C.matrix), sparse (S.pattern))) ;

end

%{
A = sprand (20, 16, 0.45)
C = GB_mex_transpose (A)

A = sparse (rand (40,10)) ;
C = GB_mex_transpose (A)
%}

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