Skip to main content

ShapedType

Struct ShapedType 

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

Owned wrapper for MPSGraphShapedType.

Implementations§

Source§

impl ShapedType

Source

pub fn new(shape: Option<&[isize]>, data_type: u32) -> Option<Self>

Create a shaped type from an optional shape and MPSDataType raw value.

Examples found in repository?
examples/04_descriptor_compile.rs (line 33)
7fn main() {
8    let device = MetalDevice::system_default().expect("no Metal device available");
9    let graph = Graph::new().expect("graph");
10    let input = graph
11        .placeholder(Some(&[4]), data_type::FLOAT32, Some("input"))
12        .expect("placeholder");
13    let output = graph
14        .unary_arithmetic(UnaryArithmeticOp::Absolute, &input, Some("abs"))
15        .expect("absolute");
16
17    let descriptor = CompilationDescriptor::new().expect("compilation descriptor");
18    descriptor
19        .set_optimization_level(optimization::LEVEL1)
20        .expect("set optimization level");
21    descriptor
22        .set_wait_for_compilation_completion(true)
23        .expect("set wait");
24
25    let executable = graph
26        .compile_with_descriptor(
27            Some(&device),
28            &[FeedDescription::new(&input, &[4], data_type::FLOAT32)],
29            &[&output],
30            Some(&descriptor),
31        )
32        .expect("compile");
33    let input_type = ShapedType::new(Some(&[4]), data_type::FLOAT32).expect("shaped type");
34    let output_types = executable
35        .output_types(Some(&device), &[&input_type], Some(&descriptor))
36        .expect("output types");
37
38    println!("feed tensors: {}", executable.feed_tensors().len());
39    println!("target tensors: {}", executable.target_tensors().len());
40    println!("output type: {:?}", output_types[0].shape());
41}
Source

pub fn shape(&self) -> Option<Vec<isize>>

Return the optional tensor shape. None corresponds to an unranked shape.

Examples found in repository?
examples/04_descriptor_compile.rs (line 40)
7fn main() {
8    let device = MetalDevice::system_default().expect("no Metal device available");
9    let graph = Graph::new().expect("graph");
10    let input = graph
11        .placeholder(Some(&[4]), data_type::FLOAT32, Some("input"))
12        .expect("placeholder");
13    let output = graph
14        .unary_arithmetic(UnaryArithmeticOp::Absolute, &input, Some("abs"))
15        .expect("absolute");
16
17    let descriptor = CompilationDescriptor::new().expect("compilation descriptor");
18    descriptor
19        .set_optimization_level(optimization::LEVEL1)
20        .expect("set optimization level");
21    descriptor
22        .set_wait_for_compilation_completion(true)
23        .expect("set wait");
24
25    let executable = graph
26        .compile_with_descriptor(
27            Some(&device),
28            &[FeedDescription::new(&input, &[4], data_type::FLOAT32)],
29            &[&output],
30            Some(&descriptor),
31        )
32        .expect("compile");
33    let input_type = ShapedType::new(Some(&[4]), data_type::FLOAT32).expect("shaped type");
34    let output_types = executable
35        .output_types(Some(&device), &[&input_type], Some(&descriptor))
36        .expect("output types");
37
38    println!("feed tensors: {}", executable.feed_tensors().len());
39    println!("target tensors: {}", executable.target_tensors().len());
40    println!("output type: {:?}", output_types[0].shape());
41}
Source

pub fn data_type(&self) -> u32

Return the underlying MPSDataType raw value.

Source

pub fn set_shape(&self, shape: Option<&[isize]>) -> Result<()>

Replace the shape metadata for this shaped type.

Source

pub fn set_data_type(&self, data_type: u32) -> Result<()>

Replace the data-type metadata for this shaped type.

Source

pub fn is_equal(&self, other: Option<&Self>) -> bool

Compare two shaped types using MPSGraphShapedType.isEqual(to:).

Trait Implementations§

Source§

impl Drop for ShapedType

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for ShapedType

Source§

impl Sync for ShapedType

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