:mod:`heat.factories` ========================== .. py:module:: heat.core.factories .. autoapi-nested-parse:: Provides high-level DNDarray initialization functions Module Contents --------------- .. function:: arange(*args: Union[int, float], dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[Union[str, heat.core.devices.Device]] = None, comm: Optional[heat.core.communication.Communication] = None) -> heat.core.dndarray.DNDarray Return evenly spaced values within a given interval. Values are generated within the half-open interval ``[start, stop)`` (in other words, the interval including `start` but excluding `stop`). For integer arguments the function is equivalent to the Python built-in `range `_ function, but returns a array rather than a list. When using a non-integer step, such as 0.1, the results may be inconsistent due to being subject to numerical rounding. In the cases the usage of :func:`linspace` is recommended. For floating point arguments, the length of the result is :math:`\lceil(stop-start)/step\rceil`. Again, due to floating point rounding, this rule may result in the last element of `out` being greater than `stop` by machine epsilon. :param \*args: Positional arguments defining the interval. Can be: - A single argument: interpreted as `stop`, with `start=0` and `step=1`. - Two arguments: interpreted as `start` and `stop`, with `step=1`. - Three arguments: interpreted as `start`, `stop`, and `step`. The function raises a `TypeError` if more than three arguments are provided. :type \*args: int or float, optional :param dtype: The type of the output array. If `dtype` is not given, it is automatically inferred from the other input arguments. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the device the array shall be allocated on, defaults to globally set default device. :type device: str, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional .. seealso:: :func:`linspace` Evenly spaced numbers with careful handling of endpoints. .. rubric:: Examples >>> ht.arange(3) DNDarray([0, 1, 2], dtype=ht.int32, device=cpu:0, split=None) >>> ht.arange(3.0) DNDarray([0., 1., 2.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.arange(3, 7) DNDarray([3, 4, 5, 6], dtype=ht.int32, device=cpu:0, split=None) >>> ht.arange(3, 7, 2) DNDarray([3, 5], dtype=ht.int32, device=cpu:0, split=None) .. function:: array(obj: Iterable, dtype: Optional[Type[heat.core.types.datatype]] = None, copy: Optional[bool] = None, ndmin: int = 0, order: str = 'C', split: Optional[int] = None, is_split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None) -> heat.core.dndarray.DNDarray Create a :class:`~heat.core.dndarray.DNDarray`. :param obj: A tensor or array, any object exposing the array interface, an object whose ``__array__`` method returns an array, or any (nested) sequence. :type obj: array_like :param dtype: The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. This argument can only be used to ‘upcast’ the array. For downcasting, use the :func:`~heat.core.dndarray.astype` method. :type dtype: datatype, optional :param copy: If ``True``, the input object is copied. If ``False``, input which supports the buffer protocol is never copied. If ``None`` (default), the function reuses the existing memory buffer if possible, and copies otherwise. :type copy: bool, optional :param ndmin: Specifies the minimum number of dimensions that the resulting array should have. Ones will, if needed, be attached to the shape if ``ndim > 0`` and prefaced in case of ``ndim < 0`` to meet the requirement. :type ndmin: int, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :param split: The axis along which the passed array content ``obj`` is split and distributed in memory. Mutually exclusive with ``is_split``. :type split: int or None, optional :param is_split: Specifies the axis along which the local data portions, passed in obj, are split across all machines. Useful for interfacing with other distributed-memory code. The shape of the global array is automatically inferred. Mutually exclusive with ``split``. :type is_split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on (i.e. globally set default device). :type device: str or Device, optional :param comm: Handle to the nodes holding distributed array chunks. :type comm: Communication, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. :raises ValueError: If ``copy`` is False but a copy is necessary to satisfy other requirements (e.g. different dtype, device, etc.). :raises TypeError: If the input object cannot be converted to a torch.Tensor, hence it cannot be converted to a :class:`~heat.core.dndarray.DNDarray`. .. rubric:: Examples >>> ht.array([1, 2, 3]) DNDarray([1, 2, 3], dtype=ht.int64, device=cpu:0, split=None) >>> ht.array([1, 2, 3.0]) DNDarray([1., 2., 3.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.array([[1, 2], [3, 4]]) DNDarray([[1, 2], [3, 4]], dtype=ht.int64, device=cpu:0, split=None) >>> ht.array([1, 2, 3], ndmin=2) DNDarray([[1], [2], [3]], dtype=ht.int64, device=cpu:0, split=None) >>> ht.array([1, 2, 3], dtype=float) DNDarray([1., 2., 3.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.array([1, 2, 3, 4], split=0) DNDarray([1, 2, 3, 4], dtype=ht.int64, device=cpu:0, split=0) >>> if ht.MPI_WORLD.rank == 0 >>> a = ht.array([1, 2], is_split=0) >>> else: >>> a = ht.array([3, 4], is_split=0) >>> a DNDarray([1, 2, 3, 4], dtype=ht.int64, device=cpu:0, split=0) >>> a = np.arange(2 * 3).reshape(2, 3) >>> a array([[ 0, 1, 2], [ 3, 4, 5]]) >>> a.strides (24, 8) >>> b = ht.array(a) >>> b DNDarray([[0, 1, 2], [3, 4, 5]], dtype=ht.int64, device=cpu:0, split=None) >>> b.strides (24, 8) >>> b.larray.untyped_storage() 0 1 2 3 4 5 [torch.LongStorage of size 6] >>> c = ht.array(a, order="F") >>> c DNDarray([[0, 1, 2], [3, 4, 5]], dtype=ht.int64, device=cpu:0, split=None) >>> c.strides (8, 16) >>> c.larray.untyped_storage() 0 3 1 4 2 5 [torch.LongStorage of size 6] >>> a = np.arange(4 * 3).reshape(4, 3) >>> a.strides (24, 8) >>> b = ht.array(a, order="F", split=0) >>> b DNDarray([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]], dtype=ht.int64, device=cpu:0, split=0) >>> b.strides [0/2] (8, 16) [1/2] (8, 16) >>> b.larray.untyped_storage() [0/2] 0 3 1 4 2 5 [torch.LongStorage of size 6] [1/2] 6 9 7 10 8 11 [torch.LongStorage of size 6] .. function:: asarray(obj: Iterable, dtype: Optional[Type[heat.core.types.datatype]] = None, copy: Optional[bool] = None, order: str = 'C', is_split: Optional[bool] = None, device: Optional[Union[str, heat.core.devices.Device]] = None) -> heat.core.dndarray.DNDarray Convert ``obj`` to a DNDarray. If ``obj`` is a `DNDarray` or `Tensor` with the same `dtype` and `device` or if the data is an `ndarray` of the corresponding ``dtype`` and the ``device`` is the CPU, no copy will be performed. :param obj: Input data, in any form that can be converted to an array. This includes e.g. lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. :type obj: iterable :param dtype: By default, the data-type is inferred from the input data. :type dtype: dtype, optional :param copy: If ``True``, then the object is copied. If ``False``, the object is not copied and a ``ValueError`` is raised in the case a copy would be necessary. If ``None``, a copy will only be made if `obj` is a nested sequence or if a copy is needed to satisfy any of the other requirements, e.g. ``dtype``. :type copy: bool, optional :param order: Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to ‘C’. :type order: str, optional :param is_split: Specifies the axis along which the local data portions, passed in obj, are split across all MPI processes. Useful for interfacing with other HPC code. The shape of the global tensor is automatically inferred. :type is_split: None or int, optional :param device: Specifies the device the tensor shall be allocated on. By default, it is inferred from the input data. :type device: str, ht.Device or None, optional .. rubric:: Examples >>> a = [1, 2] >>> ht.asarray(a) DNDarray([1, 2], dtype=ht.int64, device=cpu:0, split=None) >>> a = np.array([1, 2, 3]) >>> n = ht.asarray(a) >>> n DNDarray([1, 2, 3], dtype=ht.int64, device=cpu:0, split=None) >>> n[0] = 0 >>> a DNDarray([0, 2, 3], dtype=ht.int64, device=cpu:0, split=None) >>> a = torch.tensor([1, 2, 3]) >>> t = ht.asarray(a) >>> t DNDarray([1, 2, 3], dtype=ht.int64, device=cpu:0, split=None) >>> t[0] = 0 >>> a DNDarray([0, 2, 3], dtype=ht.int64, device=cpu:0, split=None) >>> a = ht.array([1, 2, 3, 4], dtype=ht.float32) >>> ht.asarray(a, dtype=ht.float32) is a True >>> ht.asarray(a, dtype=ht.float64) is a False .. function:: empty(shape: Union[int, Sequence[int]], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new uninitialized :class:`~heat.core.dndarray.DNDarray` of given shape and data type. May be allocated split up across multiple nodes along the specified axis. :param shape: Desired shape of the output array, e.g. 1 or (1, 2, 3,). :type shape: int or Sequence[int,...] :param dtype: The desired HeAT data type for the array. :type dtype: datatype :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int, optional :param device: Specifies the :class:`~heat.core.devices.Device`. the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> ht.empty(3) DNDarray([0., 0., 0.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.empty(3, dtype=ht.int) DNDarray([59140784, 0, 59136816], dtype=ht.int32, device=cpu:0, split=None) >>> ht.empty( ... ( ... 2, ... 3, ... ) ... ) DNDarray([[-1.7206e-10, 4.5905e-41, -1.7206e-10], [ 4.5905e-41, 4.4842e-44, 0.0000e+00]], dtype=ht.float32, device=cpu:0, split=None) .. function:: empty_like(a: heat.core.dndarray.DNDarray, dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new uninitialized :class:`~heat.core.dndarray.DNDarray` with the same type, shape and data distribution of given object. Data type, data distribution axis, and device can be explicitly overridden. :param a: The shape, data-type, split axis and device of ``a`` define these same attributes of the returned array. Uninitialized array with the same shape, type, split axis and device as ``a`` unless overriden. :type a: DNDarray :param dtype: Overrides the data type of the result. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> x = ht.ones( ... ( ... 2, ... 3, ... ) ... ) >>> x DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.empty_like(x) DNDarray([[-1.7205e-10, 4.5905e-41, 7.9442e-37], [ 0.0000e+00, 4.4842e-44, 0.0000e+00]], dtype=ht.float32, device=cpu:0, split=None) .. function:: eye(shape: Union[int, Sequence[int]], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new 2-D :class:`~heat.core.dndarray.DNDarray` with ones on the diagonal and zeroes elsewhere, i.e. an identity matrix. :param shape: The shape of the data-type. If only one number is provided, returning array will be square with that size. In other cases, the first value represents the number rows, the second the number of columns. :type shape: int or Sequence[int,...] :param dtype: Overrides the data type of the result. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> ht.eye(2) DNDarray([[1., 0.], [0., 1.]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.eye((2, 3), dtype=ht.int32) DNDarray([[1, 0, 0], [0, 1, 0]], dtype=ht.int32, device=cpu:0, split=None) .. function:: from_partitioned(x, comm: Optional[heat.core.communication.Communication] = None) -> heat.core.dndarray.DNDarray Return a newly created DNDarray constructed from the '__partitioned__' attributed of the input object. Memory of local partitions will be shared (zero-copy) as long as supported by data objects. Currently supports numpy ndarrays and torch tensors as data objects. Current limitations: * Partitions must be ordered in the partition-grid by rank * Only one split-axis * Only one partition per rank * Only SPMD-style __partitioned__ :param x: Requires x.__partitioned__ :type x: object :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional .. seealso:: :func:`ht.core.DNDarray.create_partition_interface `. :raises AttributeError: If not hasattr(x, "__partitioned__") or if underlying data has no dtype. :raises TypeError: If it finds an unsupported array types :raises RuntimeError: If other unsupported content is found. .. rubric:: Examples >>> import heat as ht >>> a = ht.ones((44, 55), split=0) >>> b = ht.from_partitioned(a) >>> assert (a == b).all() >>> a[40] = 4711 >>> assert (a == b).all() .. function:: from_partition_dict(parted: dict, comm: Optional[heat.core.communication.Communication] = None) -> heat.core.dndarray.DNDarray Return a newly created DNDarray constructed from the '__partitioned__' attributed of the input object. Memory of local partitions will be shared (zero-copy) as long as supported by data objects. Currently supports numpy ndarrays and torch tensors as data objects. Current limitations: * Partitions must be ordered in the partition-grid by rank * Only one split-axis * Only one partition per rank * Only SPMD-style __partitioned__ :param parted: A partition dictionary used to create the new DNDarray :type parted: dict :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional .. seealso:: :func:`ht.core.DNDarray.create_partition_interface `. :raises AttributeError: If not hasattr(x, "__partitioned__") or if underlying data has no dtype. :raises TypeError: If it finds an unsupported array types :raises RuntimeError: If other unsupported content is found. .. rubric:: Examples >>> import heat as ht >>> a = ht.ones((44, 55), split=0) >>> b = ht.from_partition_dict(a.__partitioned__) >>> assert (a == b).all() >>> a[40] = 4711 >>> assert (a == b).all() .. function:: full(shape: Union[int, Sequence[int]], fill_value: Union[int, float], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Return a new :class:`~heat.core.dndarray.DNDarray` of given shape and type, filled with ``fill_value``. :param shape: Shape of the new array, e.g., (2, 3) or 2. :type shape: int or Sequence[int,...] :param fill_value: Fill value. :type fill_value: scalar :param dtype: The desired data-type for the array :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> ht.full((2, 2), ht.inf) DNDarray([[inf, inf], [inf, inf]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.full((2, 2), 10) DNDarray([[10., 10.], [10., 10.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: full_like(a: heat.core.dndarray.DNDarray, fill_value: Union[int, float], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Return a full :class:`~heat.core.dndarray.DNDarray` with the same shape and type as a given array. Data type, data distribution axis, and device can be explicitly overridden. :param a: The shape, data-type, split axis and device of ``a`` define these same attributes of the returned array. :type a: DNDarray :param fill_value: Fill value. :type fill_value: scalar :param dtype: The data type of the result, defaults to `a.dtype`. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; defaults to `a.split`. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to `a.device`. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> x = ht.zeros( ... ( ... 2, ... 3, ... ) ... ) >>> x DNDarray([[0., 0., 0.], [0., 0., 0.]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.full_like(x, 1.0) DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: linspace(start: Union[int, float], stop: Union[int, float], num: int = 50, endpoint: bool = True, retstep: bool = False, dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None) -> Tuple[heat.core.dndarray.DNDarray, float] Returns num evenly spaced samples, calculated over the interval ``[start, stop]``. The endpoint of the interval can optionally be excluded. There are num equally spaced samples in the closed interval ``[start, stop]`` or the half-open interval ``[start, stop)`` (depending on whether endpoint is ``True`` or ``False``). :param start: The starting value of the sample interval, maybe a sequence if convertible to scalar :type start: scalar or scalar-convertible :param stop: The end value of the sample interval, unless is set to False. In that case, the sequence consists of all but the last of ``num+1`` evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is ``False``. :type stop: scalar or scalar-convertible :param num: Number of samples to generate, defaults to 50. Must be non-negative. :type num: int, optional :param endpoint: If ``True``, stop is the last sample, otherwise, it is not included. :type endpoint: bool, optional :param retstep: If ``True``, return (samples, step), where step is the spacing between samples. :type retstep: bool, optional :param dtype: The type of the output array. :type dtype: dtype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional .. rubric:: Examples >>> ht.linspace(2.0, 3.0, num=5) DNDarray([2.0000, 2.2500, 2.5000, 2.7500, 3.0000], dtype=ht.float32, device=cpu:0, split=None) >>> ht.linspace(2.0, 3.0, num=5, endpoint=False) DNDarray([2.0000, 2.2000, 2.4000, 2.6000, 2.8000], dtype=ht.float32, device=cpu:0, split=None) >>> ht.linspace(2.0, 3.0, num=5, retstep=True) (DNDarray([2.0000, 2.2500, 2.5000, 2.7500, 3.0000], dtype=ht.float32, device=cpu:0, split=None), 0.25) .. function:: logspace(start: Union[int, float], stop: Union[int, float], num: int = 50, endpoint: bool = True, base: float = 10.0, dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None) -> heat.core.dndarray.DNDarray Return numbers spaced evenly on a log scale. In linear space, the sequence starts at ``base**start`` (``base`` to the power of ``start``) and ends with ``base**stop`` (see ``endpoint`` below). :param start: ``base**start`` is the starting value of the sequence. :type start: scalar or scalar-convertible :param stop: ``base**stop`` is the final value of the sequence, unless `endpoint` is ``False``. In that case, ``num+1`` values are spaced over the interval in log-space, of which all but the last (a sequence of length ``num``) are returned. :type stop: scalar or scalar-convertible :param num: Number of samples to generate. :type num: int, optional :param endpoint: If ``True``, `stop` is the last sample. Otherwise, it is not included. :type endpoint: bool, optional :param base: The base of the log space. The step size between the elements in :math:`ln(samples) / ln(base)` (or :math:`base(samples)`) is uniform. :type base: float, optional :param dtype: The type of the output array. If ``dtype`` is not given, infer the data type from the other input arguments. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional .. seealso:: :func:`arange` Similar to :func:`linspace`, with the step size specified instead of the number of samples. Note that, when used with a float endpoint, the endpoint may or may not be included. :func:`linspace` Similar to ``logspace``, but with the samples uniformly distributed in linear space, instead of log space. .. rubric:: Examples >>> ht.logspace(2.0, 3.0, num=4) DNDarray([ 100.0000, 215.4434, 464.1590, 1000.0000], dtype=ht.float32, device=cpu:0, split=None) >>> ht.logspace(2.0, 3.0, num=4, endpoint=False) DNDarray([100.0000, 177.8279, 316.2278, 562.3413], dtype=ht.float32, device=cpu:0, split=None) >>> ht.logspace(2.0, 3.0, num=4, base=2.0) DNDarray([4.0000, 5.0397, 6.3496, 8.0000], dtype=ht.float32, device=cpu:0, split=None) .. function:: meshgrid(*arrays: Sequence[heat.core.dndarray.DNDarray], indexing: str = 'xy') -> List[heat.core.dndarray.DNDarray] Returns coordinate matrices from coordinate vectors. :param arrays: one-dimensional arrays representing grid coordinates. If exactly one vector is distributed, the returned matrices will reflect this distribution. :type arrays: Sequence[ DNDarray ] :param indexing: Cartesian ‘xy’ or matrix ‘ij’ indexing of output. It is ignored if zero or one one-dimensional arrays are provided. Default: 'xy' . :type indexing: str, optional :raises ValueError: If `indexing` is not 'xy' or 'ij'. :raises ValueError: If more than one input vector is distributed. .. rubric:: Examples >>> x = ht.arange(4) >>> y = ht.arange(3) >>> xx, yy = ht.meshgrid(x, y) >>> xx DNDarray(MPI-rank: 0, Shape: [3, 4], Split: None, Local Shape: (3, 4), Device: cpu:0, Dtype: int32, Data: [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]) >>> yy DNDarray(MPI-rank: 0, Shape: [3, 4], Split: None, Local Shape: (3, 4), Device: cpu:0, Dtype: int32, Data: [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2]]) >>> x = ht.arange(4, split=0) >>> xx, yy = ht.meshgrid(x, y) >>> xx DNDarray(MPI-rank: 0, Shape: [3, 4], Split: 1, Local Shape: (3, 4), Device: cpu:0, Dtype: int32, Data: [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]) >>> xx, yy = ht.meshgrid(x, y, indexing="ij") >>> xx DNDarray(MPI-rank: 0, Shape: (4, 3), Split: 0, Local Shape: (4, 3), Device: cpu:0, Dtype: int32, Data: [[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]]) .. function:: ones(shape: Union[int, Sequence[int]], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new :class:`~heat.core.dndarray.DNDarray` of given shape and data type filled with one. May be allocated split up across multiple nodes along the specified axis. :param shape: Desired shape of the output array, e.g. 1 or (1, 2, 3,). :type shape: int or Sequence[int,...] :param dtype: The desired HeAT data type for the array. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> ht.ones(3) DNDarray([1., 1., 1.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.ones(3, dtype=ht.int) DNDarray([1, 1, 1], dtype=ht.int32, device=cpu:0, split=None) >>> ht.ones( ... ( ... 2, ... 3, ... ) ... ) DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: ones_like(a: heat.core.dndarray.DNDarray, dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new :class:`~heat.core.dndarray.DNDarray` filled with ones with the same type, shape, data distribution and device of the input object. Data type, data distribution axis, and device can be explicitly overridden. :param a: The shape, data-type, split axis and device of ``a`` define these same attributes of the returned array. :type a: DNDarray :param dtype: Overrides the data type of the result. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; defaults to `a.split`. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to `a.device`. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> x = ht.zeros( ... ( ... 2, ... 3, ... ) ... ) >>> x DNDarray([[0., 0., 0.], [0., 0., 0.]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.ones_like(x) DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: zeros(shape: Union[int, Sequence[int]], dtype: Type[heat.core.types.datatype] = types.float32, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new :class:`~heat.core.dndarray.DNDarray` of given shape and data type filled with zero values. May be allocated split up across multiple nodes along the specified axis. :param shape: Desired shape of the output array, e.g. 1 or (1, 2, 3,). :type shape: int or Sequence[int,...] :param dtype: The desired HeAT data type for the array. :type dtype: datatype :param split: The axis along which the array is split and distributed; ``None`` means no distribution. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to globally set default device. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> ht.zeros(3) DNDarray([0., 0., 0.], dtype=ht.float32, device=cpu:0, split=None) >>> ht.zeros(3, dtype=ht.int) DNDarray([0, 0, 0], dtype=ht.int32, device=cpu:0, split=None) >>> ht.zeros( ... ( ... 2, ... 3, ... ) ... ) DNDarray([[0., 0., 0.], [0., 0., 0.]], dtype=ht.float32, device=cpu:0, split=None) .. function:: zeros_like(a: heat.core.dndarray.DNDarray, dtype: Optional[Type[heat.core.types.datatype]] = None, split: Optional[int] = None, device: Optional[heat.core.devices.Device] = None, comm: Optional[heat.core.communication.Communication] = None, order: str = 'C') -> heat.core.dndarray.DNDarray Returns a new :class:`~heat.core.dndarray.DNDarray` filled with zeros with the same type, shape, data distribution, and device of the input object. Data type, data distribution axis, and device can be explicitly overridden. :param a: The shape, data-type, split axis, and device of ``a`` define these same attributes of the returned array. :type a: DNDarray :param dtype: Overrides the data type of the result. :type dtype: datatype, optional :param split: The axis along which the array is split and distributed; defaults to `a.split`. :type split: int or None, optional :param device: Specifies the :class:`~heat.core.devices.Device` the array shall be allocated on, defaults to `a.device`. :type device: str or Device, optional :param comm: Handle to the nodes holding distributed parts or copies of this array. :type comm: Communication, optional :param order: Options: ``'C'`` or ``'F'``. Specifies the memory layout of the newly created array. Default is ``order='C'``, meaning the array will be stored in row-major order (C-like). If ``order=‘F’``, the array will be stored in column-major order (Fortran-like). :type order: str, optional :raises NotImplementedError: If order is one of the NumPy options ``'K'`` or ``'A'``. .. rubric:: Examples >>> x = ht.ones( ... ( ... 2, ... 3, ... ) ... ) >>> x DNDarray([[1., 1., 1.], [1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=None) >>> ht.zeros_like(x) DNDarray([[0., 0., 0.], [0., 0., 0.]], dtype=ht.float32, device=cpu:0, split=None)