Skip to content

Add rules for sparse symmetric matrices: dot, lmul, rmul.#837

Open
samuelsonric wants to merge 1 commit intoJuliaDiff:mainfrom
samuelsonric:main
Open

Add rules for sparse symmetric matrices: dot, lmul, rmul.#837
samuelsonric wants to merge 1 commit intoJuliaDiff:mainfrom
samuelsonric:main

Conversation

@samuelsonric
Copy link
Copy Markdown

@samuelsonric samuelsonric commented Mar 31, 2026

This PR adds rules for the operations

  • A * Y
  • X * A
  • dot(x, A, y)

where A is a Symmetric (or Hermitian)-wrapped sparse matrix. The new rules are much faster then the defaults, although some combinations will perform poorly until this issue is resolved.

Example

using ChainRules, LinearAlgebra, SparseArrays

A = Hermitian(sprand(10000, 10000, .001), :L)

x = rand(10000)
y = rand(10000)
Δz = 0.1

_, pullback = ChainRules.rrule(dot, x, A, y)
@time map(ChainRules.unthunk, pullback(Δz));
  • old: 0.123707 seconds (48 allocations: 769.704 MiB, 16.02% gc time)
  • new: 0.000881 seconds (23 allocations: 1.844 MiB)

@samuelsonric
Copy link
Copy Markdown
Author

Related: JuliaDiff/ChainRulesCore.jl#707

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant