R/clamp.R

Defines functions clamp

Documented in clamp

#' Clamps all elements in `x` into the range `[min,max]`
#'
#' same functionality as torch.clamp
#'
#' @param x numeric vector
#' @param min minimum value allowed in the returned vector
#' @param max maximum value allowed in the returned vector
#'
#' @return vector like x in the range `[min,max]`
#' @export
#'
#' @examples
#' clamp(seq(-1,2, by=0.25))
clamp <- function(x, min = 0, max = 1){
	x = pmax(x, min)
	x = pmin(x, max)
	return(x)
}
stackcon/rngt documentation built on June 17, 2022, 5:29 p.m.