pub struct BufferDescriptor {
pub len: usize,
pub offset: isize,
pub readonly: bool,
pub itemsize: usize,
pub format: Cow<'static, str>,
pub dim_desc: Vec<(usize, isize, isize)>,
}Fields§
§len: usizeproduct(shape) * itemsize bytes length, but not the length for obj_bytes() even is contiguous
offset: isizeByte position of the element at index [0, .., 0] within
PyBuffer::obj_bytes, which always yields the exporter’s whole memory.
Py_buffer.buf
A view that walks backwards begins at the far end of its data, so this is where addressing starts rather than a lower bound. A view with no elements addresses nothing and may sit outside the exporter altogether, which is why this is signed.
readonly: bool§itemsize: usize§format: Cow<'static, str>§dim_desc: Vec<(usize, isize, isize)>(shape, stride, suboffset) for each dimension. A non-zero suboffset means the dimension is reached through a pointer; slicing never introduces one.
Implementations§
Source§impl BufferDescriptor
impl BufferDescriptor
pub fn simple(bytes_len: usize, readonly: bool) -> Self
pub fn format( bytes_len: usize, readonly: bool, itemsize: usize, format: Cow<'static, str>, ) -> Self
Sourcepub fn projected(&self, flags: BufferFlags) -> Self
pub fn projected(&self, flags: BufferFlags) -> Self
The descriptor an exporter hands to a consumer that asked for flags:
everything the request did not ask for is dropped.
A Py_buffer drops a field by setting it to NULL and leaves the consumer to
reconstruct it. A descriptor has no NULL, so a dropped field is filled in
here with what that reconstruction would produce: "B" for a format, C-order
strides for strides, and a single dimension of len / itemsize items for a
shape. itemsize is never touched, so calcsize(format) and itemsize can
disagree on a projected descriptor — the format governs an element’s width,
the item size governs the step — and product(shape) * itemsize == len
continues to hold.
pub fn validate(self) -> Self
pub fn ndim(&self) -> usize
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Whether the elements are laid out in row-major order. _IsCContiguous
Sourcepub fn is_fortran_contiguous(&self) -> bool
pub fn is_fortran_contiguous(&self) -> bool
Whether the elements are laid out in column-major order. A view whose dimensions are all but one of length 1 is laid out both ways at once. _IsFortranContiguous
Sourcepub fn contiguous_range(&self) -> Range<usize> ⓘ
pub fn contiguous_range(&self) -> Range<usize> ⓘ
The byte range this view occupies in PyBuffer::obj_bytes, for a
contiguous view.
A view with no bytes maps to the empty range at zero: its offset is wherever slicing left it and need not be a position that exists.
Sourcepub fn contiguous(&self) -> Self
pub fn contiguous(&self) -> Self
The same shape, format and item size, laid out in C order from byte zero.
Sourcepub fn has_suboffsets(&self) -> bool
pub fn has_suboffsets(&self) -> bool
Whether any dimension is reached through a pointer rather than by
stepping, the layout PyBUF_INDIRECT describes.
Sourcepub fn fast_position(&self, indices: &[usize]) -> isize
pub fn fast_position(&self, indices: &[usize]) -> isize
this function do not check the bound panic if indices.len() != ndim
Sourcepub fn position(
&self,
indices: &[isize],
vm: &VirtualMachine,
) -> PyResult<isize>
pub fn position( &self, indices: &[isize], vm: &VirtualMachine, ) -> PyResult<isize>
panic if indices.len() != ndim
pub fn for_each_segment<F>(&self, try_contiguous: bool, f: F)
Sourcepub fn for_each_segment_fortran<F>(&self, f: F)
pub fn for_each_segment_fortran<F>(&self, f: F)
Visit each item’s byte range with the first dimension varying
fastest, which is the order a Fortran-ordered copy is written in.
for_each_segment visits in the opposite order and can hand over whole
rows at once; here every item is its own range, since consecutive items
in this order are a row apart.
Sourcepub fn zip_eq<F>(&self, other: &Self, try_contiguous: bool, f: F)
pub fn zip_eq<F>(&self, other: &Self, try_contiguous: bool, f: F)
zip two BufferDescriptor with the same shape
pub fn is_zero_in_shape(&self) -> bool
Trait Implementations§
Source§impl Clone for BufferDescriptor
impl Clone for BufferDescriptor
Auto Trait Implementations§
impl Freeze for BufferDescriptor
impl RefUnwindSafe for BufferDescriptor
impl Send for BufferDescriptor
impl Sync for BufferDescriptor
impl Unpin for BufferDescriptor
impl UnsafeUnpin for BufferDescriptor
impl UnwindSafe for BufferDescriptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Helper for T
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more