コード例 #1
0
ファイル: test__gcutils.py プロジェクト: 317070/scipy
def test_assert_deallocated():
    # Ordinary use
    class C(object):
        def __init__(self, arg0, arg1, name='myname'):
            self.name = name
    for gc_current in (True, False):
        with gc_state(gc_current):
            # We are deleting from with-block context, so that's OK
            with assert_deallocated(C, 0, 2, 'another name') as c:
                assert_equal(c.name, 'another name')
                del c
            # Or not using the thing in with-block context, also OK
            with assert_deallocated(C, 0, 2, name='third name'):
                pass
            assert_equal(gc.isenabled(), gc_current)
コード例 #2
0
ファイル: test__gcutils.py プロジェクト: 317070/scipy
def test_assert_deallocated_circular2():
    class C(object):
        def __init__(self):
            self._circular = self
    # Still circular reference, no automatic garbage collection
    with assert_deallocated(C):
        pass
コード例 #3
0
ファイル: test__gcutils.py プロジェクト: rblomberg/scipy
def test_assert_deallocated_nodel():
    class C(object):
        pass

    # Need to delete after using if in with-block context
    with assert_deallocated(C) as c:
        pass
コード例 #4
0
ファイル: test__gcutils.py プロジェクト: rblomberg/scipy
def test_assert_deallocated():
    # Ordinary use
    class C(object):
        def __init__(self, arg0, arg1, name='myname'):
            self.name = name

    for gc_current in (True, False):
        with gc_state(gc_current):
            # We are deleting from with-block context, so that's OK
            with assert_deallocated(C, 0, 2, 'another name') as c:
                assert_equal(c.name, 'another name')
                del c
            # Or not using the thing in with-block context, also OK
            with assert_deallocated(C, 0, 2, name='third name'):
                pass
            assert_equal(gc.isenabled(), gc_current)
コード例 #5
0
ファイル: test_interpolate.py プロジェクト: alouisos/scipy
 def test_circular_refs(self):
     # Test interp1d can be automatically garbage collected
     x = np.linspace(0, 1)
     y = np.linspace(0, 1)
     # Confirm interp can be released from memory after use
     with assert_deallocated(interp1d, x, y) as interp:
         new_y = interp([0.1, 0.2])
         del interp
コード例 #6
0
ファイル: test_interpolate.py プロジェクト: AGPeddle/scipy
 def test_circular_refs(self):
     # Test interp1d can be automatically garbage collected
     x = np.linspace(0, 1)
     y = np.linspace(0, 1)
     # Confirm interp can be released from memory after use
     with assert_deallocated(interp1d, x, y) as interp:
         new_y = interp([0.1, 0.2])
         del interp
コード例 #7
0
ファイル: test__gcutils.py プロジェクト: rblomberg/scipy
def test_assert_deallocated_circular2():
    class C(object):
        def __init__(self):
            self._circular = self

    # Still circular reference, no automatic garbage collection
    with assert_deallocated(C):
        pass
コード例 #8
0
def test_linearoperator_deallocation():
    # Check that the linear operators used by the Arpack wrappers are
    # deallocatable by reference counting -- they are big objects, so
    # Python's cyclic GC may not collect them fast enough before
    # running out of memory if eigs/eigsh are called in a tight loop.

    M_d = np.eye(10)
    M_s = csc_matrix(M_d)
    M_o = aslinearoperator(M_d)

    with assert_deallocated(lambda: arpack.SpLuInv(M_s)):
        pass
    with assert_deallocated(lambda: arpack.LuInv(M_d)):
        pass
    with assert_deallocated(lambda: arpack.IterInv(M_s)):
        pass
    with assert_deallocated(lambda: arpack.IterOpInv(M_o, None, 0.3)):
        pass
    with assert_deallocated(lambda: arpack.IterOpInv(M_o, M_o, 0.3)):
        pass
コード例 #9
0
ファイル: test__gcutils.py プロジェクト: 317070/scipy
def test_assert_deallocated_nodel():
    class C(object):
        pass
    # Need to delete after using if in with-block context
    with assert_deallocated(C) as c:
        pass