Skip to main content

Feed

Struct Feed 

Source
pub struct Feed<'a> {
    pub tensor: &'a Tensor,
    pub data: &'a TensorData,
}
Expand description

Ordered placeholder feed pairing used for graph execution.

Fields§

§tensor: &'a Tensor§data: &'a TensorData

Implementations§

Source§

impl<'a> Feed<'a>

Source

pub const fn new(tensor: &'a Tensor, data: &'a TensorData) -> Self

Examples found in repository?
examples/01_add_relu.rs (line 24)
4fn main() {
5    let device = MetalDevice::system_default().expect("no Metal device available");
6    let graph = Graph::new().expect("failed to create MPSGraph");
7
8    let input = graph
9        .placeholder(Some(&[2, 2]), data_type::FLOAT32, Some("input"))
10        .expect("failed to create placeholder");
11    let bias = graph
12        .constant_scalar(1.0, data_type::FLOAT32)
13        .expect("failed to create scalar constant");
14    let added = graph
15        .addition(&input, &bias, Some("add"))
16        .expect("failed to create addition op");
17    let output = graph
18        .relu(&added, Some("relu"))
19        .expect("failed to create relu op");
20
21    let input_data = TensorData::from_f32_slice(&device, &[1.0, -2.0, 3.0, -4.0], &[2, 2])
22        .expect("failed to create tensor data");
23    let results = graph
24        .run(&[Feed::new(&input, &input_data)], &[&output])
25        .expect("failed to execute graph");
26    let values = results[0].read_f32().expect("failed to read tensor output");
27
28    assert_eq!(values, vec![2.0, 0.0, 4.0, 0.0]);
29    println!("add+relu smoke passed: {values:?}");
30}

Trait Implementations§

Source§

impl<'a> Clone for Feed<'a>

Source§

fn clone(&self) -> Feed<'a>

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<'a> Copy for Feed<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Feed<'a>

§

impl<'a> RefUnwindSafe for Feed<'a>

§

impl<'a> Send for Feed<'a>

§

impl<'a> Sync for Feed<'a>

§

impl<'a> Unpin for Feed<'a>

§

impl<'a> UnsafeUnpin for Feed<'a>

§

impl<'a> UnwindSafe for Feed<'a>

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<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.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.