Пример #1
0
    def __init__(self, dtype, shape=None, strides=None, offset=0, nbytes=None):
        self.shape = tuple() if shape is None else wrap_in_tuple(shape)
        self.size = product(self.shape)
        self.dtype = dtypes.normalize_type(dtype)
        self.ctype = dtypes.ctype_module(self.dtype)

        default_strides = helpers.default_strides(self.shape,
                                                  self.dtype.itemsize)
        if strides is None:
            strides = default_strides
        else:
            strides = tuple(strides)
        self._default_strides = strides == default_strides
        self.strides = strides

        default_nbytes = helpers.min_buffer_size(self.shape,
                                                 self.dtype.itemsize,
                                                 self.strides)
        if nbytes is None:
            nbytes = default_nbytes
        self._default_nbytes = nbytes == default_nbytes
        self.nbytes = nbytes

        self.offset = offset
        self._cast = dtypes.cast(self.dtype)
Пример #2
0
    def array(self,
              shape,
              dtype,
              strides=None,
              offset=0,
              nbytes=None,
              allocator=None,
              base=None,
              base_data=None):

        if allocator is None:
            allocator = self.allocate

        dtype = dtypes.normalize_type(dtype)
        shape = wrap_in_tuple(shape)
        if nbytes is None:
            nbytes = min_buffer_size(shape,
                                     dtype.itemsize,
                                     strides=strides,
                                     offset=offset)

        if (offset != 0
                or strides is not None) and base_data is None and base is None:
            base_data = allocator(nbytes)
        elif base is not None:
            base_data = base.data

        return Array(self,
                     shape,
                     dtype,
                     strides=strides,
                     offset=offset,
                     allocator=allocator,
                     base_data=base_data,
                     nbytes=nbytes)
Пример #3
0
    def array(self,
              shape,
              dtype,
              strides=None,
              offset=0,
              nbytes=None,
              allocator=None,
              base=None,
              base_data=None):

        # In PyCUDA, the default allocator is not None, but a default alloc object
        if allocator is None:
            allocator = cuda.mem_alloc

        dtype = dtypes.normalize_type(dtype)
        shape = wrap_in_tuple(shape)
        if nbytes is None:
            nbytes = int(
                min_buffer_size(shape,
                                dtype.itemsize,
                                strides=strides,
                                offset=offset))

        if (offset != 0
                or strides is not None) and base_data is None and base is None:
            base_data = allocator(nbytes)
        elif base is not None:
            if isinstance(base, Array):
                base_data = base.base_data
            else:
                base_data = base.gpudata

        return Array(self,
                     shape,
                     dtype,
                     strides=strides,
                     allocator=allocator,
                     offset=offset,
                     base_data=base_data,
                     nbytes=nbytes)
Пример #4
0
    def __init__(self, dtype, shape=None, strides=None, offset=0, nbytes=None):
        self.shape = tuple() if shape is None else wrap_in_tuple(shape)
        self.size = product(self.shape)
        self.dtype = dtypes.normalize_type(dtype)
        self.ctype = dtypes.ctype_module(self.dtype)

        default_strides = helpers.default_strides(self.shape, self.dtype.itemsize)
        if strides is None:
            strides = default_strides
        else:
            strides = tuple(strides)
        self._default_strides = strides == default_strides
        self.strides = strides

        default_nbytes = helpers.min_buffer_size(self.shape, self.dtype.itemsize, self.strides)
        if nbytes is None:
            nbytes = default_nbytes
        self._default_nbytes = nbytes == default_nbytes
        self.nbytes = nbytes

        self.offset = offset
        self._cast = dtypes.cast(self.dtype)
Пример #5
0
    def array(
            self, shape, dtype, strides=None, offset=0, nbytes=None,
            allocator=None, base=None, base_data=None):

        # In PyCUDA, the default allocator is not None, but a default alloc object
        if allocator is None:
            allocator = cuda.mem_alloc

        dtype = dtypes.normalize_type(dtype)
        shape = wrap_in_tuple(shape)
        if nbytes is None:
            nbytes = int(min_buffer_size(shape, dtype.itemsize, strides=strides, offset=offset))

        if (offset != 0 or strides is not None) and base_data is None and base is None:
            base_data = allocator(nbytes)
        elif base is not None:
            if isinstance(base, Array):
                base_data = base.base_data
            else:
                base_data = base.gpudata

        return Array(
            self, shape, dtype, strides=strides, allocator=allocator,
            offset=offset, base_data=base_data, nbytes=nbytes)