[][src]Struct tensor_compute::TensorView

pub struct TensorView<'a> { /* fields omitted */ }

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]

pub fn compare(&self, other: &Self) -> bool[src]

pub fn shape(&self) -> &VecDeque<usize>[src]

Same as Tensor::shape

pub fn strides(&self) -> &VecDeque<usize>[src]

pub async fn to_cpu_async<'_>(&'_ self) -> CpuTensor[src]

pub fn to_cpu(&self) -> CpuTensor[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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