python类may_share_memory()的实例源码

test_shape_base.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_basic(self):
        d = np.ones((50, 60))
        d2 = np.ones((30, 60, 6))
        self.assertTrue(np.may_share_memory(d, d))
        self.assertTrue(np.may_share_memory(d, d[::-1]))
        self.assertTrue(np.may_share_memory(d, d[::2]))
        self.assertTrue(np.may_share_memory(d, d[1:, ::-1]))

        self.assertFalse(np.may_share_memory(d[::-1], d2))
        self.assertFalse(np.may_share_memory(d[::2], d2))
        self.assertFalse(np.may_share_memory(d[1:, ::-1], d2))
        self.assertTrue(np.may_share_memory(d2[1:, ::-1], d2))


# Utility
test_defmatrix.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_array_memory_sharing(self):
        assert_(np.may_share_memory(self.a, self.a.ravel()))
        assert_(not np.may_share_memory(self.a, self.a.flatten()))
mls.py 文件源码 项目:zignal 作者: ronnyandersson 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_full_sequence(self, repeats=1):
        """Get the full MLS sequence as audio samples, repeated n times. When
        extracting the impulse response we need to throw away the first MLS
        sequence. Hence we need to repeat the signal at least once, i.e
        repeat=2. More repetitions will mean longer signal but better signal
        to noise ratio since we will average away any noise.
        """

        chunkgen        = self.generator_samples(chunk=self.L)
        full_sequence   = chunkgen.next()
        reps_sequence   = np.tile(full_sequence.T, repeats).T
        self._logger.debug("May share memory: %s" %np.may_share_memory(full_sequence,
                                                                       reps_sequence))
        return reps_sequence
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_reindex(self):

        identity = self.series.reindex(self.series.index)

        # __array_interface__ is not defined for older numpies
        # and on some pythons
        try:
            self.assertTrue(np.may_share_memory(self.series.index,
                                                identity.index))
        except (AttributeError):
            pass

        self.assertTrue(identity.index.is_(self.series.index))
        self.assertTrue(identity.index.identical(self.series.index))

        subIndex = self.series.index[10:20]
        subSeries = self.series.reindex(subIndex)

        for idx, val in compat.iteritems(subSeries):
            self.assertEqual(val, self.series[idx])

        subIndex2 = self.ts.index[10:20]
        subTS = self.ts.reindex(subIndex2)

        for idx, val in compat.iteritems(subTS):
            self.assertEqual(val, self.ts[idx])
        stuffSeries = self.ts.reindex(subIndex)

        self.assertTrue(np.isnan(stuffSeries).all())

        # This is extremely important for the Cython code to not screw up
        nonContigIndex = self.ts.index[::2]
        subNonContig = self.ts.reindex(nonContigIndex)
        for idx, val in compat.iteritems(subNonContig):
            self.assertEqual(val, self.ts[idx])

        # return a copy the same index here
        result = self.ts.reindex()
        self.assertFalse((result is self.ts))
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_scalar_array_bool(self):
        # Numpy bools can be used as boolean index (python ones as of yet not)
        a = np.array(1)
        assert_equal(a[np.bool_(True)], a[np.array(True)])
        assert_equal(a[np.bool_(False)], a[np.array(False)])

        # After deprecating bools as integers:
        #a = np.array([0,1,2])
        #assert_equal(a[True, :], a[None, :])
        #assert_equal(a[:, True], a[:, None])
        #
        #assert_(not np.may_share_memory(a, a[True, :]))
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def _compare_index_result(self, arr, index, mimic_get, no_copy):
        """Compare mimicked result to indexing result.
        """
        arr = arr.copy()
        indexed_arr = arr[index]
        assert_array_equal(indexed_arr, mimic_get)
        # Check if we got a view, unless its a 0-sized or 0-d array.
        # (then its not a view, and that does not matter)
        if indexed_arr.size != 0 and indexed_arr.ndim != 0:
            assert_(np.may_share_memory(indexed_arr, arr) == no_copy)
            # Check reference count of the original array
            if no_copy:
                # refcount increases by one:
                assert_equal(sys.getrefcount(arr), 3)
            else:
                assert_equal(sys.getrefcount(arr), 2)

        # Test non-broadcast setitem:
        b = arr.copy()
        b[index] = mimic_get + 1000
        if b.size == 0:
            return  # nothing to compare here...
        if no_copy and indexed_arr.ndim != 0:
            # change indexed_arr in-place to manipulate original:
            indexed_arr += 1000
            assert_array_equal(arr, b)
            return
        # Use the fact that the array is originally an arange:
        arr.flat[indexed_arr.ravel()] += 1000
        assert_array_equal(arr, b)
memmap.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def __array_finalize__(self, obj):
        if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
            self._mmap = obj._mmap
            self.filename = obj.filename
            self.offset = obj.offset
            self.mode = obj.mode
        else:
            self._mmap = None
            self.filename = None
            self.offset = None
            self.mode = None
test_defmatrix.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_matrix_memory_sharing(self):
        assert_(np.may_share_memory(self.m, self.m.ravel()))
        assert_(not np.may_share_memory(self.m, self.m.flatten()))
test_indexing.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_scalar_array_bool(self):
        # Numpy bools can be used as boolean index (python ones as of yet not)
        a = np.array(1)
        assert_equal(a[np.bool_(True)], a[np.array(True)])
        assert_equal(a[np.bool_(False)], a[np.array(False)])

        # After deprecating bools as integers:
        #a = np.array([0,1,2])
        #assert_equal(a[True, :], a[None, :])
        #assert_equal(a[:, True], a[:, None])
        #
        #assert_(not np.may_share_memory(a, a[True, :]))
test_indexing.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def _compare_index_result(self, arr, index, mimic_get, no_copy):
        """Compare mimicked result to indexing result.
        """
        arr = arr.copy()
        indexed_arr = arr[index]
        assert_array_equal(indexed_arr, mimic_get)
        # Check if we got a view, unless its a 0-sized or 0-d array.
        # (then its not a view, and that does not matter)
        if indexed_arr.size != 0 and indexed_arr.ndim != 0:
            assert_(np.may_share_memory(indexed_arr, arr) == no_copy)
            # Check reference count of the original array
            if no_copy:
                # refcount increases by one:
                assert_equal(sys.getrefcount(arr), 3)
            else:
                assert_equal(sys.getrefcount(arr), 2)

        # Test non-broadcast setitem:
        b = arr.copy()
        b[index] = mimic_get + 1000
        if b.size == 0:
            return  # nothing to compare here...
        if no_copy and indexed_arr.ndim != 0:
            # change indexed_arr in-place to manipulate original:
            indexed_arr += 1000
            assert_array_equal(arr, b)
            return
        # Use the fact that the array is originally an arange:
        arr.flat[indexed_arr.ravel()] += 1000
        assert_array_equal(arr, b)
memmap.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def __array_finalize__(self, obj):
        if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
            self._mmap = obj._mmap
            self.filename = obj.filename
            self.offset = obj.offset
            self.mode = obj.mode
        else:
            self._mmap = None
            self.filename = None
            self.offset = None
            self.mode = None
test_shape_base.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_basic(self):
        d = np.ones((50, 60))
        d2 = np.ones((30, 60, 6))
        self.assertTrue(np.may_share_memory(d, d))
        self.assertTrue(np.may_share_memory(d, d[::-1]))
        self.assertTrue(np.may_share_memory(d, d[::2]))
        self.assertTrue(np.may_share_memory(d, d[1:, ::-1]))

        self.assertFalse(np.may_share_memory(d[::-1], d2))
        self.assertFalse(np.may_share_memory(d[::2], d2))
        self.assertFalse(np.may_share_memory(d[1:, ::-1], d2))
        self.assertTrue(np.may_share_memory(d2[1:, ::-1], d2))


# Utility
test_defmatrix.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_matrix_memory_sharing(self):
        assert_(np.may_share_memory(self.m, self.m.ravel()))
        assert_(not np.may_share_memory(self.m, self.m.flatten()))
memmap.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def __array_finalize__(self, obj):
        if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
            self._mmap = obj._mmap
            self.filename = obj.filename
            self.offset = obj.offset
            self.mode = obj.mode
        else:
            self._mmap = None
            self.filename = None
            self.offset = None
            self.mode = None
test_indexing.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_scalar_array_bool(self):
        # Numpy bools can be used as boolean index (python ones as of yet not)
        a = np.array(1)
        assert_equal(a[np.bool_(True)], a[np.array(True)])
        assert_equal(a[np.bool_(False)], a[np.array(False)])

        # After deprecating bools as integers:
        #a = np.array([0,1,2])
        #assert_equal(a[True, :], a[None, :])
        #assert_equal(a[:, True], a[:, None])
        #
        #assert_(not np.may_share_memory(a, a[True, :]))
test_indexing.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def _compare_index_result(self, arr, index, mimic_get, no_copy):
        """Compare mimicked result to indexing result.
        """
        arr = arr.copy()
        indexed_arr = arr[index]
        assert_array_equal(indexed_arr, mimic_get)
        # Check if we got a view, unless its a 0-sized or 0-d array.
        # (then its not a view, and that does not matter)
        if indexed_arr.size != 0 and indexed_arr.ndim != 0:
            assert_(np.may_share_memory(indexed_arr, arr) == no_copy)
            # Check reference count of the original array
            if no_copy:
                # refcount increases by one:
                assert_equal(sys.getrefcount(arr), 3)
            else:
                assert_equal(sys.getrefcount(arr), 2)

        # Test non-broadcast setitem:
        b = arr.copy()
        b[index] = mimic_get + 1000
        if b.size == 0:
            return  # nothing to compare here...
        if no_copy and indexed_arr.ndim != 0:
            # change indexed_arr in-place to manipulate original:
            indexed_arr += 1000
            assert_array_equal(arr, b)
            return
        # Use the fact that the array is originally an arange:
        arr.flat[indexed_arr.ravel()] += 1000
        assert_array_equal(arr, b)
memmap.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def __array_finalize__(self, obj):
        if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
            self._mmap = obj._mmap
            self.filename = obj.filename
            self.offset = obj.offset
            self.mode = obj.mode
        else:
            self._mmap = None
            self.filename = None
            self.offset = None
            self.mode = None
test_shape_base.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_basic(self):
        d = np.ones((50, 60))
        d2 = np.ones((30, 60, 6))
        self.assertTrue(np.may_share_memory(d, d))
        self.assertTrue(np.may_share_memory(d, d[::-1]))
        self.assertTrue(np.may_share_memory(d, d[::2]))
        self.assertTrue(np.may_share_memory(d, d[1:, ::-1]))

        self.assertFalse(np.may_share_memory(d[::-1], d2))
        self.assertFalse(np.may_share_memory(d[::2], d2))
        self.assertFalse(np.may_share_memory(d[1:, ::-1], d2))
        self.assertTrue(np.may_share_memory(d2[1:, ::-1], d2))


# Utility
test_defmatrix.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_array_memory_sharing(self):
        assert_(np.may_share_memory(self.a, self.a.ravel()))
        assert_(not np.may_share_memory(self.a, self.a.flatten()))
test_indexing.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def test_scalar_array_bool(self):
        # NumPy bools can be used as boolean index (python ones as of yet not)
        a = np.array(1)
        assert_equal(a[np.bool_(True)], a[np.array(True)])
        assert_equal(a[np.bool_(False)], a[np.array(False)])

        # After deprecating bools as integers:
        #a = np.array([0,1,2])
        #assert_equal(a[True, :], a[None, :])
        #assert_equal(a[:, True], a[:, None])
        #
        #assert_(not np.may_share_memory(a, a[True, :]))


问题


面经


文章

微信
公众号

扫码关注公众号