Esempio n. 1
0
    def scatter_range(self: 'PList[T]', rng) -> 'PList[T]':
        def select(index, value):
            if index in rng:
                return value
            return None

        def not_none(value):
            return value is not None

        selected = self.mapi(select).filter(not_none)
        distr = Distribution.balanced(selected.length())
        return selected.distribute(distr)
Esempio n. 2
0
    def scatter(self: 'PList[T]', pid: int) -> 'PList[T]':
        assert pid in par.procs()

        def select(index, a_list):
            if index == pid:
                return a_list
            return []

        select_distr = Distribution([
            size if index == pid else 0
            for (index, size) in enumerate(self.distribution)
        ])
        at_pid = self.get_partition().mapi(select).flatten(select_distr)

        distr = Distribution.balanced(at_pid.length())
        return at_pid.distribute(distr)
Esempio n. 3
0
 def balance(self: 'PList[T]') -> 'PList[T]':
     return self.distribute(Distribution.balanced(self.length()))
Esempio n. 4
0
def test_distribution_balanced_not_valid():
    # pylint: disable=missing-docstring
    size = random.randint(10, 100)
    distr = Distribution.balanced(size)
    res = distr.is_valid(size - 1)
    assert not res