'Test a problem with kl_div.'

def test_kl_div(self):

    import numpy as np
    import cvxpy as cp
    kK = 50
    kSeed = 10
    prng = np.random.RandomState(kSeed)
    npSPriors = prng.uniform(0.0, 1.0, (kK, 1))
    npSPriors = (npSPriors / sum(npSPriors))
    p_refProb = cp.Parameter(kK, 1, sign='positive')
    v_prob = cp.Variable(kK, 1)
    objkl = 0.0
    for k in range(kK):
        objkl += cp.kl_div(v_prob[(k, 0)], p_refProb[(k, 0)])
    constrs = [(sum([v_prob[(k, 0)] for k in range(kK)]) == 1)]
    klprob = cp.Problem(cp.Minimize(objkl), constrs)
    p_refProb.value = npSPriors
    result = klprob.solve(solver=SCS, verbose=True)
    self.assertItemsAlmostEqual(v_prob.value, npSPriors)
