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


Python _multiarray_tests.internal_overlap方法代码示例

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


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

示例1: check_internal_overlap

# 需要导入模块: from numpy.core import _multiarray_tests [as 别名]
# 或者: from numpy.core._multiarray_tests import internal_overlap [as 别名]
def check_internal_overlap(a, manual_expected=None):
    got = internal_overlap(a)

    # Brute-force check
    m = set()
    ranges = tuple(xrange(n) for n in a.shape)
    for v in itertools.product(*ranges):
        offset = sum(s*w for s, w in zip(a.strides, v))
        if offset in m:
            expected = True
            break
        else:
            m.add(offset)
    else:
        expected = False

    # Compare
    if got != expected:
        assert_equal(got, expected, err_msg=repr((a.strides, a.shape)))
    if manual_expected is not None and expected != manual_expected:
        assert_equal(expected, manual_expected)
    return got 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_mem_overlap.py

示例2: test_internal_overlap_slices

# 需要导入模块: from numpy.core import _multiarray_tests [as 别名]
# 或者: from numpy.core._multiarray_tests import internal_overlap [as 别名]
def test_internal_overlap_slices():
    # Slicing an array never generates internal overlap

    x = np.zeros([17,34,71,97], dtype=np.int16)

    rng = np.random.RandomState(1234)

    def random_slice(n, step):
        start = rng.randint(0, n+1, dtype=np.intp)
        stop = rng.randint(start, n+1, dtype=np.intp)
        if rng.randint(0, 2, dtype=np.intp) == 0:
            stop, start = start, stop
            step *= -1
        return slice(start, stop, step)

    cases = 0
    min_count = 5000

    while cases < min_count:
        steps = tuple(rng.randint(1, 11, dtype=np.intp)
                      if rng.randint(0, 5, dtype=np.intp) == 0 else 1
                      for j in range(x.ndim))
        t1 = np.arange(x.ndim)
        rng.shuffle(t1)
        s1 = tuple(random_slice(p, s) for p, s in zip(x.shape, steps))
        a = x[s1].transpose(t1)

        assert_(not internal_overlap(a))
        cases += 1 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:31,代码来源:test_mem_overlap.py


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