File: test125.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (88 lines) | stat: -rw-r--r-- 2,567 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 test125
%TEST125 test GrB_mxm: row and column scaling
% all built-in semirings, no typecast, no mask

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

[binops, ~, add_ops, types, ~, ~] = GB_spec_opsall ;
mult_ops = binops.all ;
types = types.all ;

fprintf ('-------------- GrB_mxm on all semirings (row,col scale)\n') ;

dnn = struct ;
dtn = struct ( 'inp0', 'tran' ) ;
dnt = struct ( 'inp1', 'tran' ) ;
dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ;

rng ('default') ;

n = 10 ;

n_semirings = 0 ;
A = GB_spec_random (n,n,0.3,100,'none') ;
clear B
B1matrix = spdiags (3 * rand (n,1), 0, n, n) ;
B.matrix = B1matrix ;
B.class = 'none' ;
B.pattern = logical (spones (B1matrix)) ;

C = GB_spec_random (n,n,0.3,100,'none') ;
M = spones (sprandn (n, n, 0.3)) ;

for k1 = 1:length(mult_ops)
    mulop = mult_ops {k1} ;
    fprintf ('\n%-10s ', mulop) ;
    nmult_semirings = 0 ;

    for k2 = 1:length(add_ops)
        addop = add_ops {k2} ;
        fprintf ('.') ;

        for k3 = 1:length (types)
            type = types {k3} ;

            semiring.multiply = mulop ;
            semiring.add = addop ;
            semiring.class = type ;

            % semiring

            % create the semiring.  some are not valid because the
            % or,and,xor monoids can only be used when z is boolean for
            % z=mult(x,y).
            try
                [mult_op add_op id] = GB_spec_semiring (semiring) ;
                [mult_opname mult_optype ztype xtype ytype] = ...
                    GB_spec_operator (mult_op) ;
                [ add_opname  add_optype] = GB_spec_operator (add_op) ;
                identity = GB_spec_identity (semiring.add, add_optype) ;
            catch
                continue
            end

            n_semirings = n_semirings + 1 ;
            nmult_semirings = nmult_semirings + 1 ;
            A.class = type ;
            B.class = type ;
            C.class = type ;

            % C = A*B
            C1 = GB_mex_mxm  (C, [ ], [ ], semiring, A, B, dnn);
            C0 = GB_spec_mxm (C, [ ], [ ], semiring, A, B, dnn);
            GB_spec_compare (C0, C1, identity) ;

            % C = B*A
            C1 = GB_mex_mxm  (C, [ ], [ ], semiring, B, A, dnn);
            C0 = GB_spec_mxm (C, [ ], [ ], semiring, B, A, dnn);
            GB_spec_compare (C0, C1, identity) ;

        end
    end
    fprintf (' %4d', nmult_semirings) ;
end

fprintf ('\nsemirings tested: %d\n', n_semirings) ;
fprintf ('\ntest125: all tests passed\n') ;