Exemplo n.º 1
0
    def bcast_like(self, value, other, update_host=True):
        """Create a new OffloadArray that is bound to an empty numpy.ndarray
           that matches shape and type of an existing OffloadArray or
           numpy.ndarray.  If update_host is True (the default), then the empty
           array is automatically transferred to the host numpy.ndarray.  If
           set to False, the data transfer is avoided and the data in the host
           array is in undefined state.

           The operation is enqueued into the stream object and completes
           asynchronously.

           Parameters
           ----------
           value       : scalar type
               Value to broadcast to all elements of the created array
           other       : numpy.ndarray
               Template array used to determine shape, data type, and storage
               order
           update_host : bool, optional, default True
               Control if the host array is updated with the array data
               during construction of the OffloadArray

           Returns
           -------
           out : OffloadArray
               Instance of OffloadArray with all elements being one

           See Also
           --------
           empty, empty_like, zeros, zeros_like, ones, bcast, bcast_like

           Examples
           --------
           >>> a = numpy.zeros((2,2))
           >>> stream.bcast_like(42.0, a)
           array([[ 1.,  1.],
                  [ 1.,  1.]])

           >>> o = stream.bcast_like(42.0, a, update_host=False)
           >>> o
           array([[  0.00000000e+000,   1.32102240e-312],
                  [  1.43679049e+161,   1.16250014e-012]])  # random data
           >>> o.update_host()
           array([[ 42.,  42.],
                  [ 42.,  42.]])
        """
        if (not isinstance(other, numpy.ndarray)
                and not isinstance(other, pymic.OffloadArray)):
            raise ValueError("only numpy.ndarray can be used "
                             "with this function")
        return self.bcast(value,
                          other.shape,
                          other.dtype,
                          get_order(other),
                          update_host=update_host)
Exemplo n.º 2
0
    def bcast_like(self, value, other, update_host=True):
        """Create a new OffloadArray that is bound to an empty numpy.ndarray
           that matches shape and type of an existing OffloadArray or
           numpy.ndarray.  If update_host is True (the default), then the empty
           array is automatically transferred to the host numpy.ndarray.  If
           set to False, the data transfer is avoided and the data in the host
           array is in undefined state.

           The operation is enqueued into the stream object and completes
           asynchronously.

           Parameters
           ----------
           value       : scalar type
               Value to broadcast to all elements of the created array
           other       : numpy.ndarray
               Template array used to determine shape, data type, and storage
               order
           update_host : bool, optional, default True
               Control if the host array is updated with the array data
               during construction of the OffloadArray

           Returns
           -------
           out : OffloadArray
               Instance of OffloadArray with all elements being one

           See Also
           --------
           empty, empty_like, zeros, zeros_like, ones, bcast, bcast_like

           Examples
           --------
           >>> a = numpy.zeros((2,2))
           >>> stream.bcast_like(42.0, a)
           array([[ 1.,  1.],
                  [ 1.,  1.]])

           >>> o = stream.bcast_like(42.0, a, update_host=False)
           >>> o
           array([[  0.00000000e+000,   1.32102240e-312],
                  [  1.43679049e+161,   1.16250014e-012]])  # random data
           >>> o.update_host()
           array([[ 42.,  42.],
                  [ 42.,  42.]])
        """
        if (not isinstance(other, numpy.ndarray) and
                not isinstance(other, pymic.OffloadArray)):
            raise ValueError("only numpy.ndarray can be used "
                             "with this function")
        return self.bcast(value, other.shape, other.dtype,
                          get_order(other), update_host=update_host)
Exemplo n.º 3
0
    def zeros_like(self, other, dtype=None, update_host=True):
        """Create a new OffloadArray that is bound to an empty numpy.ndarray
           that matches shape and type of an existing OffloadArray or
           numpy.ndarray.  If update_host is True (the default), then the empty
           array is automatically transferred to the host numpy.ndarray.  If
           set to False, the data transfer is avoided and the data in the host
           array is in undefined state.

           The operation is enqueued into the stream object and completes
           asynchronously.

           Parameters
           ----------
           other       : numpy.ndarray
               Template array used to determine shape, data type, and storage
               order
           update_host : bool, optional, default True
               Control if the host array is updated with the array data
               during construction of the OffloadArray

           Returns
           -------
           out : OffloadArray
               Instance of OffloadArray with all elements being zero

           See Also
           --------
           empty, empty_like, zeros, ones, ones_like, bcast, bcast_like

           Examples
           --------
           >>> a = numpy.ones((2,2))
           >>> stream.zeros_like(a)
           array([[ 0.,  0.],
                  [ 0.,  0.]])

           >>> o = stream.zeros_like(a, update_host=False)
           >>> o
           array([[  1.12110451e-316,   1.32102240e-312],
                  [  6.94088686e-310,   6.94088688e-310]])  # random data
           >>> o.update_host()
           array([[ 0.,  0.],
                  [ 0.,  0.]])
        """
        if (not isinstance(other, numpy.ndarray)
                and not isinstance(other, pymic.OffloadArray)):
            raise ValueError("only numpy.ndarray can be used "
                             "with this function")
        _dtype = other.dtype if dtype is None else dtype
        return self.zeros(other.shape, _dtype, get_order(other),
                          update_host=update_host)
Exemplo n.º 4
0
    def empty_like(self, other, update_host=True):
        """Create a new OffloadArray that is bound to an empty numpy.ndarray
           that matches shape and type of an existing OffloadArray or
           numpy.ndarray.  If update_host is True (the default), then the empty
           array is automatically transferred to the host numpy.ndarray.  If
           set to False, the data transfer is avoided and the data in the host
           array is in undefined state.

           The operation is enqueued into the stream object and completes
           asynchronously.

           Parameters
           ----------
           other       : numpy.ndarray
               Template array used to determine shape, data type, and storage
               order
           update_host :
               Control if the host array is updated with the array data
               during construction of the OffloadArray

           See Also
           --------
           empty, zeros, zeros_like, ones, ones_like, bcast, bcast_like

           Examples
           --------
           >>> a = numpy.ones((2,2))
           >>> stream.empty_like(a)
           array([[  4.26872718e-321,   6.91990916e-310],
                  [  4.34283703e-321,   6.91990916e-310]])  # random data

           >>> o = stream.empty_like(a, update_host=False)
           >>> o
           array([[  1.12110451e-316,   1.32102240e-312],
                  [  6.94088686e-310,   6.94088688e-310]])  # random data
           >>> o.update_host()
           array([[  4.26872718e-321,   6.95150287e-310],
                  [  4.34283703e-321,   6.95150287e-310]])  # random data
        """
        if (not isinstance(other, numpy.ndarray)
                and not isinstance(other, pymic.OffloadArray)):
            raise ValueError("only numpy.ndarray can be used "
                             "with this function")
        return self.empty(other.shape,
                          other.dtype,
                          get_order(other),
                          update_host=update_host)
Exemplo n.º 5
0
    def empty_like(self, other, update_host=True):
        """Create a new OffloadArray that is bound to an empty numpy.ndarray
           that matches shape and type of an existing OffloadArray or
           numpy.ndarray.  If update_host is True (the default), then the empty
           array is automatically transferred to the host numpy.ndarray.  If
           set to False, the data transfer is avoided and the data in the host
           array is in undefined state.

           The operation is enqueued into the stream object and completes
           asynchronously.

           Parameters
           ----------
           other       : numpy.ndarray
               Template array used to determine shape, data type, and storage
               order
           update_host :
               Control if the host array is updated with the array data
               during construction of the OffloadArray

           See Also
           --------
           empty, zeros, zeros_like, ones, ones_like, bcast, bcast_like

           Examples
           --------
           >>> a = numpy.ones((2,2))
           >>> stream.empty_like(a)
           array([[  4.26872718e-321,   6.91990916e-310],
                  [  4.34283703e-321,   6.91990916e-310]])  # random data

           >>> o = stream.empty_like(a, update_host=False)
           >>> o
           array([[  1.12110451e-316,   1.32102240e-312],
                  [  6.94088686e-310,   6.94088688e-310]])  # random data
           >>> o.update_host()
           array([[  4.26872718e-321,   6.95150287e-310],
                  [  4.34283703e-321,   6.95150287e-310]])  # random data
        """
        if (not isinstance(other, numpy.ndarray) and
                not isinstance(other, pymic.OffloadArray)):
            raise ValueError("only numpy.ndarray can be used "
                             "with this function")
        return self.empty(other.shape, other.dtype, get_order(other),
                          update_host=update_host)