Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created July 7, 2022 15:29
Show Gist options
  • Save Steboss89/c691f1d856454d3d90d510cc5d547d68 to your computer and use it in GitHub Desktop.
Save Steboss89/c691f1d856454d3d90d510cc5d547d68 to your computer and use it in GitHub Desktop.
Initialisation, match case
match i {
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