Skip to content
class

CofactorBackward

CofactorBackward

Autograd node for the cofactor matrix cof(A)=∇det⁡(A)\mathrm{cof}(A) = \nabla \det(A) in its singular-safe SVD form — what [[DetBackward]] records when the batch holds a singular matrix, so det differentiates twice there too.

The cofactor map is the gradient of det⁡\det, so its vector-Jacobian product is the Hessian of det⁡\det applied to GG, and that Hessian is symmetric: the backward is the directional derivative of cof\mathrm{cof} along GG. With A=U diag(s) V⊤A = U\,\mathrm{diag}(s)\,V^\top, α=det⁡Udet⁡V\alpha = \det U \det V and G′=U⊤GVG' = U^\top G V,

d cof(A)[G]=α U(diag(Q diag(G′))−Q⊙G′⊤)V⊤,Qij=[i≠j]∏m≠i,jsm, d\,\mathrm{cof}(A)[G] = \alpha\, U \left( \mathrm{diag}(Q\,\mathrm{diag}(G')) - Q \odot G'^\top \right) V^\top, \qquad Q_{ij} = [i \ne j] \prod_{m \ne i, j} s_m,

which takes no division, so it holds at any rank. A third derivative through it is not implemented.

Instance methods

2
fn

apply_for_graph

int apply_for_graph(const int & grad_out)