當前位置: 首頁>>代碼示例>>Python>>正文


Python maps.Distribution類代碼示例

本文整理匯總了Python中distarray.localapi.maps.Distribution的典型用法代碼示例。如果您正苦於以下問題:Python Distribution類的具體用法?Python Distribution怎麽用?Python Distribution使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Distribution類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_add

    def test_add(self):
        """See if binary ufunc works for a LocalArray."""
        d = Distribution.from_shape(comm=self.comm, shape=(16, 16))
        a = LocalArray(d, dtype='int32')
        b = LocalArray(d, dtype='int32')
        a.fill(1)
        b.fill(1)
        c = localarray.add(a, b)
        self.assertTrue(np.all(c.ndarray == 2))

        c = localarray.empty_like(a)
        c = localarray.add(a, b, c)
        self.assertTrue(np.all(c.ndarray == 2))

        d0 = Distribution.from_shape(comm=self.comm, shape=(16, 16))
        d1 = Distribution.from_shape(comm=self.comm, shape=(20, 20))
        a = LocalArray(d0, dtype='int32')
        b = LocalArray(d1, dtype='int32')
        self.assertRaises(IncompatibleArrayError, localarray.add, a, b)

        d0 = Distribution.from_shape(comm=self.comm, shape=(16, 16))
        d1 = Distribution.from_shape(comm=self.comm, shape=(20, 20))
        a = LocalArray(d0, dtype='int32')
        b = LocalArray(d0, dtype='int32')
        c = LocalArray(d1, dtype='int32')
        self.assertRaises(IncompatibleArrayError, localarray.add, a, b, c)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:26,代碼來源:paralleltest_umath.py

示例2: setUp

    def setUp(self):
        self.dist_1d = Distribution.from_shape(comm=self.comm,
                                        shape=(7,), grid_shape=(4,))
        self.larr_1d = LocalArray(self.dist_1d, buf=None)

        self.dist_2d = Distribution.from_shape(comm=self.comm,
                                        shape=(16, 16), grid_shape=(4, 1))
        self.larr_2d = LocalArray(self.dist_2d, buf=None)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:8,代碼來源:paralleltest_localarray.py

示例3: test_arecompatible

    def test_arecompatible(self):
        """Test if two DistArrays are compatible."""
        d0 = Distribution.from_shape(comm=self.comm, shape=(16,16))
        a = LocalArray(d0, dtype='int64')
        b = LocalArray(d0, dtype='float32')
        self.assertTrue(arecompatible(a,b))

        da = Distribution.from_shape(comm=self.comm, shape=(16, 16), dist='c')
        a = LocalArray(da, dtype='int64')
        db = Distribution.from_shape(comm=self.comm, shape=(16, 16), dist='b')
        b = LocalArray(db, dtype='float32')
        self.assertFalse(arecompatible(a,b))
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:12,代碼來源:paralleltest_functions.py

示例4: test_asdist_like

    def test_asdist_like(self):
        """Test asdist_like for success and failure."""
        d = Distribution.from_shape(comm=self.comm,
                             shape=(16, 16), dist=('b', 'n'))
        a = LocalArray(d)
        b = LocalArray(d)
        new_a = a.asdist_like(b)
        self.assertEqual(id(a), id(new_a))

        d2 = Distribution.from_shape(comm=self.comm,
                              shape=(16, 16), dist=('n', 'b'))
        a = LocalArray(d)
        b = LocalArray(d2)
        self.assertRaises(IncompatibleArrayError, a.asdist_like, b)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:14,代碼來源:paralleltest_localarray.py

示例5: test_negative

    def test_negative(self):
        """See if unary ufunc works for a LocalArray."""
        d = Distribution.from_shape(comm=self.comm, shape=(16, 16))
        a = LocalArray(d, dtype='int32')
        a.fill(1)
        b = localarray.negative(a)
        self.assertTrue(np.all(a.ndarray == -b.ndarray))

        b = localarray.empty_like(a)
        b = localarray.negative(a, b)
        self.assertTrue(np.all(a.ndarray == -b.ndarray))

        d2 = Distribution.from_shape(comm=self.comm, shape=(20, 20))
        a = LocalArray(d, dtype='int32')
        b = LocalArray(d2, dtype='int32')
        self.assertRaises(IncompatibleArrayError, localarray.negative, b, a)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:16,代碼來源:paralleltest_umath.py

示例6: test_rank_coords

 def test_rank_coords(self):
     """ Test that we can go from rank to coords and back. """
     d = Distribution.from_shape(comm=self.comm, shape=(4, 4))
     la = LocalArray(d)
     max_size = self.comm.Get_size()
     for rank in range(max_size):
         self.round_trip(la, rank=rank)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_localarray.py

示例7: test_ones

 def test_ones(self):
     size = self.comm_size
     nrows = size * 3
     d = Distribution.from_shape(comm=self.comm, shape=(nrows, 20))
     a = localarray.ones(d)
     expected = np.ones((nrows // size, 20))
     assert_array_equal(a.ndarray, expected)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_functions.py

示例8: test_copy_bn

 def test_copy_bn(self):
     distribution = Distribution.from_shape(comm=self.comm,
                                     shape=(16, 16), dist=('b', 'n'))
     a = LocalArray(distribution, dtype=np.int_)
     a.fill(11)
     b = a.copy()
     assert_localarrays_equal(a, b, check_dtype=True)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_localarray.py

示例9: test_cyclic_simple

    def test_cyclic_simple(self):
        """Can we compute local indices for a cyclic distribution?"""
        distribution = Distribution.from_shape(comm=self.comm,
                                        shape=(10,), dist={0: 'c'})
        la = LocalArray(distribution)
        self.assertEqual(la.global_shape, (10,))
        self.assertEqual(la.grid_shape, (4,))

        if la.comm_rank == 0:
            gis = (0, 4, 8)
            self.assertEqual(la.local_shape, (3,))
            calc_result = [la.local_from_global((gi,)) for gi in gis]
            result = [(0,), (1,), (2,)]
        elif la.comm_rank == 1:
            gis = (1, 5, 9)
            self.assertEqual(la.local_shape, (3,))
            calc_result = [la.local_from_global((gi,)) for gi in gis]
            result = [(0,), (1,), (2,)]
        elif la.comm_rank == 2:
            gis = (2, 6)
            self.assertEqual(la.local_shape, (2,))
            calc_result = [la.local_from_global((gi,)) for gi in gis]
            result = [(0,), (1,)]
        elif la.comm_rank == 3:
            gis = (3, 7)
            self.assertEqual(la.local_shape, (2,))
            calc_result = [la.local_from_global((gi,)) for gi in gis]
            result = [(0,), (1,)]

        self.assertEqual(result, calc_result)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:30,代碼來源:paralleltest_localarray.py

示例10: test_slicing

    def test_slicing(self):
        distribution = Distribution.from_shape(self.comm,
                                               (16, 16),
                                               dist=('b', 'n'))
        a = ones(distribution)
        if self.comm.Get_rank() == 0:
            dd00 = {"dist_type": 'b',
                    "size": 5,
                    "start": 0,
                    "stop": 3,
                    "proc_grid_size": 2,
                    "proc_grid_rank": 0}
            dd01 = {"dist_type": 'n',
                    "size": 16}

            new_distribution = Distribution(self.comm, [dd00, dd01])
            rvals = a.global_index.get_slice((slice(5, None), slice(None)),
                                             new_distribution=new_distribution)
            assert_array_equal(rvals, np.ones((3, 16)))

        elif self.comm.Get_rank() == 1:
            dd10 = {"dist_type": 'b',
                    "size": 5,
                    "start": 3,
                    "stop": 5,
                    "proc_grid_size": 2,
                    "proc_grid_rank": 1}
            dd11 = {"dist_type": 'n',
                    "size": 16}
            new_distribution = Distribution(self.comm, [dd10, dd11])
            rvals = a.global_index.get_slice((slice(None, 10), slice(None)),
                                             new_distribution=new_distribution)
            assert_array_equal(rvals, np.ones((2, 16)))
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:33,代碼來源:paralleltest_localarray.py

示例11: test_crazy

 def test_crazy(self):
     """Can we go from global to local indices and back for a complex case?"""
     distribution = Distribution.from_shape(comm=self.comm,
                                     shape=(10, 100, 20),
                                     dist=('b', 'c', 'n'))
     la = LocalArray(distribution)
     self.round_trip(la)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_localarray.py

示例12: test_fromndarray_like

 def test_fromndarray_like(self):
     """Can we build an array using fromndarray_like?"""
     d = Distribution.from_shape(comm=self.comm,
                         shape=(16, 16), dist=('c', 'b'))
     la0 = LocalArray(d, dtype='int8')
     la1 = localarray.fromndarray_like(la0.ndarray, la0)
     assert_localarrays_equal(la0, la1, check_dtype=True)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_functions.py

示例13: test_pack_unpack_index

 def test_pack_unpack_index(self):
     distribution = Distribution.from_shape(comm=self.comm,
                                     shape=(16, 16, 2), dist=('c', 'b', 'n'))
     a = LocalArray(distribution)
     for global_inds, value in ndenumerate(a):
         packed_ind = a.pack_index(global_inds)
         self.assertEqual(global_inds, a.unpack_index(packed_ind))
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:7,代碼來源:paralleltest_localarray.py

示例14: test_abs

 def test_abs(self):
     """See if unary ufunc works for a LocalArray."""
     d = Distribution.from_shape(comm=self.comm, shape=(16, 16))
     a = LocalArray(d, dtype='int32')
     a.fill(-5)
     a[2, 3] = 11
     b = abs(a)
     self.assertTrue(np.all(abs(a.ndarray) == b.ndarray))
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:8,代碼來源:paralleltest_umath.py

示例15: test_astype_bn

 def test_astype_bn(self):
     new_dtype = np.float32
     d = Distribution.from_shape(comm=self.comm,
                          shape=(16, 16), dist=('b', 'n'))
     a = LocalArray(d, dtype=np.int_)
     a.fill(11)
     b = a.astype(new_dtype)
     assert_localarrays_allclose(a, b, check_dtype=False)
     self.assertEqual(b.dtype, new_dtype)
     self.assertEqual(b.ndarray.dtype, new_dtype)
開發者ID:RaoUmer,項目名稱:distarray,代碼行數:10,代碼來源:paralleltest_localarray.py


注:本文中的distarray.localapi.maps.Distribution類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。