Exemplo n.º 1
0
def test_swap_blocks():
    """Test block-wise swapping of samples."""
    d = Data()
    d.generate_mute_data()

    # block_size divides the length of the data to be permuted, swap_range
    # leads to 2 remaining blocks
    n = 50
    block_size = 5
    swap_range = 4
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'

    # block_size leads to one block of length 1, swap_range divides the no.
    # blocks
    n = 50
    block_size = 7
    swap_range = 4
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
    n_blocks = np.ceil(n / 7).astype(int)
    assert n_blocks == 8, 'No. blocks is incorrect.'
    assert sum(perm == n_blocks - 1) == 1, ('No. remaining samples in the last'
                                            ' block is incorrect.')

    # no remaining samples or blocks
    n = 30
    block_size = 5
    swap_range = 3
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
Exemplo n.º 2
0
def test_swap_blocks():
    """Test block-wise swapping of samples."""
    d = Data()
    d.generate_mute_data()

    # block_size divides the length of the data to be permuted, swap_range
    # leads to 2 remaining blocks
    n = 50
    block_size = 5
    swap_range = 4
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'

    # block_size leads to one block of length 1, swap_range divides the no.
    # blocks
    n = 50
    block_size = 7
    swap_range = 4
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
    n_blocks = np.ceil(n/7).astype(int)
    assert n_blocks == 8, 'No. blocks is incorrect.'
    assert sum(perm == n_blocks - 1) == 1, ('No. remaining samples in the last'
                                            ' block is incorrect.')

    # no remaining samples or blocks
    n = 30
    block_size = 5
    swap_range = 3
    perm = d._swap_blocks(n, block_size, swap_range)
    assert perm.shape[0] == n, 'Incorrect length of permuted indices.'