def data_descriptor_from_ctypes(cdata, writable): """ Parameters ---------- cdata : ctypes data instance The ctypes data object which owns the data. writable : bool Should be true if the data is writable, flase if it's read-only. """ ds = datashape.from_ctypes(type(cdata)) access = "readwrite" if writable else "readonly" dyndarr = _lowlevel.array_from_ptr(ndt.type(str(ds)), ctypes.addressof(cdata), cdata, access) return DyNDDataDescriptor(dyndarr)
def data_descriptor_from_ctypes(cdata, writable): """ Parameters ---------- cdata : ctypes data instance The ctypes data object which owns the data. writable : bool Should be true if the data is writable, flase if it's read-only. """ ds = datashape.from_ctypes(type(cdata)) access = "readwrite" if writable else "readonly" dyndtp = " * ".join(["cfixed[%d]" % int(x) for x in ds[:-1]] + [str(ds[-1])]) dyndarr = _lowlevel.array_from_ptr(ndt.type(dyndtp), ctypes.addressof(cdata), cdata, access) return DyND_DDesc(dyndarr)
def data_descriptor_from_ctypes(cdata, writable): """ Parameters ---------- cdata : ctypes data instance The ctypes data object which owns the data. writable : bool Should be true if the data is writable, flase if it's read-only. """ ds = datashape.from_ctypes(type(cdata)) access = "readwrite" if writable else "readonly" dyndtp = ' * '.join(['cfixed[%d]' % int(x) for x in ds[:-1]] + [str(ds[-1])]) dyndarr = _lowlevel.array_from_ptr(ndt.type(dyndtp), ctypes.addressof(cdata), cdata, access) return DyND_DDesc(dyndarr)