Struct caffe2_tensor::Tensor

source ·
pub struct Tensor { /* private fields */ }
Expand description

| @brief | | Tensor class holds a shared pointer | to the implementation TensorImpl, | redirects API calls to TensorImpl; | | Copying of Tensor results in sharing | the same underlying implementation | object | | NB: See TensorImpl for documentation | on these methods. |

Implementations§

source§

impl Tensor

source

pub fn get_intrusive_ptr(&self) -> &IntrusivePtr<TensorImpl>

source

pub unsafe fn new(other: &Tensor) -> Self

source

pub fn resize<Ts>(&self, dim_source: Ts)

source

pub fn resize_with_dim_vec<T>(&self, dim_source: &Vec<T>)

source

pub fn unsafe_get_tensor_impl(&self) -> *mut TensorImpl

source

pub fn unsafe_shared_instance(&self) -> Tensor

source

pub fn new_with_dimension_and_type(dims: &[i32], ty: DeviceType) -> Self

| ———– | @brief | | Creates a tensor of the given dimension. | | ———– | @note | | the actual data allocation is not going | to be carried out until the first time | mutable_data() is called. |

source

pub fn new_with_dimension_and_device(dims: &[i32], device: Device) -> Self

we want to preserve index information

source

pub fn new_with_dimension_vec_and_type(dims: &Vec<i32>, ty: DeviceType) -> Self

TODO: remove?

source

pub fn new_with_type_from_src(src: &Tensor, ty: DeviceType) -> Self

| @brief | | : Create a Tensor of at::DeviceType | type and initialize it with src Tensor |

source§

impl Tensor

source

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

source

pub fn clone(&self) -> Tensor

source

pub fn alias(&self) -> Tensor

| Clone self as a Tensor that share the | same | | Storage, that is, both Tensors are views | on the same Storage. | | If we change the sizes or strides of one | | Tensor, it does not affect the other | Tensor that it shares Storage with. | | A similar yet different usage is Tensor | x = y;, this will make x and y pointing | to the same Tensor and resizing one of | them will resize the other as well. | | TODO: Deduplicate this with | | THTensor_(newWithTensor) (exposed | in ATen as at::alias but not otherwise | available) |

source

pub fn get_device_type(&self) -> DeviceType

source

pub fn get_device(&self) -> Device

source

pub fn extend_to(&self, num: i64, growth_pct: f32)

| ———– | @brief | | Extend the outer-most dimension of | this tensor to dimension of num. |

source

pub fn extend(&self, num: i64, growth_pct: f32)

source

pub fn shrink_to(&self, outer_dim: i64)

| ———– | @brief | | Shrinks the outer-most dimension to | given size, keeping the data. | | This method guarantees that no re-allocations | are carried out, which means that the | extra capacity after the end of the shrunk | tensor is maintained. | | Notably, this function does NOT respect | caffe2_keep_on_shrink. |

source

pub fn reserve_space<T>(&self, outer_dim: &T)

source

pub fn resize_like(&self, src_tensor: &Tensor)

| Resize the tensor like the source tensor. | Note that this is just a sugar wrapper | that essentially calls | | Resize(src_tensor.dims()). | | This method respects caffe2_keep_on_shrink. |

source

pub fn reshape<T: PrimInt>(&self, dims: &Vec<T>)

source

pub fn free_memory(&self)

source

pub fn debug_string(&self) -> String

| A utility function to print the debug | string for the tensor. Note that this | is very slow since it involves quite | some string operations, so do not use | it in your performance-critical code. |

source

pub fn share_data(&self, src: &Tensor)

To be deprecated

source

pub fn share_external_pointer_with_externally_managed_pointer<T>( &self, src: *mut T, nbytes: usize, d: MemoryDeleter )

| @brief | | Shares the data with an externally managed | pointer. | | This is similar to ShareData() but the | source is a pointer with an advanced | deleter option. | | In default, no deletion takes place, | and one needs to make sure that the external | memory is deallocated only after the | tensor finishes using it. | | If a Deleter object is passed in, when | this tensor is reallocated or freed, | the deleter function is going to be called. |

source

pub fn share_external_pointer_with_deleter( &self, src: *mut c_void, data_type: TypeMeta, nbytes: Option<usize>, d: Option<MemoryDeleter> )

source

pub fn share_external_pointer<T>(&self, data_ptr: DataPtr, nbytes: usize)

source

pub fn share_external_pointer_with_data_type( &mut self, data_ptr: DataPtr, data_type: TypeMeta, nbytes: usize )

source

pub fn defined(&self) -> bool

source

pub fn raw_data(&self)

| Returns a raw void* pointer of the underlying | storage. mutable_data() or raw_mutable_data() | must have been called prior to this function | call. |

source

pub fn data<T>(&self) -> *mut T

source

pub fn raw_mutable_data_with_type_meta(&self, meta: TypeMeta)

source

pub fn raw_mutable_data(&self)

| Returns a mutable raw pointer of the | underlying storage. This can only be | used when you know for sure that the underlying | storage of the tensor is already created | via an earlier raw_mutable_data(meta) | call or a mutable_data() call. | | If the existing data does not match the | desired type, it will be deleted and | a new storage will be created. |

source

pub fn mutable_data<T>(&self) -> *mut T

source

pub fn dim(&self) -> i32

| Returns the number of dimensions of | the data. |

source

pub fn ndim(&self) -> i32

| (To be deprecated) Returns the number | of dimensions of the data. |

source

pub fn size(&self) -> i64

| (To be deprecated) Returns the size | (i.e. the number of items) of the tensor. |

source

pub fn numel(&self) -> i64

| Returns the number of items of the tensor. |

source

pub fn itemsize(&self) -> usize

| Return the number of bytes each item | takes in the tensor. |

source

pub fn nbytes(&self) -> usize

| Returns the total number of bytes of | the storage. | | This is equivalent to calling size() | * itemsize(). |

source

pub fn sizes(&self) -> &[i32]

source

pub fn size_from_dim(&self, k: i32) -> i64

source

pub fn size_to_dim(&self, k: i32) -> i64

source

pub fn size_between_dim(&self, k: i32, l: i32) -> i64

source

pub fn canonical_axis_index(&self, axis_index: i32) -> i32

| Returns the ‘canonical’ version of | a (usually) user-specified axis, allowing | for negative indexing (e.g., -1 for the last | axis). | | @param axis_index the axis index. | If 0 <= index < dim(), return index. | If -ndim <= index <= -1, return (dim() - (-index)), | e.g., the last axis index (dim() - 1) if index == -1, | the second to last if index == -2, etc. | Dies on out of range index.

source

pub fn stride(&self, dim: i64) -> i64

source

pub fn strides(&self) -> &[i32]

source

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

source

pub fn is_type<T>(&self) -> bool

| Checks if the tensor content is of the | given data type. |

source

pub fn dtype(&self) -> TypeMeta

| Returns the TypeMeta object associated | with the current data type. |

source

pub fn meta(&self) -> TypeMeta

| (To be deprecated) Returns the TypeMeta | object associated with the current | data type. |

source

pub fn dim32(&self, i: i32) -> i32

| Returns the i-th dimension of the tensor | in int. | | This function returns an int value instead | of int64_t, which depending on the typedef | could be int64. If you want int64 dim | values, make sure you call dim() instead. |

source

pub fn size_from_index(&self, i: i32) -> i64

source

pub fn dim_from_index(&self, i: i32) -> i64

source

pub fn mut_storage<'a>(&'a mut self) -> &'a mut Storage

source

pub fn storage<'a>(&'a self) -> &'a Storage

source

pub fn storage_initialized(&self) -> bool

source

pub fn dtype_initialized(&self) -> bool

source

pub fn reinitialize_tensor( &mut self, tensor: *mut Tensor, dims: &[i32], options: TensorOptions )

| Reinitialize a Tensor to given dims | and options if necessary, note that | this will not do anything if the Tensor | already has correct size and data type |

source

pub fn reinitialize_and_copy_from( &mut self, t: *mut Tensor, options: TensorOptions, src: &Tensor, async_: bool )

source

pub fn enforce_invariants(&mut self)

source

pub fn copy_from(&mut self, src: &Tensor, async_: Option<bool>)

| @brief | | Copies the data from a source tensor, | with a context provided to carry out | the underlying memcpy operation. This | method respects caffe2_keep_on_shrink. | | After CopyFrom, this function guarantees | that the destination tensor will have | the same initialization state and dtype | as src. | | This function preserves the DeviceType | of the source tensor (so, e.g., if you | allocate a tensor on CPU and then CopyFrom | a CUDA tensor, that will to a CUDA-to-CPU | transfer). ‘async’ parameter triggers | async copy for | | CUDA tensors |

Trait Implementations§

source§

impl Clone for Tensor

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Tensor

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<DeviceType> for Tensor

source§

fn from(device: DeviceType) -> Self

| ———– | @brief | | Creates a tensor of the given device | type. | | ———– | @note | | the actual data allocation is not going | to be carried out until you resize the | tensor and then call mutable_data(). |

source§

impl Into<bool> for Tensor

source§

fn into(self) -> bool

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tensor

§

impl !Send for Tensor

§

impl !Sync for Tensor

§

impl Unpin for Tensor

§

impl !UnwindSafe for Tensor

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V