pub enum Value<B: Backend> {
Show 26 variants
B1(Tensor<B, 1, Bool>),
B2(Tensor<B, 2, Bool>),
B3(Tensor<B, 3, Bool>),
B4(Tensor<B, 4, Bool>),
B5(Tensor<B, 5, Bool>),
B6(Tensor<B, 6, Bool>),
B7(Tensor<B, 7, Bool>),
B8(Tensor<B, 8, Bool>),
F1(Tensor<B, 1, Float>),
F2(Tensor<B, 2, Float>),
F3(Tensor<B, 3, Float>),
F4(Tensor<B, 4, Float>),
F5(Tensor<B, 5, Float>),
F6(Tensor<B, 6, Float>),
F7(Tensor<B, 7, Float>),
F8(Tensor<B, 8, Float>),
I1(Tensor<B, 1, Int>),
I2(Tensor<B, 2, Int>),
I3(Tensor<B, 3, Int>),
I4(Tensor<B, 4, Int>),
I5(Tensor<B, 5, Int>),
I6(Tensor<B, 6, Int>),
I7(Tensor<B, 7, Int>),
I8(Tensor<B, 8, Int>),
Incompatible(String),
Multi(Vec<Self>),
}Expand description
enumerates burn tensors up to 8 dimensions, along with a variant to represent operation compatibility errors, and a variant for multiple tensors. An empty multi variant can be used to represent a lack of data. Once a the depth of a multi variant is enough for an operation to take full effect, further nesting should result in the same as applying separately
Variants§
B1(Tensor<B, 1, Bool>)
B2(Tensor<B, 2, Bool>)
B3(Tensor<B, 3, Bool>)
B4(Tensor<B, 4, Bool>)
B5(Tensor<B, 5, Bool>)
B6(Tensor<B, 6, Bool>)
B7(Tensor<B, 7, Bool>)
B8(Tensor<B, 8, Bool>)
F1(Tensor<B, 1, Float>)
F2(Tensor<B, 2, Float>)
F3(Tensor<B, 3, Float>)
F4(Tensor<B, 4, Float>)
F5(Tensor<B, 5, Float>)
F6(Tensor<B, 6, Float>)
F7(Tensor<B, 7, Float>)
F8(Tensor<B, 8, Float>)
I1(Tensor<B, 1, Int>)
I2(Tensor<B, 2, Int>)
I3(Tensor<B, 3, Int>)
I4(Tensor<B, 4, Int>)
I5(Tensor<B, 5, Int>)
I6(Tensor<B, 6, Int>)
I7(Tensor<B, 7, Int>)
I8(Tensor<B, 8, Int>)
Incompatible(String)
Multi(Vec<Self>)
Implementations§
Source§impl<B: Backend> Value<B>
impl<B: Backend> Value<B>
Sourcepub fn flatten_values(self) -> Self
pub fn flatten_values(self) -> Self
flattens depth first into a list of tensors
Sourcepub fn from_values<I: IntoIterator<Item = Self>, S: Into<Shape>>(
inner: I,
shape: S,
) -> Self
pub fn from_values<I: IntoIterator<Item = Self>, S: Into<Shape>>( inner: I, shape: S, ) -> Self
creates a value from the inner values and recursive shape. Doesn’t check actual dimension values, the shape is just used for recursion data
Sourcepub fn into_float_vec(self) -> Vec<f32>
pub fn into_float_vec(self) -> Vec<f32>
converts to a flattened vector of floats, ignoring incompatibility errors
Sourcepub fn into_int_vec(self) -> Vec<i32>
pub fn into_int_vec(self) -> Vec<i32>
converts to a flattened vector of ints, ignoring incompatibility errors
Sourcepub fn height(&self) -> usize
pub fn height(&self) -> usize
returns the maximum recursive depth of the value tree (its height). Returns 0 for empty or single
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
tests if the tensor is empty. incompatible isn’t considered empty for the purposes of this function
Sourcepub fn is_incompatible(&self) -> bool
pub fn is_incompatible(&self) -> bool
tests if the tensor represents the result of an incompatible input and operation
Sourcepub fn into_multi(self) -> Vec<Value<B>>
pub fn into_multi(self) -> Vec<Value<B>>
converts to a multiple tensor, then unwraps to a vec of values
Sourcepub fn is_multi(&self) -> bool
pub fn is_multi(&self) -> bool
tests if this is a multiple tensor. also returns true for empty and multi that only have one value
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
returns a shallow count the number of values directly within this one. 1 if not multi, otherwise the len of the vec inside.
Sourcepub fn len_recursive(&self) -> usize
pub fn len_recursive(&self) -> usize
recursively counts the number of tensors within this value, including multi tensors within multi tensors
Sourcepub fn map_multi<F: FnMut(Value<B>) -> Value<B>>(
self,
depth: usize,
f: F,
) -> Self
pub fn map_multi<F: FnMut(Value<B>) -> Value<B>>( self, depth: usize, f: F, ) -> Self
applies a function to each multi tensor value whose maximum distance to a leaf is depth. The depth for empty or single is 0, multi containing only empty or single is 1, etc
Sourcepub fn map_values<F: FnMut(Value<B>) -> Value<B>>(self, f: F) -> Self
pub fn map_values<F: FnMut(Value<B>) -> Value<B>>(self, f: F) -> Self
applies a function to each single tensor value
Sourcepub fn new<S: Into<Shape>>(data: &[f32], device: &B::Device, shape: S) -> Self
pub fn new<S: Into<Shape>>(data: &[f32], device: &B::Device, shape: S) -> Self
creates a new multi tensor from the data and shape // TODO make work for bool and int too
Sourcepub fn promote(self, rhs: Value<B>) -> (Value<B>, Value<B>)
pub fn promote(self, rhs: Value<B>) -> (Value<B>, Value<B>)
promotes the values to make them compatible if possible. bools can become floats or ints, ints can become floats, any can become multi, and lower ranks can be unsqueezed to higher ranks. This is a shallow operation, so tensors inside multi will be unaffected. incompatible with non multi will return the input
Sourcepub fn promote_kind(self, rhs: Value<B>) -> (Value<B>, Value<B>)
pub fn promote_kind(self, rhs: Value<B>) -> (Value<B>, Value<B>)
promotes the values to make them match if possible. bools can become floats or ints, ints can become floats, any can become multi. This is a shallow operation, so tensors inside multi will be unaffected. incompatible with non multi will return the input
Sourcepub fn promote_rank(self, rhs: Value<B>) -> (Value<B>, Value<B>)
pub fn promote_rank(self, rhs: Value<B>) -> (Value<B>, Value<B>)
promotes the values to make them match if possible. lower ranks can be unsqueezed to higher ranks. This is a shallow operation, so tensors inside multi will be unaffected. incompatible with non multi will return the input
Sourcepub fn rank(&self) -> Option<usize>
pub fn rank(&self) -> Option<usize>
returns the number of axes of the tensor, or none if incompatible or multi
Sourcepub fn shape(&self) -> Shape
pub fn shape(&self) -> Shape
gets the shape of the tensor. Use the recursive version to recursively get the multi shape
Sourcepub fn shape_recursive(&self) -> Shape
pub fn shape_recursive(&self) -> Shape
gets the shape of the tensor. Use the non recusive function if deep shape structure of multi is not required
Sourcepub fn shift(self, d: i32, n: i32, v: f32) -> Self
pub fn shift(self, d: i32, n: i32, v: f32) -> Self
shifts the components right n places, maintaining the current dimensions, filling the left spot with v cast to the appropriate type
Sourcepub fn slice<A: AsRef<[R]>, R: RangeBounds<usize>>(self, ranges: A) -> Self
pub fn slice<A: AsRef<[R]>, R: RangeBounds<usize>>(self, ranges: A) -> Self
returns a value containing the elements selected from the given ranges. If this is a multi tensor the slice will be applied to each sub tensor
Sourcepub fn split<I: Into<Option<i32>>>(self, chunksize: usize, dim: I) -> Self
pub fn split<I: Into<Option<i32>>>(self, chunksize: usize, dim: I) -> Self
splits into chunks along the dimension, or the multi vector if dim is None
Sourcepub fn squeeze_dim(self, d: i32) -> Self
pub fn squeeze_dim(self, d: i32) -> Self
removes a dimension of size 1 at position d. incompatible if dimension at position d is not 1
Sourcepub fn try_incompatible(self) -> Result<String, Self>
pub fn try_incompatible(self) -> Result<String, Self>
attempts to unwrap the inner incompatible value
Sourcepub fn unsqueeze_dim(self, d: i32) -> Self
pub fn unsqueeze_dim(self, d: i32) -> Self
inserts a dimension of size 1 at position d, or N+d+1 if d is negative
Sourcepub fn unwrap_incompatible(self) -> String
pub fn unwrap_incompatible(self) -> String
attempts to unwrap the inner incompatible value
Sourcepub fn unwrap_multi(self) -> Vec<Value<B>>
pub fn unwrap_multi(self) -> Vec<Value<B>>
attempts to unwrap the inner multi value
Sourcepub fn zeros_like(&self) -> Value<B>
pub fn zeros_like(&self) -> Value<B>
zeros like
Sourcepub fn zip(self) -> Self
pub fn zip(self) -> Self
takes in a multi value and zips the leaves of each inner value together. If this input is empty or single it is returned unchanged. Mistmatch between single and multi substructures will cause the multi to be interpreted as a leaf. Mismatch between multi lengths will cause the shorter to be extended with empty
Trait Implementations§
Source§impl<A: AutodiffBackend> AutodiffModule<A> for Value<A>
impl<A: AutodiffBackend> AutodiffModule<A> for Value<A>
Source§type InnerModule = Value<<A as AutodiffBackend>::InnerBackend>
type InnerModule = Value<<A as AutodiffBackend>::InnerBackend>
Source§fn valid(&self) -> Self::InnerModule
fn valid(&self) -> Self::InnerModule
Source§impl<B: Backend> Decompose for Value<B>
impl<B: Backend> Decompose for Value<B>
Source§type Decomposition = Value<B>
type Decomposition = Value<B>
Source§fn compose(decomposition: Self::Decomposition) -> Self
fn compose(decomposition: Self::Decomposition) -> Self
Source§fn decompose(self) -> Self::Decomposition
fn decompose(self) -> Self::Decomposition
Source§fn decompose_cloned(&self) -> Self::Decomposition
fn decompose_cloned(&self) -> Self::Decomposition
Source§impl<'a, B: Backend> Deserialize<'a> for Value<B>
impl<'a, B: Backend> Deserialize<'a> for Value<B>
Source§fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> From<Result<Tensor<B, N, K>, String>> for Value<B>
impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> From<Result<Tensor<B, N, K>, String>> for Value<B>
Source§impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> From<Tensor<B, N, K>> for Value<B>
impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> From<Tensor<B, N, K>> for Value<B>
Source§impl<A: Into<Value<B>>, B: Backend> FromIterator<A> for Value<B>
impl<A: Into<Value<B>>, B: Backend> FromIterator<A> for Value<B>
Source§fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self
Source§impl<B: Backend> IntoIterator for Value<B>
impl<B: Backend> IntoIterator for Value<B>
Source§impl<B: Backend> Module<B> for Value<B>
impl<B: Backend> Module<B> for Value<B>
Source§type Record = ConstantRecord
type Record = ConstantRecord
Source§fn collect_devices(
&self,
devices: Vec<<B as Backend>::Device>,
) -> Vec<<B as Backend>::Device>
fn collect_devices( &self, devices: Vec<<B as Backend>::Device>, ) -> Vec<<B as Backend>::Device>
Source§fn devices(&self) -> Vec<<B as Backend>::Device>
fn devices(&self) -> Vec<<B as Backend>::Device>
Source§fn fork(self, device: &<B as Backend>::Device) -> Self
fn fork(self, device: &<B as Backend>::Device) -> Self
Source§fn into_record(self) -> Self::Record
fn into_record(self) -> Self::Record
Source§fn load_file<F: FileRecorder<B>, P: Into<PathBuf>>(
self,
_filepath: P,
_recorder: &F,
_device: &<B as Backend>::Device,
) -> Result<Self, RecorderError>
fn load_file<F: FileRecorder<B>, P: Into<PathBuf>>( self, _filepath: P, _recorder: &F, _device: &<B as Backend>::Device, ) -> Result<Self, RecorderError>
Source§fn load_record(self, _record: Self::Record) -> Self
fn load_record(self, _record: Self::Record) -> Self
Source§fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§fn save_file<F: FileRecorder<B>, P: Into<PathBuf>>(
self,
_filepath: P,
_recorder: &F,
) -> Result<(), RecorderError>
fn save_file<F: FileRecorder<B>, P: Into<PathBuf>>( self, _filepath: P, _recorder: &F, ) -> Result<(), RecorderError>
Source§fn to_device(self, device: &<B as Backend>::Device) -> Self
fn to_device(self, device: &<B as Backend>::Device) -> Self
Source§fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
Source§impl<B: Backend> ModuleDisplay for Value<B>
impl<B: Backend> ModuleDisplay for Value<B>
Source§fn custom_content(&self, _content: Content) -> Option<Content>
fn custom_content(&self, _content: Content) -> Option<Content>
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Source§impl<B: Backend> ModuleDisplayDefault for Value<B>
impl<B: Backend> ModuleDisplayDefault for Value<B>
Source§impl<B: Backend> Stack for Value<B>
impl<B: Backend> Stack for Value<B>
Source§impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> TryFrom<Value<B>> for Tensor<B, N, K>
impl<B: Backend, K: 'static + TensorKind<B>, const N: usize> TryFrom<Value<B>> for Tensor<B, N, K>
Auto Trait Implementations§
impl<B> Freeze for Value<B>where
<B as Backend>::BoolTensorPrimitive: Freeze,
<B as Backend>::IntTensorPrimitive: Freeze,
<B as Backend>::FloatTensorPrimitive: Freeze,
<B as Backend>::QuantizedTensorPrimitive: Freeze,
impl<B> RefUnwindSafe for Value<B>where
<B as Backend>::BoolTensorPrimitive: RefUnwindSafe,
<B as Backend>::IntTensorPrimitive: RefUnwindSafe,
<B as Backend>::FloatTensorPrimitive: RefUnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: RefUnwindSafe,
impl<B> Send for Value<B>
impl<B> Sync for Value<B>
impl<B> Unpin for Value<B>where
<B as Backend>::BoolTensorPrimitive: Unpin,
<B as Backend>::IntTensorPrimitive: Unpin,
<B as Backend>::FloatTensorPrimitive: Unpin,
<B as Backend>::QuantizedTensorPrimitive: Unpin,
impl<B> UnwindSafe for Value<B>where
<B as Backend>::BoolTensorPrimitive: UnwindSafe,
<B as Backend>::IntTensorPrimitive: UnwindSafe,
<B as Backend>::FloatTensorPrimitive: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: UnwindSafe,
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
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more