Struct IValue

Source
#[repr(C)]
pub struct IValue { /* private fields */ }
Expand description

Rust binding for the C++ type c10::IValue.

IValue is a tagged union type that can hold any input to a PyTorch operator. See IValueKind for the list of supported types.

§Safety

IValue either contains Copy-able data or a Tensor-like object, so it inherits the safety properties of Tensor. See the safety discussion in Tensor for more info.

Implementations§

Source§

impl IValue

Source

pub fn dump(&self)

Prints a human-readable representation of the IValue to stdout.

Source§

impl IValue

Source

pub fn to_tensor(self) -> Option<Tensor>

Source

pub fn to_string(&self) -> Option<String>

Source

pub fn to_int_list(&self) -> Option<Vec<i64>>

Source

pub fn to_int(&self) -> Option<i64>

Source

pub fn to_double(&self) -> Option<f64>

Source

pub fn to_bool(&self) -> Option<bool>

Source

pub fn to_tensor_list(self) -> Option<Vec<Tensor>>

Source

pub fn to_device(&self) -> Option<Device>

Source

pub fn to_none(&self) -> Option<()>

Source

pub fn to_opaque(self) -> Option<OpaqueIValue>

Source

pub fn is_tensor(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_int_list(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_double(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_tensor_list(&self) -> bool

Source

pub fn is_device(&self) -> bool

Source

pub fn is_none(&self) -> bool

Source

pub fn is_other(&self) -> bool

Source

pub fn kind(&self) -> IValueKind

Source

pub fn from_py_object_with_type( obj: Bound<'_, PyAny>, type_: &TypePtr, num_elements: i32, allow_nums_as_tensors: bool, ) -> PyResult<IValue>

Trait Implementations§

Source§

impl CloneUnsafe for IValue

Source§

unsafe fn clone_unsafe(&self) -> Self

This is unsafe, it creates an alias of the underlying data that is not tracked by Rust. We use this to interface with C++ functions that expect an owned IValue.

The contract for calling this function is that the clone is local and ephemeral. More precisely:

  1. The clone must not be sent to another thread (local).
  2. You must guarantee that clone is dropped before the originating mutable reference is dropped (ephemeral).
Source§

impl Debug for IValue

Source§

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

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

impl<'de> Deserialize<'de> for IValue

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Drop for IValue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ExternType for IValue

Source§

type Id = (c, _1, _0, (), I, V, a, l, u, e)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Trivial

Source§

impl From<&[i64]> for IValue

Source§

fn from(value: &[i64]) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for IValue

Source§

fn from(value: &String) -> Self

Converts to this type from the input type.
Source§

impl From<()> for IValue

Source§

fn from(_value: ()) -> Self

Converts to this type from the input type.
Source§

impl From<Device> for IValue

Source§

fn from(value: Device) -> Self

Converts to this type from the input type.
Source§

impl From<IValue> for RValue

Source§

fn from(ivalue: IValue) -> Self

Converts to this type from the input type.
Source§

impl From<Tensor> for IValue

Source§

fn from(value: Tensor) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Tensor>> for IValue

Source§

fn from(value: Vec<Tensor>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for IValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for IValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for IValue

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl FromPyObject<'_> for IValue

Source§

fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<'py> IntoPyObject<'py> for IValue

Source§

type Target = PyAny

The Python output type
Source§

type Output = Bound<'py, <IValue as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

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

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error>

Performs the conversion.
Source§

impl PartialEq for IValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for IValue

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Send for IValue

SAFETY: IValue is Send, it is either a copyable type or atomically refcounted via c10::intrusive_ptr.

Source§

impl Sync for IValue

SAFETY: IValue is Sync, due to safety in exposing any of the interior mutability of the payload it holds. The value is converted to native types like Tensor for use in rust or left opaque. See OpaqueIValue for more details.

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.

§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, M> Handler<IndexedErasedUnbound<M>> for A
where A: Handler<M>, M: Castable,

Source§

fn handle<'life0, 'life1, 'async_trait>( &'life0 mut self, cx: &'life1 Context<'_, A>, msg: IndexedErasedUnbound<M>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, A: 'async_trait,

Handle the next M-typed message.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<M> Message for M
where M: Debug + Send + Sync + 'static,

§

impl<T> Ungil for T
where T: Send,