Skip to main content

RawTensorImpl

Struct RawTensorImpl 

Source
pub struct RawTensorImpl<'a>(/* private fields */);
Expand description

A raw tensor implementation.

This struct is a low-level match to the C++ TensorImpl class. A TensorImpl or any of its variants (TensorImplAny, TensorImplMut, etc) is preferred for most uses, but this struct is exposed for low level users who need to avoid code size overhead (avoiding the regular tensor generics). The struct does not enforce any mutability rules, and the caller must ensure that the tensor is used correctly according to its mutability.

Implementations§

Source§

impl<'a> RawTensorImpl<'a>

Source

pub unsafe fn from_ptr<S: Scalar>( sizes: &'a [SizesType], data: *mut S, dim_order: &'a [DimOrderType], strides: &'a [StridesType], ) -> Result<Self, Error>

Create a new TensorImpl from a pointer to the data.

§Arguments
  • sizes - The shape of the tensor.
  • data - A pointer to the data buffer.
  • dim_order - The order of the dimensions of the tensor, must have the same length as sizes.
  • strides - The strides of the tensor, in units of elements (not bytes), must have the same length as sizes.
§Errors

Returns an error if dim order is invalid, or if it doesn’t match the strides, or if the strides are not dense, i.e. if the strides are not the standard layout strides of some permutation of the sizes.

§Panics

If the sizes, dim_order or strides slices are of different lengths.

§Safety

The caller must ensure elements in the data can be safely accessed according to the scalar type, sizes, dim order and strides of the tensor. The caller must ensure that the data is valid for the lifetime of the TensorImpl.

Auto Trait Implementations§

§

impl<'a> Freeze for RawTensorImpl<'a>

§

impl<'a> RefUnwindSafe for RawTensorImpl<'a>

§

impl<'a> Send for RawTensorImpl<'a>

§

impl<'a> Sync for RawTensorImpl<'a>

§

impl<'a> Unpin for RawTensorImpl<'a>

§

impl<'a> UnwindSafe for RawTensorImpl<'a>

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.