Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor<T, A: Backend = CpuBackend> {
    pub storage: Buffer<T, A>,
    pub dimensions: Dimensions,
}

Fields§

§storage: Buffer<T, A>§dimensions: Dimensions

Implementations§

Source§

impl<T, A: Backend> Tensor<T, A>

Source

pub fn with_sizes_in(sizes: impl AsRef<[usize]>, allocator: A) -> Self

Source

pub fn zeros_in(sizes: impl AsRef<[usize]>, allocator: A) -> Self

Source

pub fn zeros_in_with_total_capacity( sizes: impl AsRef<[usize]>, allocator: A, ) -> Self

Source

pub fn try_with_sizes_in( sizes: impl AsRef<[usize]>, allocator: A, ) -> Result<Self, TryReserveError>

Source

pub fn reshape_in_place(&mut self, sizes: impl AsRef<[usize]>)

Source

pub fn reshape(self, sizes: impl AsRef<[usize]>) -> Self

Source

pub unsafe fn reshape_unchecked(self, dimensions: Dimensions)

§Safety

The caller must ensure that the new dimensions are compatible with the existing dimensions.

Source

pub fn flatten_in_place(&mut self)

Source

pub fn flatten(self) -> Self

Source

pub fn into_buffer(self) -> Buffer<T, A>

Source

pub fn as_buffer(&self) -> &Buffer<T, A>

Source

pub fn as_mut_buffer(&mut self) -> &mut Buffer<T, A>

Source

pub fn backend(&self) -> &A

Source

pub fn shape(&self) -> &Dimensions

Source

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

Returns the dimensions of the tensor.

Source

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

Source

pub fn as_ptr(&self) -> *const T

Source

pub unsafe fn owned_unchecked(&self) -> ManuallyDrop<Self>

§Safety

This function is unsafe because it enables bypassing the lifetime of the tensor.

Source

pub unsafe fn owned_unchecked_in( &self, storage_allocator: A, ) -> ManuallyDrop<Self>

§Safety

This function is unsafe because it enables bypassing the lifetime of the tensor.

Source

pub fn total_len(&self) -> usize

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Source

pub fn as_view(&self) -> TensorView<'_, T, A>

Source

pub fn as_view_mut(&mut self) -> TensorViewMut<'_, T, A>

Source

pub fn get(&self, index: usize) -> Option<TensorView<'_, T, A>>

Source

pub fn get_mut(&mut self, index: usize) -> Option<TensorViewMut<'_, T, A>>

Source

pub fn split(&self) -> impl Iterator<Item = TensorView<'_, T, A>>

Source

pub fn split_mut(&mut self) -> impl Iterator<Item = TensorViewMut<'_, T, A>>

Source

pub unsafe fn assume_init(&mut self)

Source

pub fn flatten_to_base<F: Field>(self) -> Tensor<F, A>
where T: ExtensionField<F>,

Source

pub fn into_extension<ET: ExtensionField<T>>(self) -> Tensor<ET, A>
where T: Field,

Source§

impl<T> Tensor<T, CpuBackend>

Source

pub fn rand<R: Rng>(rng: &mut R, sizes: impl AsRef<[usize]>) -> Self

Source

pub fn with_sizes(sizes: impl AsRef<[usize]>) -> Self

Source

pub fn as_slice(&self) -> &[T]

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Source§

impl<T: Field> Tensor<T, CpuBackend>

Source

pub fn sum(&self, dim: usize) -> Tensor<T, CpuBackend>

Computes the sum of the tensor along a dimension.

Source§

impl<T, A: TransposeBackend<T>> Tensor<T, A>

Source

pub fn transpose(&self) -> Tensor<T, A>

Returns a new tensor with the last two dimensions transposed.

This function panics if the input tensor is not a 2D tensor.

Trait Implementations§

Source§

impl<T: Clone, A: Clone + Backend> Clone for Tensor<T, A>

Source§

fn clone(&self) -> Tensor<T, A>

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<T: Debug, A: Debug + Backend> Debug for Tensor<T, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Tensor<T, CpuBackend>

Source§

fn default() -> Self

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

impl<'de, T: Deserialize<'de>> Deserialize<'de> for Tensor<T>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, T, A: Backend> From<&'a Tensor<T, A>> for TensorView<'a, T, A>

Source§

fn from(tensor: &'a Tensor<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, A: Backend> From<&'a mut Tensor<T, A>> for TensorViewMut<'a, T, A>

Source§

fn from(tensor: &'a mut Tensor<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T, A: Backend> From<Buffer<T, A>> for Tensor<T, A>

Source§

fn from(buffer: Buffer<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Send + Sync> From<DenseMatrix<T>> for Tensor<T, CpuBackend>

Source§

fn from(value: RowMajorMatrix<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Tensor<T, CpuBackend>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Tensor<T, CpuBackend>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, A: Backend> HasBackend for Tensor<T, A>

Source§

type Backend = A

Source§

fn backend(&self) -> &Self::Backend

Source§

impl<T, A: Backend, I: AsRef<[usize]>> Index<I> for Tensor<T, A>

Source§

type Output = Init<T, A>

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, A: Backend, I: AsRef<[usize]>> IndexMut<I> for Tensor<T, A>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, A: Backend> PartialEq for Tensor<T, A>
where Buffer<T, A>: PartialEq,

Source§

fn eq(&self, __other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Serialize> Serialize for Tensor<T>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Clone + Send + Sync> TryFrom<Tensor<T>> for RowMajorMatrix<T>

Source§

type Error = DimensionsError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Tensor<T, CpuBackend>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T, A: Backend> Eq for Tensor<T, A>
where Buffer<T, A>: Eq,

Auto Trait Implementations§

§

impl<T, A> Freeze for Tensor<T, A>
where A: Freeze,

§

impl<T, A> RefUnwindSafe for Tensor<T, A>

§

impl<T, A> Send for Tensor<T, A>

§

impl<T, A> Sync for Tensor<T, A>

§

impl<T, A> Unpin for Tensor<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnsafeUnpin for Tensor<T, A>
where A: UnsafeUnpin,

§

impl<T, A> UnwindSafe for Tensor<T, A>
where A: UnwindSafe, T: 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, A> CopyIntoBackend<A, A> for T
where A: Backend, T: HasBackend<Backend = A> + Send + Sync,

Source§

type Output = T

Source§

fn copy_into_backend( self, _backend: &A, ) -> Result<<T as CopyIntoBackend<A, A>>::Output, CopyError>

Source§

impl<T, A> CopyToBackend<A, A> for T
where T: HasBackend<Backend = A> + Clone + Sync, A: Backend,

Source§

type Output = T

Source§

fn copy_to_backend( &self, _backend: &A, ) -> Result<<T as CopyToBackend<A, A>>::Output, CopyError>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, Dst> IntoGlobal<Dst> for T
where Dst: GlobalBackend, T: HasBackend, <T as HasBackend>::Backend: CanCopyInto<T, Dst>,

Source§

impl<T> IntoHost for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, Dst> ToGlobal<Dst> for T
where Dst: GlobalBackend, T: HasBackend, <T as HasBackend>::Backend: CanCopyIntoRef<T, Dst>,

Source§

type Output = <<T as HasBackend>::Backend as CanCopyIntoRef<T, Dst>>::Output

Source§

fn to_global(&self) -> Result<<T as ToGlobal<Dst>>::Output, CopyError>

Source§

impl<T> ToHost for T
where T: ToGlobal<CpuBackend>,

Source§

fn to_host(&self) -> Result<Self::Output, CopyError>

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,