Skip to content

x' * SMatrix fails for SVector inputs #308

Open

Description

@devmotion
using ReverseDiff, StaticArrays
M = SMatrix{2,2}(1.0, 2.0, 3.0, 4.0)
ReverseDiff.gradient(x -> sum(abs2, x' * M), SVector(3.0, 4.0))
MethodError: no method matching _mul!(::StaticArrays.TSize{(1, 2), :adjoint}, ::MVector{2, Float64}, ::Size{(1, 2)}, ::Size{(2, 2)}, ::Adjoint{Float64, MVector{2, Float64}}, ::SMatrix{2, 2, Float64, 4}, ::StaticArrays.NoMulAdd{Float64, Float64})

transpose(x) * M fails in the same way. With a Vector input, both work.

The tracked input's value is an MVector, so the product's value is an Adjoint of an MVector. mul! then writes the result into the MVector under that Adjoint, and StaticArrays has no _mul! for writing a row vector times a matrix into a plain vector. This happens on master, both before and after #307.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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