python类ctypeslib()的实例源码

shmarray.py 文件源码 项目:TensorArtist 作者: vacancy 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __new__(cls, ctypesArray, shape, dtype=float,
                strides=None, offset=0, order=None):

        # some magic (copied from numpy.ctypeslib) to make sure the ctypes array
        # has the array interface
        tp = type(ctypesArray)
        try:
            tp.__array_interface__
        except AttributeError:
            ctypeslib.prep_array(tp)

        obj = numpy.ndarray.__new__(cls, shape, dtype, ctypesArray, offset, strides,
                                    order)

        # keep track of the underlying storage
        # this may not be strictly necessary as the same info should be stored in .base
        obj.ctypesArray = ctypesArray

        return obj
c.py 文件源码 项目:kernel_tuner 作者: benvanwerkhoven 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def memcpy_dtoh(self, dest, src):
        """a simple memcpy expects a ctypes pointer, returns a numpy array

        :param dest: A numpy array to store the data
        :type dest: numpy.ndarray

        :param src: A ctypes pointer to some memory allocation
        :type src: ctypes.pointer
        """
        dest[:] = numpy.ctypeslib.as_array(src, shape=self.arg_mapping[str(src)])


问题


面经


文章

微信
公众号

扫码关注公众号