pub struct TensorBuilder<'a> { /* private fields */ }
Expand description
Builder for initializing a new tensor.
Implementations§
Source§impl<'a> TensorBuilder<'a>
impl<'a> TensorBuilder<'a>
pub const fn new(initializer: &'a Initializer, shape: &'a [usize]) -> Self
Sourcepub const fn gain(self, gain: f64) -> Self
pub const fn gain(self, gain: f64) -> Self
Set the gain (scaling factor) on the initialized values.
Can be used to compensate for the scaling effect of activation functions.
See PyTorch’s calculate_gain
function for more information.
Sourcepub const fn fan_in(self, fan_in: usize) -> Self
pub const fn fan_in(self, fan_in: usize) -> Self
Override the fan_in
value (number of input features) calculated from shape
.
This can be useful when multiple tensors are initialized separately but act together in
a layer to implement a mapping from a collectively larger number of input features.
For example, a weights tensor and a bias tensors might be initialized with a fan_in
value
of weights_input_dim + 1
.
Sourcepub const fn fan_out(self, fan_out: usize) -> Self
pub const fn fan_out(self, fan_out: usize) -> Self
Override the fan_out
value (number of output features) calculated from shape
.
This can be useful when multiple tensors are initialized separately but their outputs features are concatenated together in a layer.
Sourcepub const fn requires_grad(self, requires_grad: bool) -> Self
pub const fn requires_grad(self, requires_grad: bool) -> Self
Set whether the tensor requires gradient tracking. Defaults to true.
Trait Implementations§
Source§impl<'a> Clone for TensorBuilder<'a>
impl<'a> Clone for TensorBuilder<'a>
Source§fn clone(&self) -> TensorBuilder<'a>
fn clone(&self) -> TensorBuilder<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Debug for TensorBuilder<'a>
impl<'a> Debug for TensorBuilder<'a>
Source§impl<'a> PartialEq for TensorBuilder<'a>
impl<'a> PartialEq for TensorBuilder<'a>
impl<'a> Copy for TensorBuilder<'a>
impl<'a> StructuralPartialEq for TensorBuilder<'a>
Auto Trait Implementations§
impl<'a> Freeze for TensorBuilder<'a>
impl<'a> RefUnwindSafe for TensorBuilder<'a>
impl<'a> Send for TensorBuilder<'a>
impl<'a> Sync for TensorBuilder<'a>
impl<'a> Unpin for TensorBuilder<'a>
impl<'a> UnwindSafe for TensorBuilder<'a>
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 more