Esempio n. 1
0
def test_correctness_calcRlogRdotv(N=1000, K=10):
    R = np.random.rand(N, K)
    v = np.random.rand(N)
    H1 = calcRlogRdotv_numpy(R, v)
    H2 = calcRlogRdotv_cython(R, v)
    H3 = calcRlogRdotv_numexpr(R, v)
    H4 = calcRlogRdotv(R, v)
    assert np.allclose(H1, H2)
    assert np.allclose(H1, H3)
    assert np.allclose(H1, H4)
Esempio n. 2
0
def calcRlogRdotv(R, v, algVersion='cython'):
    ''' Computes R * log(R) and takes inner product with weight vector v.

    Returns
    --------
    H : 1D array, size K
        H[k] = inner(v, R[:,k] * log(R[:,k]))
    '''
    if hasCython and algVersion.count('cython'):
        if R.ndim == 1:
            return calcRlogRdotv_1D_cython(R, v)
        else:
            return calcRlogRdotv_cython(R, v)
    elif hasNumexpr and algVersion.count('numexpr'):
        return calcRlogRdotv_numexpr(R, v)
    else:
        return calcRlogRdotv_numpy(R, v)