File: mxm.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 (103 lines) | stat: -rw-r--r-- 3,078 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function C = mxm (arg1, arg2, arg3, arg4, arg5, arg6, arg7)
%GRB.MXM sparse matrix-matrix multiplication.
%
% GrB.mxm computes C<M> = accum (C, A*B) using a given semiring.
%
% Usage:
%
%   C = GrB.mxm (semiring, A, B)
%   C = GrB.mxm (semiring, A, B, desc)
%
%   C = GrB.mxm (Cin, accum, semiring, A, B)
%   C = GrB.mxm (Cin, accum, semiring, A, B, desc)
%
%   C = GrB.mxm (Cin, M, semiring, A, B)
%   C = GrB.mxm (Cin, M, semiring, A, B, desc)
%
%   C = GrB.mxm (Cin, M, accum, semiring, A, B)
%   C = GrB.mxm (Cin, M, accum, semiring, A, B, desc)
%
% Cin is an optional input matrix.  If Cin is not present or is an empty
% matrix (Cin = [ ]) then it is implicitly a matrix with no entries, of the
% right size (which depends on A, B, and the descriptor).  Its type is the
% output type of the accum operator, if it is present; otherwise, its type
% is the type of the additive monoid of the semiring.
%
% M is the optional mask matrix.  If not present, or if empty, then no mask
% is used.  If present, M must have the same size as C.
%
% If accum is not present, then the operation becomes C<...> = A*B.
% Otherwise, accum (C,A*B) is computed.  The accum operator acts like a
% sparse matrix addition (see GrB.eadd).
%
% The semiring is a required string defining the semiring to use, in the
% form 'add.mult.type', where '.type' is optional.  For example,
% '+.*.double' is the conventional semiring for numerical linear algebra,
% used in the built-in C=A*B when A and B are double.  If A or B are
% double complex, then C=A*B uses the '+.*.double complex' semiring.
% GraphBLAS has many more semirings.  See 'help GrB.semiringinfo' for more
% details.
%
% A and B are the input matrices.  A is transposed on input if desc.in0
% is 'transpose', and/or desc.in1 = 'transpose' transposes B.
%
% desc is optional.  See 'help GrB.descriptorinfo' for more details.
%
% Examples:
%
%   A = sprand (4,5,0.5) ;
%   B = sprand (5,3,0.5) ;
%   C = GrB.mxm ('+.*', A, B) ;
%   norm (C-A*B,1)
%   E = sprand (4,3,0.7) ;
%   M = logical (sprand (4,3,0.5)) ;
%   C2 = GrB.mxm (E, M, '+', '+.*', A, B) ;
%   C3 = E ; AB = A*B ; C3 (M) = C3 (M) + AB (M) ;
%   norm (C2-C3,1)
%
% See also GrB.descriptorinfo, GrB.add, GrB/mtimes.

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

if (isobject (arg1))
    arg1 = arg1.opaque ;
end

if (isobject (arg2))
    arg2 = arg2.opaque ;
end

if (isobject (arg3))
    arg3 = arg3.opaque ;
end

if (nargin > 3 && isobject (arg4))
    arg4 = arg4.opaque ;
end

if (nargin > 4 && isobject (arg5))
    arg5 = arg5.opaque ;
end

if (nargin > 5 && isobject (arg6))
    arg6 = arg6.opaque ;
end

switch (nargin)
    case 3
        [C, k] = gbmxm (arg1, arg2, arg3) ;
    case 4
        [C, k] = gbmxm (arg1, arg2, arg3, arg4) ;
    case 5
        [C, k] = gbmxm (arg1, arg2, arg3, arg4, arg5) ;
    case 6
        [C, k] = gbmxm (arg1, arg2, arg3, arg4, arg5, arg6) ;
    case 7
        [C, k] = gbmxm (arg1, arg2, arg3, arg4, arg5, arg6, arg7) ;
end

if (k == 0)
    C = GrB (C) ;
end