test_regression.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:deliver 作者: orchestor 项目源码 文件源码
def test_object_array_self_reference(self):
        # Object arrays with references to themselves can cause problems
        a = np.array(0, dtype=object)
        a[()] = a
        assert_raises(TypeError, int, a)
        assert_raises(TypeError, long, a)
        assert_raises(TypeError, float, a)
        assert_raises(TypeError, oct, a)
        assert_raises(TypeError, hex, a)

        # Test the same for a circular reference.
        b = np.array(a, dtype=object)
        a[()] = b
        assert_raises(TypeError, int, a)
        # NumPy has no tp_traverse currently, so circular references
        # cannot be detected. So resolve it:
        a[()] = 0

        # This was causing a to become like the above
        a = np.array(0, dtype=object)
        a[...] += 1
        assert_equal(a, 1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号