R/gelu.R

Defines functions d4GELU d3GELU d2GELU dGELU GELU

Documented in d2GELU d3GELU d4GELU dGELU GELU

#' GELU activation function
#' @param x numeric vector
#' @return numeric vector
#' @family Activation Functions
#' @export
#' @examples
#'
#' GELU(c(-2, -1, 0, 1, 2))
#'
#' \donttest{
#' # you can use rxode2 as well
#' r <- rxode2({
#'   r = GELU(time)
#' })
#' et <- et(c(-2, -1, 0, 1, 2))
#' rxSolve(r, et)
#' }
#'
GELU <- function(x) {
  checkmate::assertNumeric(x, finite=TRUE, any.missing=FALSE)
  .Call(`_rxode2_activationF`, x, 1L)
}


#' Derivatives of GELU
#'
#' @param x numeric vector
#' @return numeric vector
#' @family Activation Functions
#' @export
#' @examples
#' dGELU(c(-2, -1, 0, 1, 2))
#' d2GELU(c(-2, -1, 0, 1, 2))
#' d3GELU(c(-2, -1, 0, 1, 2))
#' d4GELU(c(-2, -1, 0, 1, 2))
#' \donttest{
#' # you can use rxode2 as well
#' r <- rxode2({
#'    r1 <- dGELU(time)
#'    r2 <- d2GELU(time)
#'    r3 <- d3GELU(time)
#'    r4 <- d4GELU(time)
#' })
#' et <- et(c(-2, -1, 0, 1, 2))
#' rxSolve(r, et)
#' }
dGELU <- function(x) {
  checkmate::assertNumeric(x, finite=TRUE, any.missing=FALSE)
  .Call(`_rxode2_activationF`, x, 9L)
}

#' @rdname dGELU
#' @export
d2GELU <- function(x) {
  checkmate::assertNumeric(x, finite=TRUE, any.missing=FALSE)
  .Call(`_rxode2_activationF`, x, 10L)
}

#' @rdname dGELU
#' @export
d3GELU <- function(x) {
  checkmate::assertNumeric(x, finite=TRUE, any.missing=FALSE)
  .Call(`_rxode2_activationF`, x, 11L)
}

#' @rdname dGELU
#' @export
d4GELU <- function(x) {
  checkmate::assertNumeric(x, finite=TRUE, any.missing=FALSE)
  .Call(`_rxode2_activationF`, x, 12L)
}

Try the rxode2 package in your browser

Any scripts or data that you put into this service are public.

rxode2 documentation built on July 28, 2026, 5:08 p.m.