Skip to content

Correctness Bug: wrong semiring used in functional-style triple product #498

@alugowski

Description

@alugowski

The functional style multiply, i.e. gb.semiring.plus_plus(A @ B) , appears to not respect the semiring choice when doing a triple product A @ B @ C.

Let:

A = gb.Matrix.from_coo([0, 0, 1], [0, 1, 1], [11, 22, 33], nrows=2, ncols=2)

left = gb.Matrix.from_coo([0, 0], [0, 1], [1, 1], nrows=1, ncols=2)
right = gb.Matrix.from_coo([0, 1], [0, 0], [1, 1], nrows=2, ncols=1)

A triple product using the plus_first semiring returns a 1x1 matrix with a count of nonzeros in A, which is 3. Indeed that is what the method style triple product returns:

left.mxm(A, op="plus_first").mxm(right, op="plus_first")
# returns `[[3]]` (correct)

However the functional-style triple product,

gb.semiring.plus_first(left @ A @ right)
# returns `[[66]]` (incorrect)

It appears that the plus_first semiring is only used for one of the multiplications, and plus_times for the other.

Application is to implement a triple product that creates a low resolution spy plot, like this:

triple_product

See MatSpy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions