[−][src]Struct tensor_compute::TensorView
A view into the original Tensor
. A view borrows part of (or even the entirety of) the
original Tensor data. It can NOT modify the data itself. It is normally produced by indexing or
slicing a Tensor.
It can be useful for creating a new Tensor from part of another one:
Examples
use tensor_compute::{Tensor, TensorView, s}; let tensor = Tensor::from_data_and_shape(vec![1., 2., 3., 4.], vec![2, 2]); let first_row: TensorView = tensor.slice(s![1]); assert_eq!(first_row.shape(), &[1, 2]); assert_eq!(first_row.to_cpu().as_contiguous_vec(), &[3., 4.]); let new_tensor = first_row.make_contiguous(); // creates a new owned tensor from the view assert_eq!(new_tensor.shape(), &[1, 2]); assert_eq!(new_tensor.to_cpu().as_contiguous_vec(), &[3., 4.]);
Implementations
impl<'a> TensorView<'a>
[src]
pub async fn make_contiguous_async<'_>(&'_ self) -> Tensor
[src]
Same as TensorView::make_contiguous
, but async.
pub fn make_contiguous(&self) -> Tensor
[src]
Copies the TensorView
into a standalone contiguous Tensor
Examples
use tensor_compute::{Tensor, TensorView, s}; let tensor = Tensor::from_data_and_shape(vec![1., 2., 3., 4., 5., 6., 7., 8.], vec![2, 2, 2]); let first_row: TensorView = tensor.slice(s![1]); assert_eq!(first_row.shape(), &[1, 2, 2]); assert_eq!(first_row.to_cpu().as_contiguous_vec(), &[5., 6., 7., 8.]); let new_tensor = first_row.make_contiguous(); // creates a new owned tensor from the view assert_eq!(new_tensor.shape(), &[1, 2, 2]); assert_eq!(new_tensor.to_cpu().as_contiguous_vec(), &[5., 6., 7., 8.]); assert!(new_tensor.slice(s![..]).compare(&first_row));
pub async fn compare_async<'_, '_>(&'_ self, other: &'_ Self) -> bool
[src]
Same as Tensor::compare_async
pub fn compare(&self, other: &Self) -> bool
[src]
Same as Tensor::compare
pub fn shape(&self) -> &VecDeque<usize>
[src]
Same as Tensor::shape
pub fn strides(&self) -> &VecDeque<usize>
[src]
Same as Tensor::strides
pub async fn to_cpu_async<'_>(&'_ self) -> CpuTensor
[src]
Same as Tensor::to_cpu_async
pub fn to_cpu(&self) -> CpuTensor
[src]
Same as Tensor::to_cpu
Trait Implementations
impl<'a> Debug for TensorView<'a>
[src]
Beware, printing the TensorView forces a copy from GPU memory to CPU memory.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for TensorView<'a>
impl<'a> Send for TensorView<'a>
impl<'a> Sync for TensorView<'a>
impl<'a> Unpin for TensorView<'a>
impl<'a> !UnwindSafe for TensorView<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,