Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created July 6, 2022 21:11
Show Gist options
  • Save Steboss89/91d038379f30727f41640f9f16133918 to your computer and use it in GitHub Desktop.
Save Steboss89/91d038379f30727f41640f9f16133918 to your computer and use it in GitHub Desktop.
Constant method to initialize weights and biases
Init::Const(cst) => {
// Optimize the case for which a single C++ code can be done.
if cst == 0. {
Tensor::f_zeros(dims, (Kind::Float, device))
} else if (cst - 1.).abs() <= std::f64::EPSILON {
Tensor::f_ones(dims, (Kind::Float, device))
} else {
Tensor::f_ones(dims, (Kind::Float, device)).map(|t| t * cst)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment