def make_kinetic_precond(kpointset, c0, eps=0.1, asPwCoeffs=True):
    '\n    Preconditioner\n    P = 1 / (||k|| + ε)\n\n    Keyword Arguments:\n    kpointset --\n    '
    nk = len(kpointset)
    nc = kpointset.ctx().num_spins()
    if ((nc == 1) and (nk == 1) and (not asPwCoeffs)):
        kp = kpointset[0]
        gkvec = kp.gkvec()
        assert (gkvec.num_gvec() == gkvec.count())
        N = gkvec.count()
        d = np.array([(1 / (np.sum((np.array(gkvec.gkvec(i)) ** 2)) + eps)) for i in range(N)])
        return DiagonalPreconditioner(D=dia_matrix((d, 0), shape=(N, N)), c0=c0)
    else:
        P = PwCoeffs(dtype=np.float64, ctype=dia_matrix)
        for k in range(nk):
            kp = kpointset[k]
            gkvec = kp.gkvec()
            assert (gkvec.num_gvec() == gkvec.count())
            N = gkvec.count()
            d = np.array([(1 / (np.sum((np.array(gkvec.gkvec_cart(i)) ** 2)) + eps)) for i in range(N)])
            for ispn in range(nc):
                P[(k, ispn)] = dia_matrix((d, 0), shape=(N, N))
        return DiagonalPreconditioner(P, c0)
Preconditioner
P = 1 / (||k|| + ε)

Keyword Arguments:
kpointset --
def make_kinetic_precond(kpointset, c0, eps=0.1, asPwCoeffs=True):
    '\n    Preconditioner\n    P = 1 / (||k|| + ε)\n\n    Keyword Arguments:\n    kpointset --\n    '
    nk = len(kpointset)
    nc = kpointset.ctx().num_spins()
    if ((nc == 1) and (nk == 1) and (not asPwCoeffs)):
        kp = kpointset[0]
        gkvec = kp.gkvec()
        assert (gkvec.num_gvec() == gkvec.count())
        N = gkvec.count()
        d = np.array([(1 / (np.sum((np.array(gkvec.gkvec(i)) ** 2)) + eps)) for i in range(N)])
        return DiagonalPreconditioner(D=dia_matrix((d, 0), shape=(N, N)), c0=c0)
    else:
        P = PwCoeffs(dtype=np.float64, ctype=dia_matrix)
        for k in range(nk):
            kp = kpointset[k]
            gkvec = kp.gkvec()
            assert (gkvec.num_gvec() == gkvec.count())
            N = gkvec.count()
            d = np.array([(1 / (np.sum((np.array(gkvec.gkvec_cart(i)) ** 2)) + eps)) for i in range(N)])
            for ispn in range(nc):
                P[(k, ispn)] = dia_matrix((d, 0), shape=(N, N))
        return DiagonalPreconditioner(P, c0)