def _compute_style_grad(F, G, G_style, layer):
 (Fl, Gl) = (F[layer], G[layer])
 c = ((Fl.shape[0] ** (-2)) * (Fl.shape[1] ** (-2)))
 El = (Gl - G_style[layer])
 loss = ((c / 4) * (El ** 2).sum())
 grad = ((c * sgemm(1.0, El, Fl)) * (Fl > 0))
 return (loss, grad)

def _compute_style_grad ( F , G , G_style , layer ) : ( Fl , Gl ) = ( F [ layer ] , G [ layer ] ) c = ( ( Fl . shape [ 0 ] ** ( - 2 ) ) * ( Fl . shape [ 1 ] ** ( - 2 ) ) ) El = ( Gl - G_style [ layer ] ) loss = ( ( c / 4 ) * ( El ** 2 ) . sum ( ) ) grad = ( ( c * sgemm ( 1.0 , El , Fl ) ) * ( Fl > 0 ) ) return ( loss , grad )
computes style gradient and loss from activation features .