fn data()

in bindings/python/src/view.rs [37:50]


    fn data(&self) -> std::borrow::Cow<[u8]> {
        // We already checked this in the Python side.
        assert!(self.data.is_c_contiguous());
        // XXX: Ideally we could have at least readonly tensors
        // assert!(self.data.readonly());
        // SAFETY:
        // This is actually totally unsafe, PyBuffer is not immutable and could be changed from
        // under us.
        // This is made safer because we're still hanging to the GIL while treating
        // this structure
        Cow::Borrowed(unsafe {
            std::slice::from_raw_parts(self.data.buf_ptr() as *const u8, self.data.item_count())
        })
    }