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


Python HealthCheck.all方法代码示例

本文整理汇总了Python中hypothesis.HealthCheck.all方法的典型用法代码示例。如果您正苦于以下问题:Python HealthCheck.all方法的具体用法?Python HealthCheck.all怎么用?Python HealthCheck.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hypothesis.HealthCheck的用法示例。


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

示例1: test_csr_from_sps

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_from_sps(copy):
    # initialize sparse matrix
    mat = np.random.randn(10, 5)
    mat[mat <= 0] = 0
    smat = sps.csr_matrix(mat)
    # make sure it's sparse
    assert smat.nnz == np.sum(mat > 0)

    csr = lm.CSR.from_scipy(smat, copy=copy)
    assert csr.nnz == smat.nnz
    assert csr.nrows == smat.shape[0]
    assert csr.ncols == smat.shape[1]

    assert all(csr.rowptrs == smat.indptr)
    assert all(csr.colinds == smat.indices)
    assert all(csr.values == smat.data)
    assert isinstance(csr.rowptrs, np.ndarray)
    assert isinstance(csr.colinds, np.ndarray)
    assert isinstance(csr.values, np.ndarray) 
开发者ID:lenskit,项目名称:lkpy,代码行数:21,代码来源:test_matrix_csr.py

示例2: test_csr_transpose

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_transpose():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)
    csc = csr.transpose()
    assert csc.nrows == csr.ncols
    assert csc.ncols == csr.nrows

    assert all(csc.rowptrs == [0, 1, 3, 4])
    assert csc.colinds.max() == 3
    assert csc.values.sum() == approx(vals.sum())

    for r, c, v in zip(rows, cols, vals):
        row = csc.row(c)
        assert row[r] == v 
开发者ID:lenskit,项目名称:lkpy,代码行数:19,代码来源:test_matrix_csr.py

示例3: test_csr_transpose_coords

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_transpose_coords():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)
    csc = csr.transpose(False)
    assert csc.nrows == csr.ncols
    assert csc.ncols == csr.nrows

    assert all(csc.rowptrs == [0, 1, 3, 4])
    assert csc.colinds.max() == 3
    assert csc.values is None

    for r, c, v in zip(rows, cols, vals):
        row = csc.row(c)
        assert row[r] == 1 
开发者ID:lenskit,项目名称:lkpy,代码行数:19,代码来源:test_matrix_csr.py

示例4: test_csr_transpose_erow

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_transpose_erow():
    nrows = np.random.randint(10, 1000)
    ncols = np.random.randint(10, 500)
    mat = np.random.randn(nrows, ncols)
    mat[mat <= 0] = 0
    mat[:, 0:1] = 0
    smat = sps.csr_matrix(mat)

    csr = lm.CSR.from_scipy(smat)
    csrt = csr.transpose()
    assert csrt.nrows == ncols
    assert csrt.ncols == nrows

    s2 = csrt.to_scipy()
    smat = smat.T.tocsr()
    assert all(smat.indptr == csrt.rowptrs)

    assert np.all(s2.toarray() == smat.toarray()) 
开发者ID:lenskit,项目名称:lkpy,代码行数:20,代码来源:test_matrix_csr.py

示例5: test_csr_from_coo_novals

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_from_coo_novals():
    for i in range(50):
        coords = np.random.choice(np.arange(50 * 100, dtype=np.int32), 1000, False)
        rows = np.mod(coords, 100, dtype=np.int32)
        cols = np.floor_divide(coords, 100, dtype=np.int32)

        csr = lm.CSR.from_coo(rows, cols, None, (100, 50))
        assert csr.nrows == 100
        assert csr.ncols == 50
        assert csr.nnz == 1000

        for i in range(100):
            sp = csr.rowptrs[i]
            ep = csr.rowptrs[i+1]
            assert ep - sp == np.sum(rows == i)
            points, = np.nonzero(rows == i)
            po = np.argsort(cols[points])
            points = points[po]
            assert all(np.sort(csr.colinds[sp:ep]) == cols[points])
            assert np.sum(csr.row(i)) == len(points) 
开发者ID:lenskit,项目名称:lkpy,代码行数:22,代码来源:test_matrix_csr.py

示例6: test_csr_to_sps

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_to_sps():
    # initialize sparse matrix
    mat = np.random.randn(10, 5)
    mat[mat <= 0] = 0
    # get COO
    smat = sps.coo_matrix(mat)
    # make sure it's sparse
    assert smat.nnz == np.sum(mat > 0)

    csr = lm.CSR.from_coo(smat.row, smat.col, smat.data, shape=smat.shape)
    assert csr.nnz == smat.nnz
    assert csr.nrows == smat.shape[0]
    assert csr.ncols == smat.shape[1]

    smat2 = csr.to_scipy()
    assert sps.isspmatrix(smat2)
    assert sps.isspmatrix_csr(smat2)

    for i in range(csr.nrows):
        assert smat2.indptr[i] == csr.rowptrs[i]
        assert smat2.indptr[i+1] == csr.rowptrs[i+1]
        sp = smat2.indptr[i]
        ep = smat2.indptr[i+1]
        assert all(smat2.indices[sp:ep] == csr.colinds[sp:ep])
        assert all(smat2.data[sp:ep] == csr.values[sp:ep]) 
开发者ID:lenskit,项目名称:lkpy,代码行数:27,代码来源:test_matrix_csr.py

示例7: test_csr_rowinds

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_rowinds():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)
    csr = lm.CSR.from_coo(rows, cols, vals)

    ris = csr.rowinds()
    assert all(ris == rows) 
开发者ID:lenskit,项目名称:lkpy,代码行数:10,代码来源:test_matrix_csr.py

示例8: test_csr_set_values

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_set_values():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)

    v2 = np.random.randn(4)
    csr.values = v2

    assert all(csr.values == v2) 
开发者ID:lenskit,项目名称:lkpy,代码行数:13,代码来源:test_matrix_csr.py

示例9: test_csr_set_values_oversize

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_set_values_oversize():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)

    v2 = np.random.randn(6)
    csr.values = v2

    assert all(csr.values == v2[:4]) 
开发者ID:lenskit,项目名称:lkpy,代码行数:13,代码来源:test_matrix_csr.py

示例10: test_csr_set_values_undersize

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_set_values_undersize():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)

    v2 = np.random.randn(3)

    with raises(ValueError):
        csr.values = v2

    assert all(csr.values == vals) 
开发者ID:lenskit,项目名称:lkpy,代码行数:15,代码来源:test_matrix_csr.py

示例11: test_csr_row

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_row():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_) + 1

    csr = lm.CSR.from_coo(rows, cols, vals)
    assert all(csr.row(0) == np.array([0, 1, 2], dtype=np.float_))
    assert all(csr.row(1) == np.array([3, 0, 0], dtype=np.float_))
    assert all(csr.row(2) == np.array([0, 0, 0], dtype=np.float_))
    assert all(csr.row(3) == np.array([0, 4, 0], dtype=np.float_)) 
开发者ID:lenskit,项目名称:lkpy,代码行数:12,代码来源:test_matrix_csr.py

示例12: test_csr_sparse_row

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_sparse_row():
    rows = np.array([0, 0, 1, 3], dtype=np.int32)
    cols = np.array([1, 2, 0, 1], dtype=np.int32)
    vals = np.arange(4, dtype=np.float_)

    csr = lm.CSR.from_coo(rows, cols, vals)
    assert all(csr.row_cs(0) == np.array([1, 2], dtype=np.int32))
    assert all(csr.row_cs(1) == np.array([0], dtype=np.int32))
    assert all(csr.row_cs(2) == np.array([], dtype=np.int32))
    assert all(csr.row_cs(3) == np.array([1], dtype=np.int32))

    assert all(csr.row_vs(0) == np.array([0, 1], dtype=np.float_))
    assert all(csr.row_vs(1) == np.array([2], dtype=np.float_))
    assert all(csr.row_vs(2) == np.array([], dtype=np.float_))
    assert all(csr.row_vs(3) == np.array([3], dtype=np.float_)) 
开发者ID:lenskit,项目名称:lkpy,代码行数:17,代码来源:test_matrix_csr.py

示例13: test_csr_from_coo_rand

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_from_coo_rand():
    for i in range(100):
        coords = np.random.choice(np.arange(50 * 100, dtype=np.int32), 1000, False)
        rows = np.mod(coords, 100, dtype=np.int32)
        cols = np.floor_divide(coords, 100, dtype=np.int32)
        vals = np.random.randn(1000)

        csr = lm.CSR.from_coo(rows, cols, vals, (100, 50))
        rowinds = csr.rowinds()
        assert csr.nrows == 100
        assert csr.ncols == 50
        assert csr.nnz == 1000

        for i in range(100):
            sp = csr.rowptrs[i]
            ep = csr.rowptrs[i+1]
            assert ep - sp == np.sum(rows == i)
            points, = np.nonzero(rows == i)
            assert len(points) == ep - sp
            po = np.argsort(cols[points])
            points = points[po]
            assert all(np.sort(csr.colinds[sp:ep]) == cols[points])
            assert all(np.sort(csr.row_cs(i)) == cols[points])
            assert all(csr.values[np.argsort(csr.colinds[sp:ep]) + sp] == vals[points])
            assert all(rowinds[sp:ep] == i)

            row = np.zeros(50)
            row[cols[points]] = vals[points]
            assert np.sum(csr.row(i)) == approx(np.sum(vals[points]))
            assert all(csr.row(i) == row) 
开发者ID:lenskit,项目名称:lkpy,代码行数:32,代码来源:test_matrix_csr.py

示例14: test_filter

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_filter(csr):
    assume(not np.all(csr.values <= 0))  # we have to have at least one to retain
    csrf = csr.filter_nnzs(csr.values > 0)
    assert all(csrf.values > 0)
    assert csrf.nnz <= csr.nnz

    for i in range(csr.nrows):
        spo, epo = csr.row_extent(i)
        spf, epf = csrf.row_extent(i)
        assert epf - spf <= epo - spo

    d1 = csr.to_scipy().toarray()
    df = csrf.to_scipy().toarray()
    d1[d1 < 0] = 0
    assert df == approx(d1) 
开发者ID:lenskit,项目名称:lkpy,代码行数:17,代码来源:test_matrix_csr.py

示例15: test_csr_pickle

# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
def test_csr_pickle(csr):
    data = pickle.dumps(csr)
    csr2 = pickle.loads(data)

    assert csr2.nrows == csr.nrows
    assert csr2.ncols == csr.ncols
    assert csr2.nnz == csr.nnz
    assert all(csr2.rowptrs == csr.rowptrs)
    assert all(csr2.colinds == csr.colinds)
    if csr.values is not None:
        assert all(csr2.values == csr.values)
    else:
        assert csr2.values is None 
开发者ID:lenskit,项目名称:lkpy,代码行数:15,代码来源:test_matrix_csr.py


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