Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Imports: Rcpp (>= 0.11.0), stats, utils
Suggests: Matrix, inline, tinytest, pkgKitten, microbenchmark
URL: https://github.com/RcppCore/RcppEigen, https://dirk.eddelbuettel.com/code/rcpp.eigen.html
BugReports: https://github.com/RcppCore/RcppEigen/issues
RoxygenNote: 6.0.1
10 changes: 7 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
useDynLib("RcppEigen", .registration=TRUE)

importFrom("Rcpp", "evalCpp")
importFrom("utils", "packageDescription", "package.skeleton")
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt")
importFrom("utils", "packageDescription", "package.skeleton", "packageVersion")
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt", "na.omit")
export("fastLm",
"fastLmPure",
"RcppEigen.package.skeleton"
"RcppEigen.package.skeleton",
"EigenNbThreads",
"EigenSetNbThreads",
"RcppEigen_throttle_cores",
"RcppEigen_reset_cores"
)

S3method("fastLm", "default")
Expand Down
10 changes: 10 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ eigen_version <- function(single) {
.Call(`_RcppEigen_eigen_version`, single)
}

eigen_version_typed <- function() {
.Call(`_RcppEigen_eigen_version_typed`)
}

Eigen_SSE <- function() {
.Call(`_RcppEigen_Eigen_SSE`)
}

#' @rdname RcppEigen_throttle_cores
EigenNbThreads <- function() {
.Call(`_RcppEigen_EigenNbThreads`)
}

#' @rdname RcppEigen_throttle_cores
EigenSetNbThreads <- function(n) {
invisible(.Call(`_RcppEigen_EigenSetNbThreads`, n))
}

fastLm_Impl <- function(X, y, type) {
.Call(`_RcppEigen_fastLm_Impl`, X, y, type)
}
Expand Down
61 changes: 61 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## init.R: Startup
##
## Copyright (C) 2025 Dirk Eddelbuettel
##
## This file is part of RcppEigen.
##
## RcppEigen is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
##
## RcppEigen is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with RcppEigen. If not, see <http://www.gnu.org/licenses/>.

.pkgenv <- new.env(parent=emptyenv())

.onLoad <- function(libname, pkgname) {
## simple fallback: 'Ncpus' (if set) or else all cpus seen by OpenMP
ncores <- getOption("Ncpus", EigenNbThreads())
## consider OMP_THREAD_LIMIT (cf Writing R Extensions), gets NA if envvar unset
ompcores <- as.integer(Sys.getenv("OMP_THREAD_LIMIT"))
## keep the smaller value, omitting NA
ncores <- min(na.omit(c(ncores, ompcores)))
.pkgenv[["nb_threads"]] <- ncores # #nocov
RcppEigen_throttle_cores(ncores)
}

.onAttach <- function(libname, pkgname) {
if (interactive()) {
packageStartupMessage("RcppEigen ", packageVersion("RcppEigen"),
" using ", .pkgenv[["nb_threads"]], " cores. See ",
"'help(\"RcppEigen-package\")' for details.")
}
}

##' Throttle (or Reset) (Rcpp)Eigen Core Usage
##'
##' Helper functions to throttle use of cores by RcppEigen-internal code.
##' On package load, the initial value is saved and used to reset the value.
##' @param n Integer value of desired cores, default is the value set at package
##' startup reflecting the smallest value among the total number of available
##' cores (or one if compiled without OpenMP support), the value of option
##' \code{Ncpus} and the value of environment variable \code{OMP_THREAD_LIMIT}.
##' @return Only \code{EigenNbThreads()} returns a value, the current value of
##' the number of cores used. The other functions are invoked for their side
##' effect of affecting the count of cores used.
##' @seealso \code{\link{RcppEigen-package}}
RcppEigen_throttle_cores <- function(n) {
if (missing(n)) n <- .pkgenv[["nb_threads"]]
EigenSetNbThreads(n)
}

##' @rdname RcppEigen_throttle_cores
RcppEigen_reset_cores <- function() {
EigenSetNbThreads(.pkgenv[["nb_threads"]])
}
3 changes: 2 additions & 1 deletion cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ rm -f src/*.o src/*.so \
inst/doc/RcppEigen-unitTests.out \
inst/doc/RcppEigen-unitTests.aux \
inst/doc/RcppEigen-unitTests.log \
*/*~ *~
*/*~ *~ \
config.log config.status src/Makevars
rm -rf autom4te.cache
Loading