コード例 #1
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__coverage(data: Any, x: NDArray) -> None:
    # Draw block size that is no less than 1 but possibly
    # greater than or equal to the size of the array
    size = data.draw(st.integers(min_value=1, max_value=len(x) + 1))
    idx, sizes = index_array_blocks(x, size)
    assert sizes.sum() == x.size
    assert idx.ndim == sizes.ndim == 1
    assert idx.size == sizes.size
    chunks = []
    for i in range(idx.size):
        start, stop = idx[i], idx[i] + sizes[i]
        chunk = x[slice(start, stop)]
        assert len(chunk) <= size
        chunks.append(chunk)
    if chunks:
        np.testing.assert_equal(np.concatenate(chunks), x)
コード例 #2
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__raise_on_not_monotonic_increasing():
    with pytest.raises(
        ValueError, match="Array to partition must be monotonic increasing"
    ):
        index_array_blocks([0, 1, 1, 1, 0], 3)
コード例 #3
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__raise_on_non_int():
    with pytest.raises(ValueError, match="Array to partition must contain integers"):
        index_array_blocks([1.0, 2.0, 3.0], 3)
コード例 #4
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__raise_on_size_lte_0():
    with pytest.raises(ValueError, match=r"Block size .* must be > 0"):
        index_array_blocks([1, 2, 3], 0)
コード例 #5
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__raise_on_not_1d():
    with pytest.raises(ValueError, match=r"Array shape .* is not 1D"):
        index_array_blocks([[1]], 1)
コード例 #6
0
ファイル: test_regenie.py プロジェクト: timothymillar/sgkit
def test_index_array_blocks__basic(
    x: Any, size: int, expected_index: Any, expected_sizes: Any
) -> None:
    index, sizes = index_array_blocks(x, size)
    np.testing.assert_equal(index, expected_index)
    np.testing.assert_equal(sizes, expected_sizes)