def forward(self, inputs):
    xp = backend.get_array_module(*inputs)
    (h,) = inputs
    self.h_centered = (h - h.mean(axis=0, keepdims=True))
    self.covariance = self.h_centered.T.dot(self.h_centered)
    xp.fill_diagonal(self.covariance, 0.0)
    self.covariance /= len(h)
    if (self.reduce == 'half_squared_sum'):
        cost = xp.vdot(self.covariance, self.covariance)
        cost *= h.dtype.type(0.5)
        return (utils.force_array(cost),)
    else:
        return (self.covariance,)
def forward(self, inputs):
    xp = backend.get_array_module(*inputs)
    (h,) = inputs
    self.h_centered = (h - h.mean(axis=0, keepdims=True))
    self.covariance = self.h_centered.T.dot(self.h_centered)
    xp.fill_diagonal(self.covariance, 0.0)
    self.covariance /= len(h)
    if (self.reduce == 'half_squared_sum'):
        cost = xp.vdot(self.covariance, self.covariance)
        cost *= h.dtype.type(0.5)
        return (utils.force_array(cost),)
    else:
        return (self.covariance,)