Skip to main content

HostArray

Struct HostArray 

Source
pub struct HostArray { /* private fields */ }
Expand description

An array in host memory: a typed buffer and a shape.

Implementations§

Source§

impl HostArray

Source

pub fn from_vec<T: Element>(data: Vec<T>, shape: impl Into<Shape>) -> Self

Creates an array from its elements in row-major order.

§Panics

Panics if the number of elements does not match the shape.

Source

pub fn from_buffer(buffer: Buffer, shape: impl Into<Shape>) -> Self

Creates an array from a buffer.

§Panics

Panics if the number of elements does not match the shape.

Source

pub fn scalar<T: Element>(v: T) -> Self

Creates a scalar.

Source

pub fn full(shape: impl Into<Shape>, dtype: DType, value: Value) -> Self

An array filled with value, converted to dtype.

Source

pub fn zeros(shape: impl Into<Shape>, dtype: DType) -> Self

An array of zeros.

Source

pub fn dtype(&self) -> DType

Returns the element type.

Source

pub fn shape(&self) -> &Shape

Returns the shape.

Source

pub fn aval(&self) -> AVal

Returns the abstract value.

Source

pub fn size(&self) -> usize

Returns the number of elements.

Source

pub fn buffer(&self) -> &Buffer

Returns the buffer.

Source

pub fn into_buffer(self) -> Buffer

Returns the buffer, consuming the array.

Source

pub fn as_slice<T: Element>(&self) -> Result<&[T]>

Views the elements as T.

§Errors

Returns an error if the elements have another type.

Source

pub fn to_vec<T: Element>(&self) -> Result<Vec<T>>

Copies the elements as T.

§Errors

Returns an error if the elements have another type.

Source

pub fn get(&self, i: usize) -> Value

Returns element i (in row-major order), widened.

Source

pub fn convert(&self, dtype: DType) -> Self

Returns the array with its elements converted to dtype.

Source

pub fn reshape(self, shape: impl Into<Shape>) -> Self

Returns the array with another shape of the same size.

§Panics

Panics if the sizes differ.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

Returns the native-endian bytes of the elements.

Source

pub fn from_bytes( bytes: &[u8], shape: impl Into<Shape>, dtype: DType, ) -> Result<Self>

Creates an array from native-endian bytes.

§Errors

Returns an error if the number of bytes does not match.

Trait Implementations§

Source§

impl Clone for HostArray

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 HostArray

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for HostArray

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HostArray

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
§

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

§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

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

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.