Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.sparse.blas.dot

Authors:
Ilya Yaroshenko
  • dot
    Unqual!(CommonType!(T1, T2)) dot(V1 : CompressedArray!(T1, I1), V2 : CompressedArray!(T2, I2), T1, T2, I1, I2)(V1 x, V2 y);

    D dot(D, V1 : CompressedArray!(T1, I1), V2 : CompressedArray!(T2, I2), T1, T2, I1, I2)(V1 x, V2 y);
    Dot product of two vectors
    Parameters:
    V1 x sparse vector
    V2 y sparse vector
    Returns:
    scalar xᵀ × y
    Examples:
    auto x = CompressedArray!(int, uint)([1, 3, 4, 9, 10], [0, 3, 5, 9, 100]);
    auto y = CompressedArray!(int, uint)([1, 10, 100, 1000], [1, 3, 4, 9]);
    // x = [1, 0, 0,  3, 0, 4, 0, 0, 0, 9, ... ,10]
    // y = [0, 1, 0, 10, 0, 0, 0, 0, 0, 1000]
    assert(dot(x, y) == 9030);
    assert(dot!double(x, y) == 9030);
    
  • dot
    Unqual!(CommonType!(T1, ForeachType!V2)) dot(V1 : CompressedArray!(T1, I1), T1, I1, V2)(V1 x, V2 y)
    if (isDynamicArray!V2 || isSlice!V2 == [1]);

    D dot(D, V1 : CompressedArray!(T1, I1), T1, I1, V2)(V1 x, V2 y)
    if (isDynamicArray!V2 || isSlice!V2 == [1]);
    Dot product of two vectors.
    Parameters:
    V1 x sparse vector
    V2 y dense vector
    Returns:
    scalar x × y
    Examples:
    import std.typecons: No;
    auto x = CompressedArray!(double, uint)([1.0, 3, 4, 9, 13], [0, 3, 5, 9, 10]);
    auto y = [0.0, 1.0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
    // x: [1, 0, 0, 3, 0, 4, 0, 0, 0, 9, 13,  0,  0,  0]
    // y: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
    auto r = 0 + 3 * 3 + 4 * 5 + 9 * 9 + 13 * 10;
    assert(dot(x, y) == r);
    assert(dot(x, y.sliced) == r);
    assert(dot(x, y.slicedField) == r);