R/RcppExports.R

Defines functions runifC duplicatedInt adjPairsMatrix adjPairsWithId

Documented in adjPairsMatrix adjPairsWithId duplicatedInt runifC

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Adjacent-pairs with id, used by spread2 hot loop
#'
#' Computes 4- or 8-direction neighbour pairs (from, to, id) for every cell
#' and filters out neighbours that fall off the raster top/bottom or wrap
#' across left/right edges. Rows are emitted in the same direction-major
#' order that adj() produces (topl, top, topr, lef, rig, botl, bot, botr for
#' directions == 8) so that downstream seeded operations (e.g. R-side
#' sample.int shuffle) consume RNG state and produce identical output to
#' the original spread2 implementation. This replaces only the adj()
#' call inside the spread2 main loop; the row-randomization step still
#' happens in R afterwards.
#'
#' @param cells integer vector of source cell indices (1-based)
#' @param id integer vector of the same length as cells; the event id for each cell
#' @param numCol integer; number of raster columns
#' @param numCell integer; total number of raster cells
#' @param directions integer; either 4 or 8
#'
#' @return A list with three integer vectors `from`, `to`, `id`.
#' @keywords internal
#' @rdname adjPairsWithId
adjPairsWithId <- function(cells, id, numCol, numCell, directions) {
    .Call(`_SpaDES_tools_adjPairsWithId`, cells, id, numCol, numCell, directions)
}

#' Adjacent-pairs matrix used by spread() hot loop
#'
#' Computes 4- or 8-direction neighbour pairs (from, to) for every input cell
#' and filters out neighbours that fall off the raster top/bottom or wrap
#' across left/right edges. Returns a 2-column integer matrix with column
#' names "from" and "to". Equivalent to adj(..., pairs = TRUE) but without
#' the data.table allocation/coercion overhead.
#'
#' @inheritParams adjPairsWithId
#'
#' @return A 2-column integer matrix with columns named `from` and `to`.
#' @keywords internal
#' @rdname adjPairsMatrix
adjPairsMatrix <- function(cells, numCol, numCell, directions) {
    .Call(`_SpaDES_tools_adjPairsMatrix`, cells, numCol, numCell, directions)
}

#' @title
#' Rcpp duplicated on integers using Rcpp Sugar
#' @description
#' `.duplicatedInt` does same as `duplicated` in R, but only on integers, and faster.
#' It uses Rcpp sugar
#'
#' @param x Integer Vector
#' @return
#' A logical vector, as per `duplicated`
#'
#' @rdname duplicated
duplicatedInt <- function(x) {
    .Call(`_SpaDES_tools_duplicatedInt`, x)
}

#' @title
#' Rcpp Sugar version of runif
#' @description
#' Slightly faster than runif, and used a lot
#'
#' @param N Integer Vector
#' @export
#' @return
#' A vector of uniform random numbers as per `runif`
#'
#' @rdname rcpp-extras
runifC <- function(N) {
    .Call(`_SpaDES_tools_runifC`, N)
}

Try the SpaDES.tools package in your browser

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

SpaDES.tools documentation built on Aug. 29, 2026, 1:07 a.m.