#[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
impl IValue
pub fn to_tensor(self) -> Option<Tensor>
pub fn to_string(&self) -> Option<String>
pub fn to_int_list(&self) -> Option<Vec<i64>>
pub fn to_int(&self) -> Option<i64>
pub fn to_double(&self) -> Option<f64>
pub fn to_bool(&self) -> Option<bool>
pub fn to_tensor_list(self) -> Option<Vec<Tensor>>
pub fn to_device(&self) -> Option<Device>
pub fn to_none(&self) -> Option<()>
pub fn to_opaque(self) -> Option<OpaqueIValue>
pub fn is_tensor(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_int_list(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_double(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_tensor_list(&self) -> bool
pub fn is_device(&self) -> bool
pub fn is_none(&self) -> bool
pub fn is_other(&self) -> bool
pub fn kind(&self) -> IValueKind
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
impl CloneUnsafe for IValue
Source§unsafe fn clone_unsafe(&self) -> Self
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:
- The clone must not be sent to another thread (local).
- You must guarantee that clone is dropped before the originating mutable reference is dropped (ephemeral).
Source§impl<'de> Deserialize<'de> for IValue
impl<'de> Deserialize<'de> for IValue
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl ExternType for IValue
impl ExternType for IValue
Source§impl FromPyObject<'_> for IValue
impl FromPyObject<'_> for IValue
Source§fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self>
fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self>
Source§impl<'py> IntoPyObject<'py> for IValue
impl<'py> IntoPyObject<'py> for IValue
impl Send for IValue
SAFETY: IValue is Send
, it is either a copyable type or atomically
refcounted via c10::intrusive_ptr
.
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§
impl Freeze for IValue
impl RefUnwindSafe for IValue
impl Unpin for IValue
impl UnwindSafe for IValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<A, M> Handler<IndexedErasedUnbound<M>> for A
impl<A, M> Handler<IndexedErasedUnbound<M>> for A
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
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>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self
into a Python object. Read more