当前位置: 首页>>代码示例>>Python>>正文


Python test_core.srand函数代码示例

本文整理汇总了Python中test_core.srand函数的典型用法代码示例。如果您正苦于以下问题:Python srand函数的具体用法?Python srand怎么用?Python srand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了srand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_spectral_rolloff_synthetic

def test_spectral_rolloff_synthetic():

    srand()

    sr = 22050
    n_fft = 2048

    def __test(S, freq, pct):

        rolloff = librosa.feature.spectral_rolloff(S=S, sr=sr, freq=freq,
                                                   roll_percent=pct)

        if freq is None:
            freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)

        idx = np.floor(pct * freq.shape[0]).astype(int)
        assert np.allclose(rolloff, freq[idx])

    S = np.ones((1 + n_fft // 2, 10))

    for pct in [0.25, 0.5, 0.95]:
        # Implicit frequencies
        yield __test, S, None, pct

        # Explicit frequencies
        freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)
        yield __test, S, freq, pct

        # And time-varying frequencies
        freq = np.cumsum(np.abs(np.random.randn(*S.shape)), axis=0)
        yield __test, S, freq, pct
开发者ID:ai-learn-use,项目名称:librosa,代码行数:31,代码来源:test_features.py

示例2: __test

    def __test(metric, bandwidth, self):
        srand()
        data = np.random.randn(3, 100)
        distance = squareform(pdist(data.T, metric=metric))
        rec = librosa.segment.recurrence_matrix(data, mode='affinity',
                                                metric=metric,
                                                sparse=True,
                                                bandwidth=bandwidth,
                                                self=self)

        if self:
            assert np.allclose(rec.diagonal(), 1.0)
        else:
            assert np.allclose(rec.diagonal(), 0.0)

        i, j, vals = scipy.sparse.find(rec)
        logvals = np.log(vals)

        # After log-scaling, affinity will match distance up to a constant factor
        ratio = -logvals / distance[i, j]
        if bandwidth is None:
            # Estimate the global bandwidth using non-zero distances
            assert np.allclose(-logvals, distance[i, j] * np.nanmax(ratio))
        else:
            assert np.allclose(-logvals, distance[i, j] * bandwidth)
开发者ID:ai-learn-use,项目名称:librosa,代码行数:25,代码来源:test_segment.py

示例3: test_hcqt_white_noise

def test_hcqt_white_noise():

    def __test(fmin, n_bins, scale, sr, y):

        C = librosa.hybrid_cqt(y=y, sr=sr,
                               fmin=fmin,
                               n_bins=n_bins,
                               scale=scale)

        if not scale:
            lengths = librosa.filters.constant_q_lengths(sr, fmin,
                                                         n_bins=n_bins)
            C /= np.sqrt(lengths[:, np.newaxis])

        assert np.allclose(np.mean(C, axis=1), 1.0, atol=2.5e-1), np.mean(C, axis=1)
        assert np.allclose(np.std(C, axis=1), 0.5, atol=5e-1), np.std(C, axis=1)

    srand()
    for sr in [22050]:
        y = np.random.randn(30 * sr)

        for scale in [False, True]:
            for fmin in librosa.note_to_hz(['C1', 'C2']):
                for n_octaves in [6, 7]:
                    yield __test, fmin, n_octaves * 12, scale, sr, y
开发者ID:dpwe,项目名称:librosa,代码行数:25,代码来源:test_constantq.py

示例4: test_stack_memory

def test_stack_memory():

    def __test(data, n_steps, delay):
        data_stack = librosa.feature.stack_memory(data,
                                                  n_steps=n_steps,
                                                  delay=delay)

        # If we're one-dimensional, reshape for testing
        if data.ndim == 1:
            data = data.reshape((1, -1))

        d, t = data.shape

        eq_(data_stack.shape[0], n_steps * d)
        eq_(data_stack.shape[1], t)

        for i in range(d):
            for step in range(1, n_steps):
                assert np.allclose(data[i, :- step * delay],
                                   data_stack[step * d + i, step * delay:])

    srand()

    for ndim in [1, 2]:
        data = np.random.randn(* ([5] * ndim))

        for n_steps in [-1, 0, 1, 2, 3, 4]:
            for delay in [-1, 0, 1, 2, 4]:
                tf = __test
                if n_steps < 1:
                    tf = raises(librosa.ParameterError)(__test)
                if delay < 1:
                    tf = raises(librosa.ParameterError)(__test)
                yield tf, data, n_steps, delay
开发者ID:Cortexelus,项目名称:librosa,代码行数:34,代码来源:test_features.py

示例5: test_spectral_centroid_synthetic

def test_spectral_centroid_synthetic():

    k = 5

    def __test(S, freq, sr, n_fft):
        cent = librosa.feature.spectral_centroid(S=S, freq=freq)

        if freq is None:
            freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)

        assert np.allclose(cent, freq[k])

    srand()
    # construct a fake spectrogram
    sr = 22050
    n_fft = 1024
    S = np.zeros((1 + n_fft // 2, 10))

    S[k, :] = 1.0

    yield __test, S, None, sr, n_fft

    freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)
    yield __test, S, freq, sr, n_fft

    # And if we modify the frequencies
    freq *= 3
    yield __test, S, freq, sr, n_fft

    # Or if we make up random frequencies for each frame
    freq = np.random.randn(*S.shape)
    yield __test, S, freq, sr, n_fft
开发者ID:ai-learn-use,项目名称:librosa,代码行数:32,代码来源:test_features.py

示例6: test_spectral_bandwidth_synthetic

def test_spectral_bandwidth_synthetic():
    # This test ensures that a signal confined to a single frequency bin
    # always achieves 0 bandwidth
    k = 5

    def __test(S, freq, sr, n_fft, norm, p):
        bw = librosa.feature.spectral_bandwidth(S=S, freq=freq, norm=norm, p=p)

        assert not np.any(bw)

    srand()
    # construct a fake spectrogram
    sr = 22050
    n_fft = 1024
    S = np.zeros((1 + n_fft // 2, 10))
    S[k, :] = 1.0

    for norm in [False, True]:
        for p in [1, 2]:
            # With vanilla frequencies
            yield __test, S, None, sr, n_fft, norm, p

            # With explicit frequencies
            freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)
            yield __test, S, freq, sr, n_fft, norm, p

            # And if we modify the frequencies
            freq = 3 * librosa.fft_frequencies(sr=sr, n_fft=n_fft)
            yield __test, S, freq, sr, n_fft, norm, p

            # Or if we make up random frequencies for each frame
            freq = np.random.randn(*S.shape)
            yield __test, S, freq, sr, n_fft, norm, p
开发者ID:ai-learn-use,项目名称:librosa,代码行数:33,代码来源:test_features.py

示例7: __test

    def __test(n, d, q):
        srand()

        X = np.random.randn(*([d] * n))**4

        X = np.asarray(X)

        xs = librosa.util.sparsify_rows(X, quantile=q)

        if ndim == 1:
            X = X.reshape((1, -1))

        assert np.allclose(xs.shape, X.shape)

        # And make sure that xs matches X on nonzeros
        xsd = np.asarray(xs.todense())

        for i in range(xs.shape[0]):
            assert np.allclose(xsd[i, xs[i].indices], X[i, xs[i].indices])

        # Compute row-wise magnitude marginals
        v_in = np.sum(np.abs(X), axis=-1)
        v_out = np.sum(np.abs(xsd), axis=-1)

        # Ensure that v_out retains 1-q fraction of v_in
        assert np.all(v_out >= (1.0 - q) * v_in)
开发者ID:baifengbai,项目名称:librosa,代码行数:26,代码来源:test_util.py

示例8: test_roll_sparse

def test_roll_sparse():
    srand()

    def __test(fmt, shift, axis, X):

        X_sparse = X.asformat(fmt)
        X_dense = X.toarray()

        Xs_roll = librosa.util.roll_sparse(X_sparse, shift, axis=axis)

        assert scipy.sparse.issparse(Xs_roll)
        eq_(Xs_roll.format, X_sparse.format)

        Xd_roll = librosa.util.roll_sparse(X_dense, shift, axis=axis)

        assert np.allclose(Xs_roll.toarray(), Xd_roll), (X_dense, Xs_roll.toarray(), Xd_roll)

        Xd_roll_np = np.roll(X_dense, shift, axis=axis)

        assert np.allclose(Xd_roll, Xd_roll_np)

    X = scipy.sparse.lil_matrix(np.random.randint(0, high=10, size=(16, 16)))

    for fmt in ['csr', 'csc', 'lil', 'dok', 'coo']:
        for shift in [0, 8, -8, 20, -20]:
            for axis in [0, 1, -1]:
                yield __test, fmt, shift, axis, X
开发者ID:baifengbai,项目名称:librosa,代码行数:27,代码来源:test_util.py

示例9: test_spectral_bandwidth_onecol

def test_spectral_bandwidth_onecol():
    # This test checks for issue https://github.com/librosa/librosa/issues/552
    # failure when the spectrogram has a single column

    def __test(S, freq):
        bw = librosa.feature.spectral_bandwidth(S=S, freq=freq)

        assert bw.shape == (1, 1)

    k = 5

    srand()
    # construct a fake spectrogram
    sr = 22050
    n_fft = 1024
    S = np.zeros((1 + n_fft // 2, 1))
    S[k, :] = 1.0

    # With vanilla frequencies
    yield __test, S, None

    # With explicit frequencies
    freq = librosa.fft_frequencies(sr=sr, n_fft=n_fft)
    yield __test, S, freq

    # And if we modify the frequencies
    freq = 3 * librosa.fft_frequencies(sr=sr, n_fft=n_fft)
    yield __test, S, freq

    # Or if we make up random frequencies for each frame
    freq = np.random.randn(*S.shape)
    yield __test, S, freq
开发者ID:ai-learn-use,项目名称:librosa,代码行数:32,代码来源:test_features.py

示例10: test_cqt_white_noise

def test_cqt_white_noise():

    def __test(fmin, n_bins, scale, sr, y):

        C = np.abs(librosa.cqt(y=y, sr=sr,
                               fmin=fmin,
                               n_bins=n_bins,
                               scale=scale))

        if not scale:
            lengths = librosa.filters.constant_q_lengths(sr, fmin,
                                                         n_bins=n_bins)
            C /= np.sqrt(lengths[:, np.newaxis])

        # Only compare statistics across the time dimension
        # we want ~ constant mean and variance across frequencies
        assert np.allclose(np.mean(C, axis=1), 1.0, atol=2.5e-1), np.mean(C, axis=1)
        assert np.allclose(np.std(C, axis=1), 0.5, atol=5e-1), np.std(C, axis=1)

    srand()
    for sr in [22050]:
        y = np.random.randn(30 * sr)

        for scale in [False, True]:
            for fmin in librosa.note_to_hz(['C1', 'C2']):
                for n_octaves in range(2, 4):
                    yield __test, fmin, n_octaves * 12, scale, sr, y
开发者ID:dpwe,项目名称:librosa,代码行数:27,代码来源:test_constantq.py

示例11: __test

    def __test(n, k, width, sym, metric):
        srand()
        # Make a data matrix
        data = np.random.randn(3, n)

        D = librosa.segment.recurrence_matrix(data, k=k, width=width, sym=sym, axis=-1, metric=metric)

        # First test for symmetry
        if sym:
            assert np.allclose(D, D.T)

        # Test for target-axis invariance
        D_trans = librosa.segment.recurrence_matrix(data.T, k=k, width=width, sym=sym, axis=0, metric=metric)
        assert np.allclose(D, D_trans)

        # If not symmetric, test for correct number of links
        if not sym and k is not None:
            real_k = min(k, n - width)
            assert not np.any(D.sum(axis=1) != real_k)

        # Make sure the +- width diagonal is hollow
        # It's easier to test if zeroing out the triangles leaves nothing
        idx = np.tril_indices(n, k=width)

        D[idx] = False
        D.T[idx] = False
        assert not np.any(D)
开发者ID:dpwe,项目名称:librosa,代码行数:27,代码来源:test_segment.py

示例12: test_lag_to_recurrence_sparse_badaxis

def test_lag_to_recurrence_sparse_badaxis():

    srand()

    data = np.random.randn(3, 100)
    R = librosa.segment.recurrence_matrix(data, sparse=True)
    L = librosa.segment.recurrence_to_lag(R)
    librosa.segment.lag_to_recurrence(L, axis=2)
开发者ID:dpwe,项目名称:librosa,代码行数:8,代码来源:test_segment.py

示例13: test_recurrence_badmode

def test_recurrence_badmode():

    srand()
    data = np.random.randn(3, 100)

    rec = librosa.segment.recurrence_matrix(data, mode='NOT A MODE',
                                            metric='sqeuclidean',
                                            sparse=True)
开发者ID:dpwe,项目名称:librosa,代码行数:8,代码来源:test_segment.py

示例14: __test_positional

    def __test_positional(n):
        srand()
        dpos0 = librosa.segment.timelag_filter(pos0_filter)
        dpos1 = librosa.segment.timelag_filter(pos1_filter, index=1)

        X = np.random.randn(n, n)

        assert np.allclose(X, dpos0(X))
        assert np.allclose(X, dpos1(None, X))
开发者ID:dpwe,项目名称:librosa,代码行数:9,代码来源:test_segment.py

示例15: test_recurrence_sparse

def test_recurrence_sparse():

    srand()
    data = np.random.randn(3, 100)
    D_sparse = librosa.segment.recurrence_matrix(data, sparse=True)
    D_dense = librosa.segment.recurrence_matrix(data, sparse=False)

    assert scipy.sparse.isspmatrix(D_sparse)
    assert np.allclose(D_sparse.todense(), D_dense)
开发者ID:dpwe,项目名称:librosa,代码行数:9,代码来源:test_segment.py


注:本文中的test_core.srand函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。