Creates a distributed array from the given data. This function does not check if all elements of the given array are stored in some of the chunks. Args: array (array_like): :class:`DistributedArray` object, :class:`cupy.ndarray` object or any other object that can b
(
array: ArrayLike,
index_map: dict[int, Any],
mode: _modes.Mode = _modes.REPLICA,
)
| 835 | |
| 836 | |
| 837 | def distributed_array( |
| 838 | array: ArrayLike, |
| 839 | index_map: dict[int, Any], |
| 840 | mode: _modes.Mode = _modes.REPLICA, |
| 841 | ) -> DistributedArray: |
| 842 | """Creates a distributed array from the given data. |
| 843 | |
| 844 | This function does not check if all elements of the given array are stored |
| 845 | in some of the chunks. |
| 846 | |
| 847 | Args: |
| 848 | array (array_like): :class:`DistributedArray` object, |
| 849 | :class:`cupy.ndarray` object or any other object that can be passed |
| 850 | to :func:`numpy.array`. |
| 851 | index_map (dict from int to array indices): Indices for the chunks |
| 852 | that devices with designated IDs own. One device can have multiple |
| 853 | chunks, which can be specified as a list of array indices. |
| 854 | mode (mode object, optional): Mode that determines how overlaps |
| 855 | of the chunks are interpreted. Defaults to |
| 856 | ``cupyx.distributed.array.REPLICA``. |
| 857 | |
| 858 | .. seealso:: |
| 859 | :attr:`DistributedArray.mode` for details about modes. |
| 860 | |
| 861 | Example: |
| 862 | >>> array = cupy.arange(9).reshape(3, 3) |
| 863 | >>> A = distributed_array( |
| 864 | ... array, |
| 865 | ... {0: [(slice(2), slice(2)), # array[:2, :2] |
| 866 | ... slice(None, None, 2)], # array[::2] |
| 867 | ... 1: (slice(1, None), 2)}) # array[1:, 2] |
| 868 | """ |
| 869 | if isinstance(array, DistributedArray): |
| 870 | if array.mode != mode: |
| 871 | array = array.change_mode(mode) |
| 872 | if array.index_map != index_map: |
| 873 | array = array.reshard(index_map) |
| 874 | return DistributedArray( |
| 875 | array.shape, array.dtype, array._chunks_map, array._mode, |
| 876 | array._comms) |
| 877 | |
| 878 | if isinstance(array, (numpy.ndarray, ndarray)): |
| 879 | if mode != _modes.REPLICA: |
| 880 | array = array.copy() |
| 881 | else: |
| 882 | array = numpy.array(array) |
| 883 | |
| 884 | index_map = _index_arith._normalize_index_map(array.shape, index_map) |
| 885 | comms = None |
| 886 | |
| 887 | # Define how to form a chunk from (dev, idx, src_array) |
| 888 | make_chunk: Callable[ |
| 889 | [int, int, tuple[slice, ...], ndarray, list[Any] | None], |
| 890 | _Chunk |
| 891 | ] |
| 892 | |
| 893 | if isinstance(array, ndarray): |
| 894 | src_dev = array.device.id |
nothing calls this directly
no test coverage detected