當前位置: 首頁>>代碼示例>>Python>>正文


Python strategies.randoms方法代碼示例

本文整理匯總了Python中hypothesis.strategies.randoms方法的典型用法代碼示例。如果您正苦於以下問題:Python strategies.randoms方法的具體用法?Python strategies.randoms怎麽用?Python strategies.randoms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hypothesis.strategies的用法示例。


在下文中一共展示了strategies.randoms方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extended_textual_header

# 需要導入模塊: from hypothesis import strategies [as 別名]
# 或者: from hypothesis.strategies import randoms [as 別名]
def extended_textual_header(draw, count=-1, end_text_stanza_probability=None):
    if count == -1:
        if end_text_stanza_probability is not None:
            raise ValueError("end_text_stanza_probability {} does not make sense when count is not {}"
                             .format(end_text_stanza_probability, count))
        count = draw(integers(min_value=0, max_value=10))
        headers = draw(lists(stanza(),
                             min_size=count,
                             max_size=count))
        headers.append(END_TEXT_STANZA)
        return headers

    if count == 0:
        return []

    # For counted headers, the end-text stanza is optional. We generate it
    # with the specified probability
    if end_text_stanza_probability is None:
        end_text_stanza_probability = 0.5

    random = draw(randoms())
    x = random.uniform(0.0, 1.0)
    num_data_stanzas = count - 1 if x <= end_text_stanza_probability else count

    headers = draw(lists(stanza(),
                   min_size=num_data_stanzas,
                   max_size=num_data_stanzas))

    if num_data_stanzas == count - 1:
        headers.append(END_TEXT_STANZA)

    assert len(headers) == count

    return headers 
開發者ID:sixty-north,項目名稱:segpy,代碼行數:36,代碼來源:dataset_strategy.py

示例2: csrs

# 需要導入模塊: from hypothesis import strategies [as 別名]
# 或者: from hypothesis.strategies import randoms [as 別名]
def csrs(draw, nrows=None, ncols=None, nnz=None, values=None):
    if ncols is None:
        ncols = draw(st.integers(5, 100))
    elif not isinstance(ncols, int):
        ncols = draw(ncols)

    if nrows is None:
        nrows = draw(st.integers(5, 100))
    elif not isinstance(nrows, int):
        nrows = draw(nrows)

    if nnz is None:
        nnz = draw(st.integers(10, nrows * ncols // 2))
    elif not isinstance(nnz, int):
        nnz = draw(nnz)

    coords = draw(nph.arrays(np.int32, nnz, elements=st.integers(0, nrows*ncols - 1), unique=True))
    rows = np.mod(coords, nrows, dtype=np.int32)
    cols = np.floor_divide(coords, nrows, dtype=np.int32)
    if values is None:
        values = draw(st.booleans())
    if values:
        rng = draw(st.randoms())
        vals = np.array([rng.normalvariate(0, 1) for i in range(nnz)])
    else:
        vals = None
    return matrix.CSR.from_coo(rows, cols, vals, (nrows, ncols)) 
開發者ID:lenskit,項目名稱:lkpy,代碼行數:29,代碼來源:test.py


注:本文中的hypothesis.strategies.randoms方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。