Skip to content

Incorrect method in matmul example in documentation #59620

@PatrickHaecker

Description

@PatrickHaecker

The method matmul defined in the documentation has multiple problems:

R = promote_op(op, eltype(a), eltype(b)) does not work as promote_op is not exported from Base nor public. To get it to run we would need to write Base.promote_op, but do we really want to encourage using private symbols?

It uses arguments of type AbstractMatrix, but then uses indices always starting from 1 which fails with OffsetMatrix. Reproducer:

using Base: promote_op
a = OffsetMatrix([1 2; 3 4], -2, -2)
matmul(a, a)

To be fair, it's introduced with "a generic square-matrix multiply pseudo-code might look like", i.e. mentioning that it should be "pseudo-code". However, I think this is compensated by calling it "generic".

I think this example should be improved, it should be removed or at least some hints about the shortcomings should be added. The latter one has the disadvantage of not being so observable both for humans and machines (e.g. in training LLMs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions