• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python test_core.srand函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: __test

    def __test(x, y, sparse):
        srand()

        X = np.empty((10, 100))
        # Build a recurrence matrix, just for testing purposes
        rec = np.random.randn(x, y)
        if sparse:
            rec = scipy.sparse.csr_matrix(rec)

        librosa.decompose.nn_filter(X, rec=rec)
开发者ID:Cortexelus,项目名称:librosa,代码行数:10,代码来源:test_decompose.py


示例17: test_recurrence_distance

def test_recurrence_distance():

    srand()
    data = np.random.randn(3, 100)
    distance = squareform(pdist(data.T, metric='sqeuclidean'))
    rec = librosa.segment.recurrence_matrix(data, mode='distance',
                                            metric='sqeuclidean',
                                            sparse=True)

    i, j, vals = scipy.sparse.find(rec)
    assert np.allclose(vals, distance[i, j])
开发者ID:dpwe,项目名称:librosa,代码行数:11,代码来源:test_segment.py


示例18: test_nn_filter_mean_rec_sparse

def test_nn_filter_mean_rec_sparse():

    srand()
    X = np.random.randn(10, 100)

    # Build a recurrence matrix, just for testing purposes
    rec = librosa.segment.recurrence_matrix(X, sparse=True)

    X_filtered = librosa.decompose.nn_filter(X, rec=rec)

    # Normalize the recurrence matrix
    rec = librosa.util.normalize(rec.toarray(), axis=1, norm=1)
    assert np.allclose(X_filtered, (X.dot(rec.T)))
开发者ID:Cortexelus,项目名称:librosa,代码行数:13,代码来源:test_decompose.py


示例19: test_normalize

def test_normalize():
    srand()

    def __test_pass(X, norm, axis):
        X_norm = librosa.util.normalize(X, norm=norm, axis=axis)

        # Shape and dtype checks
        assert X_norm.dtype == X.dtype
        assert X_norm.shape == X.shape

        if norm is None:
            assert np.allclose(X, X_norm)
            return

        X_norm = np.abs(X_norm)

        if norm == np.inf:
            values = np.max(X_norm, axis=axis)
        elif norm == -np.inf:
            values = np.min(X_norm, axis=axis)
        elif norm == 0:
            # XXX: normalization here isn't quite right
            values = np.ones(1)

        else:
            values = np.sum(X_norm**norm, axis=axis)**(1./norm)

        assert np.allclose(values, np.ones_like(values))

    @raises(librosa.ParameterError)
    def __test_fail(X, norm, axis):
        librosa.util.normalize(X, norm=norm, axis=axis)

    for ndims in [1, 2, 3]:
        X = np.random.randn(* ([16] * ndims))

        for axis in range(X.ndim):
            for norm in [np.inf, -np.inf, 0, 0.5, 1.0, 2.0, None]:
                yield __test_pass, X, norm, axis

            for norm in ['inf', -0.5, -2]:
                yield __test_fail, X, norm, axis

        # And test for non-finite failure
        X[0] = np.nan
        yield __test_fail, X, np.inf, 0

        X[0] = np.inf
        yield __test_fail, X, np.inf, 0
        X[0] = -np.inf
        yield __test_fail, X, np.inf, 0
开发者ID:baifengbai,项目名称:librosa,代码行数:51,代码来源:test_util.py


示例20: test_nn_filter_mean

def test_nn_filter_mean():

    srand()
    X = np.random.randn(10, 100)

    # Build a recurrence matrix, just for testing purposes
    rec = librosa.segment.recurrence_matrix(X)

    X_filtered = librosa.decompose.nn_filter(X)

    # Normalize the recurrence matrix so dotting computes an average
    rec = librosa.util.normalize(rec.astype(np.float), axis=1, norm=1)

    assert np.allclose(X_filtered, X.dot(rec.T))
开发者ID:ai-learn-use,项目名称:librosa,代码行数:14,代码来源:test_decompose.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_dm_utils.FakeDeviceConnect类代码示例发布时间:2022-05-27
下一篇:
Python test_connection.get_connection函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap