Struct Tensor

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

Rust binding for the C++ type at::Tensor.

§Safety

Tensor will properly manage the refcount of the underling TensorImpl.

Tensor is Send: it is safe to send across thread boundaries because the underlying C++ type is atomically refcounted.

Tensor is Sync: it can be shared across threads. The underlying C++ type has interior mutability, (i.e. a const Tensor& can be used to mutate the tensor) but we are careful to expose Rust bindings that require exclusive access (ownership or mutable reference) for any C++ code that can mutate a tensor.

Implementations§

Source§

impl Tensor

Source

pub fn device(&self) -> Device

Source§

impl Tensor

Source

pub fn scalar_type(&self) -> ScalarType

Source§

impl Tensor

Source

pub fn is_cuda(&self) -> bool

Source§

impl Tensor

Source

pub fn cpu(&self) -> Tensor

Source§

impl Tensor

Source

pub fn is_sparse(&self) -> bool

Source§

impl Tensor

Source

pub fn is_contiguous(&self, memory_format: MemoryFormat) -> bool

Source§

impl Tensor

Source

pub fn numel(&self) -> i64

Source§

impl Tensor

Source

pub fn nbytes(&self) -> usize

Source§

impl Tensor

Source

pub fn equal(&self, other: &Tensor) -> bool

Source§

impl Tensor

Source

pub fn defined(&self) -> bool

Source§

impl Tensor

Source

pub unsafe fn data_ptr(&self) -> *const c_void

This is unsafe as it directly accesses the underlying data pointer. Additionally, this should only be used when the user is sure the tensor is defined.

Source

pub unsafe fn mut_data_ptr(&self) -> *mut c_void

This is unsafe as it directly accesses the underlying data pointer. Additionally, this should only be used when the user is sure the tensor is defined.

Source

pub fn copy_(&mut self, src: &Tensor)

Self-modify this tensor by copying data from another tensor. The other tensor must be the same shape as this one.

Source

pub fn sizes(&self) -> Vec<i32>

Return the size of each dimension in this tensor.

Source

pub fn shape(&self) -> Vec<i32>

Alias of sizes.

Trait Implementations§

Source§

impl CloneUnsafe for Tensor

Source§

unsafe fn clone_unsafe(&self) -> Self

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

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 Tensor

Source§

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

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

impl<'de> Deserialize<'de> for Tensor

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 Display for Tensor

Source§

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

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

impl Drop for Tensor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ExternType for Tensor

Source§

type Id = (t, o, r, c, h, (), T, e, n, s, o, r)

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

type Kind = Trivial

Source§

impl From<Tensor> for IValue

Source§

fn from(value: Tensor) -> Self

Converts to this type from the input type.
Source§

impl FromPyObject<'_> for Tensor

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 Tensor

Source§

type Target = PyAny

The Python output type
Source§

type Output = Bound<'py, <Tensor 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 Tensor

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 Tensor

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 Tensor

Source§

impl Sync for Tensor

Source§

impl VectorElement for Tensor

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

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,