TensorWrapper

Struct TensorWrapper 

Source
pub struct TensorWrapper<'a, B, const D: usize, K = Float>
where B: Backend, K: BasicOps<B>,
{ /* private fields */ }
👎Deprecated since 0.1.0: Use bimm-contracts instead
Expand description

A wrapper around a Tensor that provides additional assertions.

Implementations§

Source§

impl<B, const D: usize, K> TensorWrapper<'_, B, D, K>
where B: Backend, K: BasicOps<B>,

Source

pub fn has_dims(&self, dims: [usize; D]) -> &Self

👎Deprecated since 0.1.0: Use bimm-contracts instead

Assert that the wrapped tensor has the expected dimensions.

§Parameters
  • dims: The expected dimensions of the tensor.
§Panics

Panics if the tensor does not have the expected dimensions.

§Example:
use burn::backend::NdArray;
use burn::tensor::Tensor;
use burn_contracts::assert_tensor;

let device = Default::default();
let tensor = Tensor::<NdArray, 2>::from_data([[2., 3.], [4., 5.]], &device);

assert_tensor(&tensor).has_dims([2, 2]);
Source

pub fn unpacks_shape<const S: usize, C: ShapeBindingSource>( &self, keys: [&str; S], pattern: &str, bindings: C, ) -> Result<[usize; S], ShapePatternError>

👎Deprecated since 0.1.0: Use bimm-contracts instead

Unpacks components of the shape of the tensor according to a pattern.

§Parameters
  • keys: The keys to select from the unpacked shape.
  • pattern: The pattern to unpack the shape.
  • bindings: The bindings to use for the unpacking.
§Returns

The unpacked shape.

§Errors

Returns an error if the pattern is invalid or the bindings are not found, or do not match the shape.

§Example
#[cfg(test)]
mod tests {
   use burn::backend::NdArray;
   use burn::tensor::Tensor;
   use burn_contracts::assert_tensor;

   #[test]
   fn example() -> Result<(), Box<dyn std::error::Error>> {
       let device = Default::default();
       let tensor = Tensor::<NdArray, 6>::zeros([2, 2, 2, 5 * 4, 4 * 4, 3], &device);

       let [b, h, w] = assert_tensor(&tensor).unpacks_shape(
          ["b", "h", "w"],
          "b ... (h p) (w p) c",
          &[("p", 4), ("c", 3)],
       )?;

       assert_eq!(b, 2);
       assert_eq!(h, 5);
       assert_eq!(w, 4);

       Ok(())
   }
}
Source

pub fn has_named_dims(&self, dims: [(&str, usize); D]) -> &Self

👎Deprecated since 0.1.0: Use bimm-contracts instead

Assert that the wrapped tensor has the expected named dimensions.

§Parameters
  • dims: The expected named dimensions of the tensor.
§Panics

Panics if the tensor does not have the expected named dimensions.

§Example:
use burn::backend::NdArray;
use burn::tensor::Tensor;
use burn_contracts::assert_tensor;

let device = Default::default();
let tensor = Tensor::<NdArray, 2>::from_data([[2., 3.], [4., 5.]], &device);

assert_tensor(&tensor).has_named_dims([("rows", 2), ("cols", 2)]);

Trait Implementations§

Source§

impl<'a, B, const D: usize, K> Clone for TensorWrapper<'a, B, D, K>
where B: Backend + Clone, K: BasicOps<B> + Clone,

Source§

fn clone(&self) -> TensorWrapper<'a, B, D, K>

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<'a, B, const D: usize, K> Debug for TensorWrapper<'a, B, D, K>
where B: Backend + Debug, K: BasicOps<B> + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, B, const D: usize, K> Freeze for TensorWrapper<'a, B, D, K>

§

impl<'a, B, const D: usize, K> RefUnwindSafe for TensorWrapper<'a, B, D, K>

§

impl<'a, B, const D: usize, K> Send for TensorWrapper<'a, B, D, K>

§

impl<'a, B, const D: usize, K> Sync for TensorWrapper<'a, B, D, K>

§

impl<'a, B, const D: usize, K> Unpin for TensorWrapper<'a, B, D, K>

§

impl<'a, B, const D: usize, K> UnwindSafe for TensorWrapper<'a, B, D, K>

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