Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions distarray/dist/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,44 @@ def reduce(self, axes):

def localshapes(self):
return shapes_from_dim_data_per_rank(self.get_dim_data_per_rank())


def distribution(context, shape, dist=None, grid_shape=None, targets=None):
""" Create a new Distribution from parameters.

Parameters
----------

context: distarray.dist.Context instance.

shape: sequence of nonnegative integers.
The global shape of the data associated with this Distribution object.
Also used to determine automatic partioning of targets in process grid
when ``grid_shape`` is None.

dist: sequence or dictionary. Optional.
If ``dist`` is None, defaults to {0: 'b'} -- i.e., block-distributed in
the 0th dimension. If a sequence, must be a sequence of ``dist_type``
characters in the set {'b', 'c', 'n', 'u'}, no more than
``len(shape)``. Any unspecified dimensions are assumed to be ``'n'``.
If a dictionary, must be a mapping of axis index to ``dist_type``
character.

grid_shape: sequence of non-negative integers. Optional.
If ``None``, will be determined automatically from ``shape``, ``dist``,
and ``targets``, according to some automatic grid creation heuristics.
If a sequence of integers, then ``reduce(operator.mul, grid_shape, 1)
<= len(targets)``.

targets: sequence of target IDs. Optional.
If unspecified, defaults to ``context.targets``. The
``Distribution``'s targets will always be kept in sorted order, and the
underlying MPI rank is the index into the targets sequence.

Returns
-------

New Distribution object.

"""
return Distribution.from_shape(context, shape, dist, grid_shape, targets)