pub struct RefTensor<'a, T> { /* private fields */ }
Expand description
A tensor-like structure that owns no data and holds only slices.
The shape is &'a [usize]
, meaning the shape can never be changed once instantiated.
The data is &'a mut [data]
, allowing for the data to be changed at runtime.
Implementations§
Source§impl<'a, T> RefTensor<'a, T>
impl<'a, T> RefTensor<'a, T>
Sourcepub fn with_data(shape: &'a [usize], data: &'a mut [T]) -> Self
pub fn with_data(shape: &'a [usize], data: &'a mut [T]) -> Self
Constructs a new RefTensor
borrowing mutable data slice with given static shape.
Unlike owned Tensor
types, RefTensor
has no default constructor.
If it did, the constructor would refuse to compile because slices have no statically known size.
§Panics
This constructor panics when the product of each dimension is not equal to the length of all the data.
§Example
use tensor_optim::RefTensor;
const SHAPE: &[usize] = &[2, 3];
let mut data = [0f64; 6];
let mut tensor = RefTensor::with_data(SHAPE, &mut data);
tensor[&[1, 2]] = 42.0;
println!("First element: {}", tensor[&[0, 0]]);
Trait Implementations§
Source§impl<T> AddAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
impl<T> AddAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
Performs the
+=
operation. Read moreSource§impl<T> AddAssign<T> for RefTensor<'_, T>
impl<T> AddAssign<T> for RefTensor<'_, T>
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+=
operation. Read moreSource§impl<T> DivAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
impl<T> DivAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
Source§fn div_assign(&mut self, rhs: &Self)
fn div_assign(&mut self, rhs: &Self)
Performs the
/=
operation. Read moreSource§impl<T> DivAssign<T> for RefTensor<'_, T>
impl<T> DivAssign<T> for RefTensor<'_, T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the
/=
operation. Read moreSource§impl<T> MulAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
impl<T> MulAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
Source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
Performs the
*=
operation. Read moreSource§impl<T> MulAssign<T> for RefTensor<'_, T>
impl<T> MulAssign<T> for RefTensor<'_, T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read moreSource§impl<'a, T: Ord> Ord for RefTensor<'a, T>
impl<'a, T: Ord> Ord for RefTensor<'a, T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'a, T: PartialOrd> PartialOrd for RefTensor<'a, T>
impl<'a, T: PartialOrd> PartialOrd for RefTensor<'a, T>
Source§impl<T> SubAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
impl<T> SubAssign<&RefTensor<'_, T>> for RefTensor<'_, T>
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
Performs the
-=
operation. Read moreSource§impl<T> SubAssign<T> for RefTensor<'_, T>
impl<T> SubAssign<T> for RefTensor<'_, T>
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the
-=
operation. Read moreSource§impl<T> TensorOps<T> for RefTensor<'_, T>
impl<T> TensorOps<T> for RefTensor<'_, T>
impl<'a, T: Eq> Eq for RefTensor<'a, T>
impl<'a, T> StructuralPartialEq for RefTensor<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for RefTensor<'a, T>
impl<'a, T> RefUnwindSafe for RefTensor<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for RefTensor<'a, T>where
T: Send,
impl<'a, T> Sync for RefTensor<'a, T>where
T: Sync,
impl<'a, T> Unpin for RefTensor<'a, T>
impl<'a, T> !UnwindSafe for RefTensor<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more