Struct Tensor

Source
pub struct Tensor<S: Storage, Dim: Dimension> { /* private fields */ }
Expand description

A multidimensional data structure not unlike ndarray::ArrayBase.

Implementations§

Source§

impl<S: Storage> Tensor<S, [usize; 2]>

Source

pub fn dot( &self, rhs: Vector<&ViewOf<S>>, ) -> Vector<DefaultVec<S::T, S::Device>>

Matrix-vector multiplication

Source

pub fn dot_using<C: BLASContext<Device = S::Device>>( &self, rhs: Vector<&ViewOf<S>>, ctx: C, ) -> Vector<DefaultVec<S::T, S::Device>>
where S::Device: DefaultDeviceAllocator, S::T: Zero + One + BLAS<C>,

Matrix-vector multiplication, using the specified BLASContext

Source

pub fn dot_into<C: BLASContext<Device = S::Device>, A: DeviceAllocator<Device = S::Device>>( &self, rhs: Vector<&ViewOf<S>>, ctx: C, alloc: A, ) -> Vector<Vec<S::T, A>>
where S::T: Zero + One + BLAS<C>,

Matrix-vector multiplication, using the provided DeviceAllocator, using the specified BLASContext

Source§

impl<S: Storage> Tensor<S, [usize; 2]>

Source

pub fn matmul( &self, rhs: Matrix<&ViewOf<S>>, ) -> Matrix<DefaultVec<S::T, S::Device>>

Multiply two matricies together.

Source

pub fn matmul_using<C: BLASContext<Device = S::Device>>( &self, rhs: Matrix<&ViewOf<S>>, ctx: C, ) -> Matrix<DefaultVec<S::T, S::Device>>
where S::Device: DefaultDeviceAllocator, S::T: Zero + One + BLAS<C>,

Multiply two matricies together, using the specified BLASContext

Source

pub fn matmul_into<C: BLASContext<Device = S::Device>, A: DeviceAllocator<Device = S::Device>>( &self, rhs: Matrix<&ViewOf<S>>, ctx: C, alloc: A, ) -> Matrix<Vec<S::T, A>>
where S::T: Zero + One + BLAS<C>,

Multiply two matricies together, using the provided DeviceAllocator, using the specified BLASContext

Source§

impl<S: Storage> Tensor<S, [usize; 1]>

Source

pub fn dot(&self, rhs: Vector<&ViewOf<S>>) -> S::T

Vector dot product

Source

pub fn dot_using<C: BLASContext<Device = S::Device>>( &self, rhs: Vector<&ViewOf<S>>, ctx: C, ) -> S::T
where S::T: BLAS1<C>,

Vector dot product, using the specified BLASContext

§Panics

If the vectors do not have the same length

Source§

impl<S: StorageMut> Tensor<S, [usize; 1]>

Source

pub fn scale_using<C: BLASContext<Device = S::Device>>( &mut self, alpha: S::T, ctx: C, )
where S::T: BLAS1<C>,

Vector scaling, using the specified BLASContext

Source§

impl<S: Storage, Dim: Dimension> Tensor<S, Dim>

Source

pub fn from_shape(shape: Dim, data: S) -> Self

Creates a new tensor using the shape and the raw data.

§Panics

The length of the data structure must match the size of the dimensions

Source

pub fn into_inner(self) -> S

Consumes the tensor, returning the underlying data

Source

pub fn reverse_axes(&mut self)

Reverses the axes of the tensor. An inplace transpose

Source

pub fn swap_axes(&mut self, i: usize, j: usize)

Source

pub fn t(&self) -> Tensor<&ViewOf<S>, Dim>

Returns a view of the tensor with the contents transposed. This operation happens without mutating or cloning any data

Source

pub fn into_owned(self) -> Tensor<S::Owned, Dim>
where S: IntoOwned, S::Owned: Storage<T = S::T, Device = S::Device>,

Creates a new owned version of the tensor. Will only clone the contents if needed

Source

pub fn slice_axis( &self, axis: usize, n: usize, ) -> Tensor<&ViewOf<S>, Dim::Smaller>
where Dim: RemoveDim,

Slices the tensor over a specific axis. The resulting tensor will be a dimension smaller

§Panics

If the axis is outside of the length of the dimensions

Source§

impl<'a, T, D: Device, Dim: Dimension> Tensor<&'a mut Ref<[MaybeUninit<T>], D>, Dim>

Source

pub unsafe fn assume_init(self) -> TensorViewMut<'a, T, D, Dim>

§Safety

Contents must be initialised

Source§

impl<'a, T, D: Device, Dim: Dimension> Tensor<&'a Ref<[MaybeUninit<T>], D>, Dim>

Source

pub unsafe fn assume_init(self) -> TensorView<'a, T, D, Dim>

§Safety

Contents must be initialised

Trait Implementations§

Source§

impl<'a, S: StorageMut> AddAssign<Tensor<&'a Ref<[<S as Storage>::T], <S as Storage>::Device>, [usize; 1]>> for Vector<S>

Source§

fn add_assign(&mut self, rhs: Vector<&'a ViewOf<S>>)

Performs the += operation. Read more
Source§

impl<S: Clone + Storage, Dim: Clone + Dimension> Clone for Tensor<S, Dim>

Source§

fn clone(&self) -> Tensor<S, Dim>

Returns a duplicate 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<S: Storage, Dim: Dimension> View for Tensor<S, Dim>

Source§

type Ref<'a> = Tensor<&'a Ref<[<S as Storage>::T], <S as Storage>::Device>, Dim> where Self: 'a

Source§

fn view(&self) -> TensorView<'_, S::T, S::Device, Dim>

Source§

impl<S: StorageMut, Dim: Dimension> ViewMut for Tensor<S, Dim>

Source§

type Mut<'a> = Tensor<&'a mut Ref<[<S as Storage>::T], <S as Storage>::Device>, Dim> where Self: 'a

Source§

fn view_mut(&mut self) -> TensorViewMut<'_, S::T, S::Device, Dim>

Source§

impl<S: Copy + Storage, Dim: Copy + Dimension> Copy for Tensor<S, Dim>

Auto Trait Implementations§

§

impl<S, Dim> Freeze for Tensor<S, Dim>
where Dim: Freeze, S: Freeze,

§

impl<S, Dim> RefUnwindSafe for Tensor<S, Dim>

§

impl<S, Dim> Send for Tensor<S, Dim>
where Dim: Send, S: Send,

§

impl<S, Dim> Sync for Tensor<S, Dim>
where Dim: Sync, S: Sync,

§

impl<S, Dim> Unpin for Tensor<S, Dim>
where Dim: Unpin, S: Unpin,

§

impl<S, Dim> UnwindSafe for Tensor<S, Dim>
where Dim: UnwindSafe, S: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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 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.