示例#1
0
    def __array_interface__(self):
        """Return an `__array_interface__` version 3.

        Note that the pointer returned in the items 'data' corresponds to
        a memory area under R's memory management and that it will become
        invalid once the area once R frees the object. It is safer to keep
        the rpy2 object proxying the R object alive for the duration the
        pointer is used in Python / numpy."""
        return {
            'shape': bufferprotocol.getshape(self.__sexp__._cdata),
            'typestr': self._NP_TYPESTR,
            'strides': bufferprotocol.getstrides(self.__sexp__._cdata),
            'data': self._R_GET_PTR(self.__sexp__._cdata),
            'version': 3
        }
示例#2
0
    def __array_interface__(self: NPCOMPAT_TYPE) -> dict:
        """Return an `__array_interface__` version 3.

        Note that the pointer returned in the items 'data' corresponds to
        a memory area under R's memory management and that it will become
        invalid once the area once R frees the object. It is safer to keep
        the rpy2 object proxying the R object alive for the duration the
        pointer is used in Python / numpy."""
        shape = bufferprotocol.getshape(self.__sexp__._cdata)
        data = openrlib.ffi.buffer(self._R_GET_PTR(self.__sexp__._cdata))
        strides = bufferprotocol.getstrides(self.__sexp__._cdata, shape,
                                            self._R_SIZEOF_ELT)
        return {
            'shape': shape,
            'typestr': self._NP_TYPESTR,
            'strides': strides,
            'data': data,
            'version': 3
        }