#[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
impl Tensor
pub fn scalar_type(&self) -> ScalarType
Source§impl Tensor
impl Tensor
pub fn is_contiguous(&self, memory_format: MemoryFormat) -> bool
Source§impl Tensor
impl Tensor
Sourcepub unsafe fn data_ptr(&self) -> *const c_void
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.
Sourcepub unsafe fn mut_data_ptr(&self) -> *mut c_void
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.
Trait Implementations§
Source§impl CloneUnsafe for Tensor
impl CloneUnsafe for Tensor
Source§unsafe fn clone_unsafe(&self) -> Self
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:
- 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 Tensor
impl<'de> Deserialize<'de> for Tensor
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 Tensor
impl ExternType for Tensor
Source§impl FromPyObject<'_> for Tensor
impl FromPyObject<'_> for Tensor
Source§fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self>
fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self>
Source§impl<'py> IntoPyObject<'py> for Tensor
impl<'py> IntoPyObject<'py> for Tensor
impl Send for Tensor
impl Sync for Tensor
impl VectorElement for Tensor
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl Unpin for Tensor
impl UnwindSafe for Tensor
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