pub struct TensorWrapper<'a, B, const D: usize, K = Float>{ /* 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>
impl<B, const D: usize, K> TensorWrapper<'_, B, D, K>
Sourcepub fn has_dims(&self, dims: [usize; D]) -> &Self
👎Deprecated since 0.1.0: Use bimm-contracts instead
pub fn has_dims(&self, dims: [usize; D]) -> &Self
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]);Sourcepub 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
pub fn unpacks_shape<const S: usize, C: ShapeBindingSource>( &self, keys: [&str; S], pattern: &str, bindings: C, ) -> Result<[usize; S], ShapePatternError>
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(())
}
}Sourcepub fn has_named_dims(&self, dims: [(&str, usize); D]) -> &Self
👎Deprecated since 0.1.0: Use bimm-contracts instead
pub fn has_named_dims(&self, dims: [(&str, usize); D]) -> &Self
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>
impl<'a, B, const D: usize, K> Clone for TensorWrapper<'a, B, D, K>
Source§fn clone(&self) -> TensorWrapper<'a, B, D, K>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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