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
impl Tensor
pub fn get_intrusive_ptr(&self) -> &IntrusivePtr<TensorImpl>
pub unsafe fn new(other: &Tensor) -> Self
pub fn resize<Ts>(&self, dim_source: Ts)
pub fn resize_with_dim_vec<T>(&self, dim_source: &Vec<T>)
pub fn unsafe_get_tensor_impl(&self) -> *mut TensorImpl
sourcepub fn new_with_dimension_and_type(dims: &[i32], ty: DeviceType) -> Self
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. |
sourcepub fn new_with_dimension_and_device(dims: &[i32], device: Device) -> Self
pub fn new_with_dimension_and_device(dims: &[i32], device: Device) -> Self
we want to preserve index information
sourcepub fn new_with_dimension_vec_and_type(dims: &Vec<i32>, ty: DeviceType) -> Self
pub fn new_with_dimension_vec_and_type(dims: &Vec<i32>, ty: DeviceType) -> Self
TODO: remove?
sourcepub fn new_with_type_from_src(src: &Tensor, ty: DeviceType) -> Self
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
impl Tensor
pub fn is_same(&self, other: &Tensor) -> bool
pub fn clone(&self) -> Tensor
sourcepub fn alias(&self) -> Tensor
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)
|
pub fn get_device_type(&self) -> DeviceType
pub fn get_device(&self) -> Device
sourcepub fn extend_to(&self, num: i64, growth_pct: f32)
pub fn extend_to(&self, num: i64, growth_pct: f32)
| ———–
| @brief
|
| Extend the outer-most dimension of
| this tensor to dimension of num
.
|
pub fn extend(&self, num: i64, growth_pct: f32)
sourcepub fn shrink_to(&self, outer_dim: i64)
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. |
pub fn reserve_space<T>(&self, outer_dim: &T)
sourcepub fn resize_like(&self, src_tensor: &Tensor)
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. |
pub fn reshape<T: PrimInt>(&self, dims: &Vec<T>)
pub fn free_memory(&self)
sourcepub fn debug_string(&self) -> String
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. |
To be deprecated
| @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. |
pub fn defined(&self) -> bool
sourcepub fn raw_data(&self)
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. |
pub fn data<T>(&self) -> *mut T
pub fn raw_mutable_data_with_type_meta(&self, meta: TypeMeta)
sourcepub fn raw_mutable_data(&self)
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
pub fn mutable_data<T>(&self) -> *mut T
sourcepub fn ndim(&self) -> i32
pub fn ndim(&self) -> i32
| (To be deprecated) Returns the number | of dimensions of the data. |
sourcepub fn size(&self) -> i64
pub fn size(&self) -> i64
| (To be deprecated) Returns the size | (i.e. the number of items) of the tensor. |
sourcepub fn itemsize(&self) -> usize
pub fn itemsize(&self) -> usize
| Return the number of bytes each item | takes in the tensor. |
sourcepub fn nbytes(&self) -> usize
pub fn nbytes(&self) -> usize
| Returns the total number of bytes of | the storage. | | This is equivalent to calling size() | * itemsize(). |
pub fn sizes(&self) -> &[i32]
pub fn size_from_dim(&self, k: i32) -> i64
pub fn size_to_dim(&self, k: i32) -> i64
pub fn size_between_dim(&self, k: i32, l: i32) -> i64
sourcepub fn canonical_axis_index(&self, axis_index: i32) -> i32
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.
pub fn stride(&self, dim: i64) -> i64
pub fn strides(&self) -> &[i32]
pub fn is_contiguous(&self, memory_format: Option<MemoryFormat>) -> bool
sourcepub fn dtype(&self) -> TypeMeta
pub fn dtype(&self) -> TypeMeta
| Returns the TypeMeta object associated | with the current data type. |
sourcepub fn meta(&self) -> TypeMeta
pub fn meta(&self) -> TypeMeta
| (To be deprecated) Returns the TypeMeta | object associated with the current | data type. |
sourcepub fn dim32(&self, i: i32) -> i32
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. |
pub fn size_from_index(&self, i: i32) -> i64
pub fn dim_from_index(&self, i: i32) -> i64
pub fn mut_storage<'a>(&'a mut self) -> &'a mut Storage
pub fn storage<'a>(&'a self) -> &'a Storage
pub fn storage_initialized(&self) -> bool
pub fn dtype_initialized(&self) -> bool
sourcepub fn reinitialize_tensor(
&mut self,
tensor: *mut Tensor,
dims: &[i32],
options: TensorOptions
)
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 |
pub fn reinitialize_and_copy_from( &mut self, t: *mut Tensor, options: TensorOptions, src: &Tensor, async_: bool )
pub fn enforce_invariants(&mut self)
sourcepub fn copy_from(&mut self, src: &Tensor, async_: Option<bool>)
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 From<DeviceType> for Tensor
impl From<DeviceType> for Tensor
source§fn from(device: DeviceType) -> Self
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(). |
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§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.