'Apply softmax derivative, where labels are the correct labels.'

def apply_softmax_grad(self, labels, target=None):

    if (not target):
        target = self
    assert (labels.shape == (1, self.shape[1]))
    assert (target.shape == self.shape)
    if isinstance(labels, EigenMatrix):
        err_code = _eigenmat.apply_softmax_grad(self.p_mat, labels.p_mat, target.p_mat)
    else:
        raise ValueError, 'labels    must    be    of    type    EigenMatrix    or    CUDAMatrix.'
    if err_code:
        raise generate_exception(err_code)
    return target
