Esempio n. 1
0
def test_correctness_calcRlogR(N=1000, K=10):
    R = np.random.rand(N, K)
    H1 = calcRlogR_numpy_forloop(R)
    H2 = calcRlogR_numpy_vectorized(R)
    H3 = calcRlogR_cython(R)
    H4 = calcRlogR_numexpr(R)
    assert np.allclose(H1, H2)
    assert np.allclose(H1, H3)
    assert np.allclose(H1, H4)
Esempio n. 2
0
def calcRlogR(R, algVersion='cython'):
    ''' Compute R * log(R), then sum along columns of result.

    Returns
    --------
    H : 1D array, size K
        H[k] = sum(R[:,k] * log(R[:,k]))
    '''
    if hasCython and algVersion.count('cython'):
        if R.ndim == 1:
            return calcRlogR_1D_cython(R)
        else:
            return calcRlogR_cython(R)
    elif hasNumexpr and algVersion.count('numexpr'):
        return calcRlogR_numexpr(R)
    else:
        return calcRlogR_numpy_vectorized(R)