selectiveGemm

Selective general matrix multiplication with selector sparse matrix.

void
selectiveGemm
(
string op = ""
SliceKind kind1
SliceKind kind2
SliceKind kind3
T
T3
I3
J3
)
(
Slice!(T*, 2, kind1) a
,
Slice!(T*, 2, kind2) b
,
Slice!(ChopIterator!(J3*, Series!(I3*, T3*)), 1, kind3) c
)

Parameters

a Slice!(T*, 2, kind1)

dense matrix

b Slice!(T*, 2, kind2)

dense matrix

c Slice!(ChopIterator!(J3*, Series!(I3*, T3*)), 1, kind3)

sparse matrix (CSR format)

Return Value

Type: void

c[available indexes] <op>= (a × b)[available indexes].

Examples

import mir.ndslice;
import mir.sparse;

auto a = slice!double(3, 5);
a[] =
    [[-5, 1, 7, 7, -4],
     [-1, -5, 6, 3, -3],
     [-5, -2, -3, 6, 0]];

auto b = slice!double(5, 4);
b[] =
    [[-5.0, -3, 3, 1],
     [4.0, 3, 6, 4],
     [-4.0, -2, -2, 2],
     [-1.0, 9, 4, 8],
     [9.0, 8, 3, -2]];

// a * b ==
//    [[-42.0, 35, -7, 77],
//     [-69.0, -21, -42, 21],
//     [23.0, 69, 3, 29]]);

auto cs = sparse!double(3, 4);
cs[0, 2] = 1;
cs[0, 1] = 3;
cs[2, 3] = 2;

auto c = cs.compress;

selectiveGemm!"*"(a, b, c);
assert(c.length == 3);
assert(c[0].index == [1, 2]);
assert(c[0].value == [105, -7]);
assert(c[1].empty);
assert(c[2].index == [3]);
assert(c[2].value == [58]);

Meta