Skip to main content

BufferDescriptor

Struct BufferDescriptor 

Source
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: usize

product(shape) * itemsize bytes length, but not the length for obj_bytes() even is contiguous

§offset: isize

Byte 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

Source

pub fn simple(bytes_len: usize, readonly: bool) -> Self

Source

pub fn format( bytes_len: usize, readonly: bool, itemsize: usize, format: Cow<'static, str>, ) -> Self

Source

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.

Source

pub fn validate(self) -> Self

Source

pub fn ndim(&self) -> usize

Source

pub fn is_contiguous(&self) -> bool

Whether the elements are laid out in row-major order. _IsCContiguous

Source

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

Source

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.

Source

pub fn contiguous(&self) -> Self

The same shape, format and item size, laid out in C order from byte zero.

Source

pub fn has_suboffsets(&self) -> bool

Whether any dimension is reached through a pointer rather than by stepping, the layout PyBUF_INDIRECT describes.

Source

pub fn fast_position(&self, indices: &[usize]) -> isize

this function do not check the bound panic if indices.len() != ndim

Source

pub fn position( &self, indices: &[isize], vm: &VirtualMachine, ) -> PyResult<isize>

panic if indices.len() != ndim

Source

pub fn for_each_segment<F>(&self, try_contiguous: bool, f: F)
where F: FnMut(Range<isize>),

Source

pub fn for_each_segment_fortran<F>(&self, f: F)
where F: FnMut(Range<isize>),

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.

Source

pub fn zip_eq<F>(&self, other: &Self, try_contiguous: bool, f: F)
where F: FnMut(Range<isize>, Range<isize>) -> bool,

zip two BufferDescriptor with the same shape

Source

pub fn is_zero_in_shape(&self) -> bool

Trait Implementations§

Source§

impl Clone for BufferDescriptor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BufferDescriptor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Helper for T

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> PrimitiveIntRandomBounds for T

Source§

impl<T> PrimitiveSignedRandomBounds for T

Source§

impl<T> PyThreadingConstraint for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U