def backward(self, inputs, grad_outputs):
    xp = backend.get_array_module(*inputs)
    (h,) = inputs
    (gcost,) = grad_outputs
    gcost_div_n = (gcost / gcost.dtype.type(len(h)))
    if (self.reduce == 'half_squared_sum'):
        gh = (2.0 * self.h_centered.dot(self.covariance))
        gh *= gcost_div_n
    else:
        xp.fill_diagonal(gcost_div_n, 0.0)
        gh = self.h_centered.dot((gcost_div_n + gcost_div_n.T))
    return (gh,)
def backward(self, inputs, grad_outputs):
    xp = backend.get_array_module(*inputs)
    (h,) = inputs
    (gcost,) = grad_outputs
    gcost_div_n = (gcost / gcost.dtype.type(len(h)))
    if (self.reduce == 'half_squared_sum'):
        gh = (2.0 * self.h_centered.dot(self.covariance))
        gh *= gcost_div_n
    else:
        xp.fill_diagonal(gcost_div_n, 0.0)
        gh = self.h_centered.dot((gcost_div_n + gcost_div_n.T))
    return (gh,)