• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.may_share_memory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.may_share_memory函数的典型用法代码示例。如果您正苦于以下问题:Python may_share_memory函数的具体用法?Python may_share_memory怎么用?Python may_share_memory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_BandMat_sub

    def test_BandMat_sub(self, its=100):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            a_bm = gen_BandMat(size)
            b_bm = gen_BandMat(size)
            a_full = a_bm.full()
            b_full = b_bm.full()

            c_bm = a_bm - b_bm
            c_full = a_full - b_full
            assert_allclose(c_bm.full(), c_full)
            assert not np.may_share_memory(c_bm.data, a_bm.data)
            assert not np.may_share_memory(c_bm.data, b_bm.data)

            c_bm = a_bm - 0
            c_full = a_full - 0
            assert_allclose(c_bm.full(), c_full)
            assert not np.may_share_memory(c_bm.data, a_bm.data)

            c_bm = 0 - a_bm
            c_full = 0 - a_full
            assert_allclose(c_bm.full(), c_full)
            assert not np.may_share_memory(c_bm.data, a_bm.data)

            with self.assertRaises(TypeError):
                a_bm - 1.0
            with self.assertRaises(TypeError):
                1.0 - a_bm
开发者ID:wuaalb,项目名称:bandmat,代码行数:28,代码来源:test_core.py


示例2: test_no_aliasing_2

    def test_no_aliasing_2(self):
        # B and A take one another's values
        # no copying is necessary since each one is updated.
        orig_a = numpy.zeros((2,2))+.5
        orig_b = numpy.zeros((2,2))-.5
        A = self.shared(orig_a)
        B = self.shared(orig_b)
        C = tensor.dmatrix()

        z = numpy.zeros((2,2))

        data_of_a = data_of(A)
        data_of_b = data_of(B)

        f = pfunc([C], [], updates=[(A,B),(B,A)])
        f(z)
        # correctness
        assert numpy.all(data_of(A) == -.5)
        assert numpy.all(data_of(B) == +.5)

        # shared vars may not be aliased
        assert not numpy.may_share_memory(data_of(A), data_of(B))

        # theano should have been smart enough to not make copies
        assert numpy.may_share_memory(data_of(A), data_of_b)
        assert numpy.may_share_memory(data_of(B), data_of_a)
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:26,代码来源:test_pfunc.py


示例3: test_nodes_at_link

def test_nodes_at_link():
    """Test nodes_at_link shares data with tail and head."""
    assert_array_equal(rmg.nodes_at_link[:, 0], rmg.node_at_link_tail)
    assert_array_equal(rmg.nodes_at_link[:, 1], rmg.node_at_link_head)

    assert_true(np.may_share_memory(rmg.nodes_at_link, rmg.node_at_link_tail))
    assert_true(np.may_share_memory(rmg.nodes_at_link, rmg.node_at_link_head))
开发者ID:awickert,项目名称:landlab,代码行数:7,代码来源:test_init.py


示例4: check_may_share_memory_easy_fuzz

def check_may_share_memory_easy_fuzz(get_max_work, same_steps, min_count):
    # Check that overlap problems with common strides are solved with
    # little work.
    x = np.zeros([17,34,71,97], dtype=np.int16)

    feasible = 0
    infeasible = 0

    pair_iter = iter_random_view_pairs(x, same_steps)

    while min(feasible, infeasible) < min_count:
        a, b = next(pair_iter)

        bounds_overlap = np.may_share_memory(a, b)
        may_share_answer = np.may_share_memory(a, b)
        easy_answer = np.may_share_memory(a, b, max_work=get_max_work(a, b))
        exact_answer = np.may_share_memory(a, b, max_work=MAY_SHARE_EXACT)

        if easy_answer != exact_answer:
            # assert_equal is slow...
            assert_equal(easy_answer, exact_answer)

        if may_share_answer != bounds_overlap:
            assert_equal(may_share_answer, bounds_overlap)

        if bounds_overlap:
            if exact_answer:
                feasible += 1
            else:
                infeasible += 1
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:30,代码来源:test_mem_overlap.py


示例5: test_transpose

    def test_transpose(self):
        s0_transpose = self.s0.transpose()
        s0_diff = s0_transpose.differentials['s']
        assert s0_transpose.shape == (7, 6)
        assert s0_diff.shape == s0_transpose.shape
        assert np.all(s0_transpose.lon == self.s0.lon.transpose())
        assert np.all(s0_diff.d_lon == self.diff.d_lon.transpose())
        assert np.may_share_memory(s0_transpose.distance, self.s0.distance)
        assert np.may_share_memory(s0_diff.d_lon, self.diff.d_lon)

        s1_transpose = self.s1.transpose()
        s1_diff = s1_transpose.differentials['s']
        assert s1_transpose.shape == (7, 6)
        assert s1_diff.shape == s1_transpose.shape
        assert np.all(s1_transpose.lat == self.s1.lat.transpose())
        assert np.all(s1_diff.d_lon == self.diff.d_lon.transpose())
        assert np.may_share_memory(s1_transpose.lat, self.s1.lat)
        assert np.may_share_memory(s1_diff.d_lon, self.diff.d_lon)

        # Only one check on T, since it just calls transpose anyway.
        # Doing it on the CartesianRepresentation just for variety's sake.
        c0_T = self.c0.T
        assert c0_T.shape == (7, 6)
        assert np.all(c0_T.x == self.c0.x.T)
        assert np.may_share_memory(c0_T.y, self.c0.y)
开发者ID:AustereCuriosity,项目名称:astropy,代码行数:25,代码来源:test_representation_methods.py


示例6: test_non_ndarray_inputs

def test_non_ndarray_inputs():
    # Regression check for gh-5604

    class MyArray(object):
        def __init__(self, data):
            self.data = data

        @property
        def __array_interface__(self):
            return self.data.__array_interface__

    class MyArray2(object):
        def __init__(self, data):
            self.data = data

        def __array__(self):
            return self.data

    for cls in [MyArray, MyArray2]:
        x = np.arange(5)

        assert_(np.may_share_memory(cls(x[::2]), x[1::2]))
        assert_(not np.shares_memory(cls(x[::2]), x[1::2]))

        assert_(np.shares_memory(cls(x[1::3]), x[::2]))
        assert_(np.may_share_memory(cls(x[1::3]), x[::2]))
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:26,代码来源:test_mem_overlap.py


示例7: test_dot_mm_partial

    def test_dot_mm_partial(self, its=50):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            a_bm = gen_BandMat(size)
            b_bm = gen_BandMat(size)
            l = random.choice([0, 1, randint(0, 10)])
            u = random.choice([0, 1, randint(0, 10)])
            diag = None if rand_bool() else randn(size)
            diag_value = np.ones((size,)) if diag is None else diag
            a_full = a_bm.full()
            b_full = b_bm.full()

            c_bm = bm.dot_mm_partial(l, u, a_bm, b_bm, diag=diag)
            c_full = fl.band_ec(
                l, u,
                np.dot(np.dot(a_full, np.diag(diag_value)), b_full)
            )
            assert c_bm.l == l
            assert c_bm.u == u
            assert c_bm.size == size
            assert_allclose(c_bm.full(), c_full)
            assert not np.may_share_memory(c_bm.data, a_bm.data)
            assert not np.may_share_memory(c_bm.data, b_bm.data)
            if diag is not None:
                assert not np.may_share_memory(c_bm.data, diag)
开发者ID:wuaalb,项目名称:bandmat,代码行数:25,代码来源:test_tensor.py


示例8: test_nodes_at_link

def test_nodes_at_link():
    """Test nodes_at_link shares data with tail and head."""
    rmg = RasterModelGrid((4, 5), spacing=1.)
    assert_array_equal(rmg.nodes_at_link[:, 0], rmg.node_at_link_tail)
    assert_array_equal(rmg.nodes_at_link[:, 1], rmg.node_at_link_head)

    assert np.may_share_memory(rmg.nodes_at_link, rmg.node_at_link_tail)
    assert np.may_share_memory(rmg.nodes_at_link, rmg.node_at_link_head)
开发者ID:Glader011235,项目名称:Landlab,代码行数:8,代码来源:test_init.py


示例9: test_no_copy

def test_no_copy():
    c1 = SkyCoord(np.arange(10.) * u.hourangle, np.arange(20., 30.) * u.deg)
    c2 = SkyCoord(c1, copy=False)
    # Note: c1.ra and c2.ra will *not* share memory, as these are recalculated
    # to be in "preferred" units.  See discussion in #4883.
    assert np.may_share_memory(c1.data.lon, c2.data.lon)
    c3 = SkyCoord(c1, copy=True)
    assert not np.may_share_memory(c1.data.lon, c3.data.lon)
开发者ID:amaurea,项目名称:astropy,代码行数:8,代码来源:test_sky_coord.py


示例10: test__solve_triangular_banded

    def test__solve_triangular_banded(self, its=100):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            b = randn(size)
            chol_bm = gen_chol_factor_BandMat(size, transposed=False)
            chol_data = chol_bm.data
            depth = chol_bm.l + chol_bm.u
            lower = (chol_bm.u == 0)
            if size > 0 and rand_bool() and rand_bool():
                badFrame = randint(size)
                chol_data[0 if lower else depth, badFrame] = 0.0
            else:
                badFrame = None
            transposed = rand_bool()
            overwrite_b = rand_bool()
            chol_full = chol_bm.full()

            b_arg = b.copy()
            if badFrame is not None:
                msg = (
                    'singular matrix: resolution failed at diagonal %d' %
                    badFrame
                )
                msgRe = '^' + re.escape(msg) + '$'
                with self.assertRaisesRegexp(la.LinAlgError, msgRe):
                    bla._solve_triangular_banded(
                        chol_data, b_arg, transposed=transposed, lower=lower,
                        overwrite_b=overwrite_b
                    )
                with self.assertRaisesRegexp(la.LinAlgError, msgRe):
                    sla.solve_triangular(
                        chol_full, b, trans=transposed, lower=lower
                    )
            else:
                x = bla._solve_triangular_banded(
                    chol_data, b_arg, transposed=transposed, lower=lower,
                    overwrite_b=overwrite_b
                )
                if transposed:
                    assert_allclose(bm.dot_mv(chol_bm.T, x), b)
                else:
                    assert_allclose(bm.dot_mv(chol_bm, x), b)
                if size == 0:
                    x_good = np.zeros((size,))
                else:
                    x_good = sla.solve_triangular(
                        chol_full, b, trans=transposed, lower=lower
                    )
                assert_allclose(x, x_good)
                assert not np.may_share_memory(x, chol_data)
                if size > 0:
                    self.assertEquals(
                        np.may_share_memory(x, b_arg),
                        overwrite_b
                    )

            if not overwrite_b:
                assert np.all(b_arg == b)
开发者ID:wuaalb,项目名称:bandmat,代码行数:58,代码来源:test_linalg.py


示例11: check_may_share_memory_easy_fuzz

def check_may_share_memory_easy_fuzz(get_max_work, same_steps, min_count):
    # Check that overlap problems with common strides are solved with
    # little work.
    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)

    feasible = 0
    infeasible = 0

    while min(feasible, infeasible) < 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))
        if same_steps:
            steps2 = steps
        else:
            steps2 = 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)

        t2 = np.arange(x.ndim)
        rng.shuffle(t2)

        s1 = tuple(random_slice(p, s) for p, s in zip(x.shape, steps))
        s2 = tuple(random_slice(p, s) for p, s in zip(x.shape, steps2))
        a = x[s1].transpose(t1)
        b = x[s2].transpose(t2)

        bounds_overlap = np.may_share_memory(a, b)
        may_share_answer = np.may_share_memory(a, b)
        easy_answer = np.may_share_memory(a, b, max_work=get_max_work(a, b))
        exact_answer = np.may_share_memory(a, b, max_work=MAY_SHARE_EXACT)

        if easy_answer != exact_answer:
            # assert_equal is slow...
            assert_equal(easy_answer, exact_answer, err_msg=repr((s1, s2)))

        if may_share_answer != bounds_overlap:
            assert_equal(may_share_answer, bounds_overlap,
                         err_msg=repr((s1, s2)))

        if bounds_overlap:
            if exact_answer:
                feasible += 1
            else:
                infeasible += 1
开发者ID:Dapid,项目名称:numpy,代码行数:58,代码来源:test_mem_overlap.py


示例12: test_shared_constructor_copies

    def test_shared_constructor_copies(self):
        # shared constructor makes copy
        # (rule #2)
        orig_a = numpy.zeros((2,2))
        A = self.shared(orig_a)
        assert not numpy.may_share_memory(orig_a, data_of(A))

        # rule #2 reading back from theano-managed memory
        assert not numpy.may_share_memory(A.get_value(borrow=False), data_of(A))
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:9,代码来源:test_pfunc.py


示例13: test_diagonal

 def test_diagonal(self):
     s0_diagonal = self.s0.diagonal()
     s0_diff = s0_diagonal.differentials['s']
     assert s0_diagonal.shape == (6,)
     assert s0_diff.shape == s0_diagonal.shape
     assert np.all(s0_diagonal.lat == self.s0.lat.diagonal())
     assert np.all(s0_diff.d_lon == self.diff.d_lon.diagonal())
     assert np.may_share_memory(s0_diagonal.lat, self.s0.lat)
     assert np.may_share_memory(s0_diff.d_lon, self.diff.d_lon)
开发者ID:AustereCuriosity,项目名称:astropy,代码行数:9,代码来源:test_representation_methods.py


示例14: test_swapaxes

 def test_swapaxes(self):
     s1_swapaxes = self.s1.swapaxes(0, 1)
     s1_diff = s1_swapaxes.differentials['s']
     assert s1_swapaxes.shape == (7, 6)
     assert s1_diff.shape == s1_swapaxes.shape
     assert np.all(s1_swapaxes.lat == self.s1.lat.swapaxes(0, 1))
     assert np.all(s1_diff.d_lon == self.diff.d_lon.swapaxes(0, 1))
     assert np.may_share_memory(s1_swapaxes.lat, self.s1.lat)
     assert np.may_share_memory(s1_diff.d_lon, self.diff.d_lon)
开发者ID:AustereCuriosity,项目名称:astropy,代码行数:9,代码来源:test_representation_methods.py


示例15: _assert_copies

def _assert_copies(t, t2, deep=True):
    assert t.colnames == t2.colnames
    np.testing.assert_array_equal(t._data, t2._data)
    assert t.meta == t2.meta

    if deep:
        assert not np.may_share_memory(t._data, t2._data)
    else:
        assert np.may_share_memory(t._data, t2._data)
开发者ID:skendrew,项目名称:astropy,代码行数:9,代码来源:test_table.py


示例16: test_nodes_at_link

def test_nodes_at_link():
    """Test nodes_at_link shares data with tail and head."""
    grid = HexModelGrid(3, 2)

    assert_array_equal(grid.nodes_at_link[:, 0], grid.node_at_link_tail)
    assert_array_equal(grid.nodes_at_link[:, 1], grid.node_at_link_head)

    assert np.may_share_memory(grid.nodes_at_link, grid.node_at_link_tail)
    assert np.may_share_memory(grid.nodes_at_link, grid.node_at_link_head)
开发者ID:Glader011235,项目名称:Landlab,代码行数:9,代码来源:test_link_order.py


示例17: assertTableEqual

 def assertTableEqual(self, a, b, copy=None):
     assert a.colnames == b.colnames
     nptest.assert_array_equal(a.as_array(), b.as_array())
     assert a.meta == b.meta
     for col, col2 in zip(a.columns.values(), b.columns.values()):
         if copy:
             assert not may_share_memory(col, col2)
         elif copy is False:
             assert may_share_memory(col, col2)
开发者ID:rpfisher,项目名称:gwpy,代码行数:9,代码来源:test_table.py


示例18: trim_and_avgerage

 def trim_and_avgerage(self, other):
     """It is assumed that at least two full MLSes are used and sent through the
     system we want to measure. By using m repeated sequences of MLSes we can throw
     away the first full sequence. This first part might be delayed because of
     latency and will contain the startup response of the system which we aren't
     interested in. We then have n=m-1 sequences. Remember that MLS is a repeated
     sequence and it doesn't matter that we have for example latency of for example
     one third of a sequence. This will show up as phase shift which can be
     compensated for.
     
     We now calculate the average of the n sequences. This gives us even more noise
     resistance.
     
     Returns a numpy array of length L.
     """
     # data is [[A_1],
     #          [A_2],
     #          [A_3],
     #          [B_1],
     #          [B_2],
     #          [B_3],
     #          [C_1],
     #          [C_2],
     #          [C_3]]
     
     # throw away first full sequence
     trimmed = other[self.L:]
     self._logger.debug("May share memory: %s" %np.may_share_memory(other, trimmed))
     #print(repr(trimmed))
     # data is [[B_1],
     #          [B_2],
     #          [B_3],
     #          [C_1],
     #          [C_2],
     #          [C_3]]
     
     repeats = len(trimmed)//self.L
     self._logger.debug("repeats (first discared): %i" %repeats)
     
     # reshape so we can average
     reshaped = trimmed.reshape((repeats, self.L))
     # data is [[B_1, B_2, B_3],
     #          [C_1, C_2, C_3]]
     
     self._logger.debug("May share memory: %s" %np.may_share_memory(other, reshaped))
     #print(repr(reshaped))
     
     # the averaging finally creates a new array that has it's own data
     average = np.average(reshaped, axis=0)
     
     average = np.expand_dims(average, axis=1) # up the rank to 2
     # data is [[X_1],
     #          [X_2],
     #          [X_3]]
     
     return average
开发者ID:adrian-stepien,项目名称:zignal,代码行数:56,代码来源:mls.py


示例19: test_copy

    def test_copy(self):
        mlp0 = MultilayerPerceptron()
        mlp1 = mlp0.copy()

        assert mlp0.params == mlp1.params
        check_mlp_same_est(mlp0, mlp1)
        for l0, l1 in zip(mlp0.layers, mlp1.layers):
            assert not np.may_share_memory(l0.weights, l1.weights)
            assert not np.may_share_memory(l0.activations, l1.activations)
            assert l0.bias == l1.bias
开发者ID:rogerfan,项目名称:simpleml,代码行数:10,代码来源:test_perceptron.py


示例20: test_copy

    def test_copy(self):
        s0_copy = self.s0.copy()
        s0_copy_diff = s0_copy.differentials['s']
        assert s0_copy.shape == self.s0.shape
        assert np.all(s0_copy.lon == self.s0.lon)
        assert np.all(s0_copy.lat == self.s0.lat)

        # Check copy was made of internal data.
        assert not np.may_share_memory(s0_copy.distance, self.s0.distance)
        assert not np.may_share_memory(s0_copy_diff.d_lon, self.diff.d_lon)
开发者ID:AustereCuriosity,项目名称:astropy,代码行数:10,代码来源:test_representation_methods.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.mean函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.maximum_sctype函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap