mapped_struct.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:sharedbuffers 作者: jampp 项目源码 文件源码
def iteritems(self):
        buf = self._buf
        dtype = self.dtype
        index = self.index
        if cython.compiled:
            #lint:disable
            buf = self._likebuf
            PyObject_GetBuffer(buf, cython.address(pybuf), PyBUF_SIMPLE)
            try:
                if dtype is npuint64:
                    PyObject_GetBuffer(index, cython.address(indexbuf), PyBUF_STRIDED_RO)
                    try:
                        if ( indexbuf.strides == cython.NULL 
                                or indexbuf.ndim < 2
                                or indexbuf.len < self.index_elements * indexbuf.strides[0] ):
                            raise ValueError("Invalid buffer state")
                        stride0 = indexbuf.strides[0]
                        stride1 = indexbuf.strides[1]
                        pindex = cython.cast(cython.p_char, indexbuf.buf)
                        for i in xrange(self.index_elements):
                            yield (
                                cython.cast(cython.p_ulonglong, pindex)[0],
                                cython.cast(cython.p_ulonglong, pindex + stride1)[0]
                            )
                            pindex += stride0
                    finally:
                        PyBuffer_Release(cython.address(indexbuf))
                elif dtype is npuint32:
                    PyObject_GetBuffer(index, cython.address(indexbuf), PyBUF_STRIDED_RO)
                    try:
                        if ( indexbuf.strides == cython.NULL 
                                or indexbuf.ndim < 2
                                or indexbuf.len < self.index_elements * indexbuf.strides[0] ):
                            raise ValueError("Invalid buffer state")
                        stride0 = indexbuf.strides[0]
                        stride1 = indexbuf.strides[1]
                        pindex = cython.cast(cython.p_char, indexbuf.buf)
                        for i in xrange(self.index_elements):
                            yield (
                                cython.cast(cython.p_uint, pindex)[0],
                                cython.cast(cython.p_uint, pindex + stride1)[0]
                            )
                            pindex += stride0
                    finally:
                        PyBuffer_Release(cython.address(indexbuf))
                else:
                    for i in xrange(self.index_elements):
                        yield (
                            index[i,0],
                            index[i,1]
                        )
            finally:
                PyBuffer_Release(cython.address(pybuf))
            #lint:enable
        else:
            for i in xrange(self.index_elements):
                yield (index[i,0], index[i,1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号