Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Override chainrules rrule
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Mar 28, 2024
1 parent 1911ccf commit d0ce078
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ function CRC.rrule(::typeof(*), X::UniformBlockDiagonalMatrix{<:Union{Real, Comp
return X * Y, ∇times
end

function CRC.rrule(cfg::CRC.RuleConfig{>:CRC.HasReverseMode}, ::typeof(*),
X::AbstractMatrix{<:Union{Real, Complex}},
Y::UniformBlockDiagonalMatrix{<:Union{Real, Complex}})
_f = @closure (x, y) -> dropdims(
batched_mul(reshape(x, :, 1, nbatches(x)), y.data); dims=1)
return CRC.rrule_via_ad(cfg, _f, X, Y)
end

# constructor
function CRC.rrule(::Type{<:UniformBlockDiagonalMatrix}, data)
function ∇UniformBlockDiagonalMatrix(Δ)
Expand Down

0 comments on commit d0ce078

Please sign in to comment.