diff --git a/.github/workflows/cuda_test.yml b/.github/workflows/cuda_test.yml index 1d727b2f1..428fd69d2 100644 --- a/.github/workflows/cuda_test.yml +++ b/.github/workflows/cuda_test.yml @@ -12,4 +12,12 @@ jobs: uses: actions/checkout@v2 - name: Test with pytest run: | - sh ./pytest.sh + #sh ./pytest.sh + echo "BYPASS Python tests" + - name: Test rkeops + run: | + cd rkeops/ci + pwd + ls + export TEST_GPU=1 + bash ./run_ci.sh diff --git a/rkeops/.Rbuildignore b/rkeops/.Rbuildignore index 5a3771d76..a792c7c64 100644 --- a/rkeops/.Rbuildignore +++ b/rkeops/.Rbuildignore @@ -1,7 +1,7 @@ \.gitkeep \.gitignore ^prebuild\.R$ -^recipe\.md$ +^README_dev\.md$ ^benchmarks$ ^ci$ ^dev$ @@ -16,3 +16,4 @@ TODOs.md ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^Rplots\.pdf$ diff --git a/rkeops/DESCRIPTION b/rkeops/DESCRIPTION index 641e62c95..fd8cba7ff 100644 --- a/rkeops/DESCRIPTION +++ b/rkeops/DESCRIPTION @@ -1,7 +1,7 @@ Package: rkeops Title: Kernel Operations on GPU or CPU, with Autodiff, without Memory Overflows -Version: 2.2.3 +Version: 2.3.0 Authors@R: c( person("Ghislain", "Durif", , "gd.dev@libertymail.net", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2567-1401", website = "")), @@ -59,10 +59,10 @@ VignetteBuilder: RdMacros: Rdpack Config/testthat/edition: 3 -Date/Publication: 2024/04/16 +Date/Publication: 2025/07/16 Encoding: UTF-8 OS_type: unix Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 SystemRequirements: Python (>= 3.5.0), C++ compiler (gcc/clang), CUDA (optional but recommended) diff --git a/rkeops/NAMESPACE b/rkeops/NAMESPACE index 72981896c..857f37ea3 100644 --- a/rkeops/NAMESPACE +++ b/rkeops/NAMESPACE @@ -126,6 +126,8 @@ export(clampint) export(clean_rkeops) export(concat) export(cos) +export(def_rkeops_options) +export(default_rkeops_cache_dir) export(elem) export(elemT) export(exp) @@ -135,10 +137,8 @@ export(extractT) export(get_rkeops_cache_dir) export(get_rkeops_options) export(grad) -export(helloWorld) export(ifelse) export(imag2complex) -export(install_rkeops) export(inv) export(is.ComplexLazyParameter) export(is.ComplexLazyTensor) @@ -213,6 +213,7 @@ importFrom(checkmate,assert_subset) importFrom(checkmate,assert_true) importFrom(checkmate,qassert) importFrom(checkmate,qtest) +importFrom(checkmate,test_directory) importFrom(checkmate,test_null) importFrom(data.table,address) importFrom(fs,as_fs_bytes) @@ -228,7 +229,7 @@ importFrom(reticulate,np_array) importFrom(reticulate,py_available) importFrom(reticulate,py_capture_output) importFrom(reticulate,py_config) -importFrom(reticulate,py_install) +importFrom(reticulate,py_require) importFrom(reticulate,source_python) importFrom(stringi,stri_rand_strings) importFrom(stringr,"str_sub<-") @@ -238,6 +239,7 @@ importFrom(stringr,str_count) importFrom(stringr,str_detect) importFrom(stringr,str_extract) importFrom(stringr,str_extract_all) +importFrom(stringr,str_glue) importFrom(stringr,str_length) importFrom(stringr,str_locate_all) importFrom(stringr,str_match) @@ -251,3 +253,4 @@ importFrom(stringr,str_trim) importFrom(tibble,lst) importFrom(utils,head) importFrom(utils,packageVersion) +importFrom(utils,tail) diff --git a/rkeops/R/formula_args.R b/rkeops/R/formula_args.R index c306019c9..5e380587c 100644 --- a/rkeops/R/formula_args.R +++ b/rkeops/R/formula_args.R @@ -7,13 +7,13 @@ #' understood by the C++ code. #' #' @details -#' Mathematical formula: `sum_i e^(lambda*||x_i - y_j||^2)` where `x_i`, `y_j` -#' are 3d vectors, and `lambda` is a scaler parameter. +#' Mathematical formula: `sum_i e^(sigma*||x_i - y_j||^2)` where `x_i`, `y_j` +#' are 3d vectors, and `sigma` is a scaler parameter. #' #' Corresponding KeOps formula and input parameters: #' ``` -#' formula = "Sum_Reduction(Exp(lambda * SqNorm2(x-y)), 0)" -#' args = c("x=Vi(3)", "y=Vj(3)", "lambda=Pm(1)") +#' formula = "Sum_Reduction(Exp(sigma * SqNorm2(x-y)), 0)" +#' args = c("x=Vi(3)", "y=Vj(3)", "sigma=Pm(1)") #' ``` #' #' Input arguments can be of different types: @@ -35,9 +35,9 @@ #' variable or none, if not specify the natural order in the vector `args` is #' used. #' -#' For the formula `"Sum_Reduction(Exp(lambda * SqNorm2(x-y)), 0)"`, both -#' `args = c("x=Vi(3)", "y=Vj(3)", "lambda=Pm(1)")` and -#' `args <- c("x=Vi(0,3)", "y=Vj(1,3)", "beta=Vj(2,3)", "lambda=Pm(3,1)")` are +#' For the formula `"Sum_Reduction(Exp(sigma * SqNorm2(x-y)), 0)"`, both +#' `args = c("x=Vi(3)", "y=Vj(3)", "sigma=Pm(1)")` and +#' `args <- c("x=Vi(0,3)", "y=Vj(1,3)", "beta=Vj(2,3)", "sigma=Pm(3,1)")` are #' equivalent. When specifying the `pos` parameter, the natural order in the #' vector `args` may not correspond to the order of the formula input arguments. #' @@ -65,6 +65,7 @@ #' str_replace_all fixed #' #' @importFrom checkmate assert_character assert_string +#' @noRd parse_args <- function(formula, args) { # check input type @@ -205,6 +206,7 @@ parse_args <- function(formula, args) { #' @return a boolean value indicating if extra args were found in the formula. #' #' @importFrom stringr str_match_all str_replace +#' @noRd parse_extra_args <- function(formula) { ## remove space diff --git a/rkeops/R/install.R b/rkeops/R/install.R deleted file mode 100644 index 8b545b5a4..000000000 --- a/rkeops/R/install.R +++ /dev/null @@ -1,66 +0,0 @@ -#' Install RKeOps requirements -#' -#' @author Ghislain Durif -#' @inheritParams reticulate::py_install -#' -#' @description -#' Install requirements (i.e. Python packages) for RKeOps to work. -#' -#' @details -#' RKeOps now uses PyKeOps Python package under the hood thanks to the -#' [`reticulate`](https://rstudio.github.io/reticulate/) R package that -#' provides an "R Interface to Python". -#' -#' We recommend to use a dedicated Python environment (through `reticulate`) -#' to install and use RKeOps Python dependencies. -#' -#' `install_rkeops()` is just a wrapper around [`reticulate::py_install()`] -#' and takes the same input arguments. -#' -#' See the specific **"Using RKeOps" [article](https://www.kernel-operations.io/rkeops/articles/using_rkeops.html)** -#' or the corresponding vignette: `vignette("using_rkeops", package = "rkeops")` -#' -#' **Important:** Python is a requirement as an intern machinery for the -#' package to work but you will not need to create nor manipulate Python -#' codes to use the RKeOps package. -#' -#' @importFrom reticulate py_install -#' -#' @export -#' -#' @examples -#' \dontrun{ -#' ## setup Python virtual environment -#' # create Python virtualenv -#' reticulate::virtualenv_create("rkeops") -#' # activate python environment -#' reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -#' -#' ## install rkeops requirements in Python virtual environment -#' install_rkeops() -#' -#' ## check install -#' check_rkeops() -#' } -install_rkeops <- function( - envname = NULL, - method = c("auto", "virtualenv", "conda"), - conda = "auto", - python_version = NULL, - pip = FALSE, - ..., - pip_ignore_installed = ignore_installed, - ignore_installed = FALSE) { - - reticulate::py_install( - packages = "pykeops", - envname = envname, - method = method, - conda = conda, - python_version = python_version, - pip = pip, - ..., - pip_ignore_installed = pip_ignore_installed, - ignore_installed = ignore_installed - ) -} \ No newline at end of file diff --git a/rkeops/R/keops_grad.R b/rkeops/R/keops_grad.R index 40e5925f0..39e508b80 100644 --- a/rkeops/R/keops_grad.R +++ b/rkeops/R/keops_grad.R @@ -17,6 +17,7 @@ #' @importFrom tibble lst #' #' @author Ghislain Durif +#' @noRd get_gradient_formula <- function(formula, args, var, args_info) { # check input assert_string(formula) @@ -137,9 +138,14 @@ get_gradient_formula <- function(formula, args, var, args_info) { #' @seealso [rkeops::keops_kernel()] #' #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) #' set_rkeops_options() -#' +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # defining an operator (reduction on squared distance) #' formula <- "Sum_Reduction(SqNorm2(x-y), 0)" #' args <- c("x=Vi(0,3)", "y=Vj(1,3)") @@ -175,6 +181,10 @@ get_gradient_formula <- function(formula, args, var, args_info) { #' # computation #' input <- list(x, y, eta) #' res <- op(input) +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export keops_grad <- function(operator, var) { diff --git a/rkeops/R/keops_kernel.R b/rkeops/R/keops_kernel.R index cc28e767f..9b3aabce2 100644 --- a/rkeops/R/keops_kernel.R +++ b/rkeops/R/keops_kernel.R @@ -72,16 +72,23 @@ #' @seealso [rkeops::keops_grad()] #' #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) #' set_rkeops_options() -#' +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' ## Example 1 #' # Defining a function that computes for each j the sum over i #' # of the scalar products between `x_i` and `y_j` (both 3d vectors), #' # i.e. the sum over the rows of the result of the matrix product `X * t(Y)` #' # where `x_i` and `y_j` are the respective rows of the matrices `X` and `Y`. #' op <- keops_kernel( -#' formula = "Sum_Reduction((x|y), 1)", args = c("x=Vi(3)", "y=Vj(3)")) +#' formula = "Sum_Reduction((x|y), 1)", +#' args = c("x=Vi(3)", "y=Vj(3)") +#' ) #' # data #' nx <- 10 #' ny <- 15 @@ -112,11 +119,12 @@ #' #' ## Example 2 #' # Defining a function that computes the convolution with a Gaussian kernel -#' # i.e. the sum over i of `e^(lambda * ||x_i - y_j||^2) * beta_j` where `x_i`, -#' # `y_j` and `beta_j` are 3d vectors, and `lambda` is a scalar parameter. -#' op = keops_kernel( -#' formula = "Sum_Reduction(Exp(lambda*SqNorm2(x-y))*beta, 1)", -#' args = c("x=Vi(3)", "y=Vj(3)", "beta=Vj(3)", "lambda=Pm(1)")) +#' # i.e. the sum over i of `e^(sigma * ||x_i - y_j||^2) * beta_j` where `x_i`, +#' # `y_j` and `beta_j` are 3d vectors, and `sigma` is a scalar parameter. +#' op <- keops_kernel( +#' formula = "Sum_Reduction(Exp(sigma*SqNorm2(x-y))*beta, 1)", +#' args = c("x=Vi(3)", "y=Vj(3)", "beta=Vj(3)", "sigma=Pm(1)") +#' ) #' #' # data #' nx <- 10 @@ -130,10 +138,14 @@ #' # !! important !! y and beta should have the same dimension #' #' # parameter -#' lambda <- 0.25 +#' sigma <- 0.25 #' #' # compute the result -#' res <- op(list(X, Y, beta, lambda)) +#' res <- op(list(X, Y, beta, sigma)) +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export keops_kernel <- function(formula, args, sum_scheme = "auto") { diff --git a/rkeops/R/keops_setup.R b/rkeops/R/keops_setup.R index d4d239a8b..2cc6f567a 100644 --- a/rkeops/R/keops_setup.R +++ b/rkeops/R/keops_setup.R @@ -25,6 +25,7 @@ #' @importFrom fs dir_create #' @importFrom reticulate py_config #' @importFrom stringr str_c str_length +#' @noRd def_pykeops_build_dir <- function() { # system info @@ -37,7 +38,7 @@ def_pykeops_build_dir <- function() { str_c( "keops_", str_c("R", as.character(getRversion())), - str_c("Python", reticulate::py_config()$version), + str_c("Python", as.character(reticulate::py_config()$version)), str_c("pykeops", pykeops[["__version__"]]), str_c( sys_info$sysname, sys_info$release, @@ -73,10 +74,7 @@ def_pykeops_build_dir <- function() { #' #' @seealso [rkeops::setup_pykeops()] #' -#' @examples -#' \dontrun{ -#' set_pykeops_verbosity() -#' } +#' @noRd set_pykeops_verbosity <- function() { # current verbosity level verbosity <- get_rkeops_options("verbosity") @@ -112,10 +110,7 @@ set_pykeops_verbosity <- function() { #' #' @seealso [rkeops::def_pykeops_build_dir()], [rkeops::setup_pykeops()] #' -#' @examples -#' \dontrun{ -#' set_pykeops_build_dir() -#' } +#' @noRd set_pykeops_build_dir <- function() { # current cache dir cache_dir <- get_rkeops_cache_dir() @@ -154,10 +149,7 @@ set_pykeops_build_dir <- function() { #' #' @seealso [rkeops::set_pykeops_verbosity()], [rkeops::set_pykeops_build_dir()] #' -#' @examples -#' \dontrun{ -#' setup_pykeops() -#' } +#' @noRd setup_pykeops <- function() { set_pykeops_verbosity() set_pykeops_build_dir() diff --git a/rkeops/R/keops_utils.R b/rkeops/R/keops_utils.R index 905ccd9f7..5b66ee16e 100644 --- a/rkeops/R/keops_utils.R +++ b/rkeops/R/keops_utils.R @@ -38,8 +38,10 @@ #' @importFrom checkmate assert_flag assert_string #' @importFrom stringr str_c str_detect str_match str_replace_all str_split #' str_extract_all str_locate_all str_sub str_sub<- +#' @importFrom utils tail #' #' @author Ghislain Durif +#' @noRd get_pykeops_formula <- function( formula, grad = FALSE, var_to_diff = NULL, input_grad = NULL) { @@ -66,14 +68,19 @@ get_pykeops_formula <- function( extract_coma_parenthesis <- unlist(str_extract_all( tmp_form, "[\\(\\)\\,]")) ## cumulative count of parenthesis and commas - count_parenthesis <- cumsum(sapply(extract_coma_parenthesis, function(item) { - return(switch( - item, - "(" = 1, - ")" = -1, - "," = 0 - )) - })) + count_parenthesis <- cumsum(sapply( + extract_coma_parenthesis, + function(item) { + return(switch( + item, + "(" = 1, + ")" = -1, + "," = 0 + )) + } + )) + if(tail(count_parenthesis, 1) != 0) + stop("Non matching parenthesis opening/closing in formula.") ## get position of coma in tmp_form coma_position <- str_locate_all(tmp_form, "\\,")[[1]] coma_position <- as.data.frame(as.matrix(coma_position)) @@ -119,10 +126,10 @@ get_pykeops_formula <- function( reduction_args <- unlist(strsplit(tmp_form, ",")) # number of reduction arguments - nargs <- length(reduction_args) + n_args <- length(reduction_args) # reduction axis - axis <- as.integer(reduction_args[nargs]) + axis <- as.integer(reduction_args[n_args]) # reduction optional arguments opt_arg <- NULL @@ -132,12 +139,12 @@ get_pykeops_formula <- function( weighted_reduction <- TRUE # weighted reduction argument: operand, weight, index # optional reduction arguments - if(nargs > 2) { - opt_arg <- str_replace_all(reduction_args[nargs-1], "\\$", ",") + if(n_args > 2) { + opt_arg <- str_replace_all(reduction_args[n_args-1], "\\$", ",") } } else { # optional reduction arguments - if(nargs > 2) opt_arg <- as.integer(reduction_args[nargs - 1]) + if(n_args > 2) opt_arg <- as.integer(reduction_args[n_args - 1]) } # formula inside reduction diff --git a/rkeops/R/lazytensor_operations.R b/rkeops/R/lazytensor_operations.R index a480b543e..a90d833d3 100644 --- a/rkeops/R/lazytensor_operations.R +++ b/rkeops/R/lazytensor_operations.R @@ -52,7 +52,6 @@ #' @seealso [rkeops::+.default()], [rkeops::+.LazyTensor()], #' [rkeops::+.ComplexLazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' +5 #' 1 + 3 @@ -64,7 +63,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' Sum_xy <- x_i + y_j # symbolic matrix, 150 rows and 3 columns -#' } #' @export "+" <- function(x, y = NULL) { if(!is.null(y) && !is.ComplexLazyTensor(x) && is.LazyTensor(y)) @@ -96,7 +94,6 @@ #' @return An object of class `LazyTensor`. #' @seealso [rkeops::+()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -104,7 +101,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' Sum_xy <- x_i + y_j # symbolic matrix, 150 rows and 3 columns -#' } #' @export "+.LazyTensor" <- function(x, y = NULL) { @@ -199,7 +195,6 @@ #' @seealso [rkeops::-.default()], [rkeops::-.LazyTensor()], #' [rkeops::-.ComplexLazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' +5 #' 1 + 3 @@ -212,7 +207,6 @@ #' # indexed by 'j' #' Sub_xy <- x_i - y_j # symbolic matrix #' Minus_x <- -x_i # symbolic matrix -#' } #' @export "-" <- function(x, y = NULL) { if(!is.null(y) && (!is.ComplexLazyTensor(x) && is.LazyTensor(y))) @@ -248,7 +242,6 @@ #' @return An object of class `LazyTensor`. #' @seealso [rkeops::-()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -257,7 +250,6 @@ #' # indexed by 'j' #' Sub_xy <- x_i - y_j # symbolic matrix #' Minus_x <- -x_i # symbolic matrix -#' } #' @export "-.LazyTensor" <- function(x, y = NULL) { @@ -334,7 +326,6 @@ #' @seealso [rkeops::*.default()], [rkeops::*.LazyTensor()], #' [rkeops::*.ComplexLazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' +5 #' 1 + 3 @@ -346,7 +337,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_times_y <- x_i * y_j # symbolic matrix -#' } #' @export "*" <- function(x, y) { if(!is.ComplexLazyTensor(x) && is.LazyTensor(y)) @@ -373,7 +363,6 @@ #' @return An object of class `LazyTensor`. #' @seealso [rkeops::*()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -381,7 +370,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_times_y <- x_i * y_j # symbolic matrix -#' } #' @export "*.LazyTensor" <- function(x, y) { res <- binaryop.LazyTensor(x, y, "Mult", dim_check_type = "sameor1") @@ -455,7 +443,6 @@ #' @seealso [rkeops::/.default()], [rkeops::/.LazyTensor()], #' [rkeops::/.ComplexLazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' +5 #' 1 + 3 @@ -467,7 +454,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_div_y <- x_i / y_j # symbolic matrix -#' } #' @export "/" <- function(x, y) { if(!is.ComplexLazyTensor(x) && is.LazyTensor(y)) @@ -494,7 +480,6 @@ #' @return An object of class `LazyTensor`. #' @seealso [rkeops::/()] #' @examples -#' \dontrun{ #' # LazyTensor symbolic division #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns @@ -503,7 +488,6 @@ #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_div_y <- x_i / y_j # symbolic matrix -#' } #' @export "/.LazyTensor" <- function(x, y) { res <- binaryop.LazyTensor(x, y, "Divide", dim_check_type = "sameor1") @@ -578,7 +562,6 @@ square.default <- function(x) { #' [rkeops::square.LazyTensor()] #' @seealso [rkeops::square.default()], [rkeops::square.LazyTensor()] #' @examples -#' \dontrun{ #' # Numerical input #' square(4) #' square(1:4) @@ -587,7 +570,6 @@ square.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Square_x <- square(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export square <- function(x) { UseMethod("square", x) @@ -604,12 +586,10 @@ square <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::square()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Square_x <- square(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export square.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Square")) @@ -629,6 +609,7 @@ square.LazyTensor <- function(x) { #' @inherit base::sqrt examples #' @seealso [base::sqrt()] #' @author R core team and contributors +#' @return See 'Details' section. #' @export sqrt.default <- function(x) { return(base::sqrt(x)) @@ -649,7 +630,6 @@ sqrt.default <- function(x) { #' @return See value of [rkeops::sqrt.default()] or [rkeops::sqrt.LazyTensor()]. #' @seealso [rkeops::sqrt.default()], [rkeops::sqrt.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' sqrt(4) #' sqrt(c(1,4,9,16)) @@ -658,7 +638,6 @@ sqrt.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sqrt_x <- sqrt(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sqrt <- function(x) { UseMethod("sqrt", x) @@ -676,12 +655,10 @@ sqrt <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sqrt()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sqrt_x <- sqrt(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sqrt.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Sqrt")) @@ -723,7 +700,6 @@ rsqrt.default <- function(x) { #' [rkeops::rsqrt.LazyTensor()]. #' @seealso [rkeops::rsqrt.default()], [rkeops::rsqrt.LazyTensor()] #' @examples -#' \dontrun{ #' # Numerical input #' rsqrt(4) #' rsqrt(c(1,4,9,16)) @@ -732,7 +708,6 @@ rsqrt.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Rsqrt_x <- rsqrt(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export rsqrt <- function(x) { UseMethod("rsqrt", x) @@ -751,12 +726,10 @@ rsqrt <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::rsqrt()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Rsqrt_x <- rsqrt(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export rsqrt.LazyTensor <- function(x) { res <- unaryop.LazyTensor(x, "Rsqrt") @@ -789,7 +762,6 @@ rsqrt.LazyTensor <- function(x) { #' @return See value of [rkeops::^.default()] or [rkeops::^.LazyTensor()]. #' @seealso [rkeops::^.default()], [rkeops::^.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' 3^2 #' (1:10)^3 @@ -803,7 +775,6 @@ rsqrt.LazyTensor <- function(x) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_pow_y <- x_i^y_j # symbolic matrix -#' } #' @export "^" <- function(x, y) { if(!is.LazyTensor(x)) @@ -832,7 +803,6 @@ rsqrt.LazyTensor <- function(x) { #' or a scalar value. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -840,7 +810,6 @@ rsqrt.LazyTensor <- function(x) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_pow_y <- x_i^y_j # symbolic matrix -#' } #' @export "^.LazyTensor" <- function(x, y) { if(is.numeric(y) && length(y) == 1) { @@ -903,7 +872,6 @@ rsqrt.LazyTensor <- function(x) { #' @return See value of [rkeops::|.default()] or [rkeops::|.LazyTensor()]. #' @seealso [rkeops::|.default()], [rkeops::|.LazyTensor()] #' @examples -#' \dontrun{ #' # R base element-wise logical or operation #' TRUE | FALSE #' x <- 1:10 @@ -917,7 +885,6 @@ rsqrt.LazyTensor <- function(x) { #' # indexed by 'j' #' #' x_sp_y <- x_i | y_j # symbolic matrix -#' } #' @export "|" <- function(x, y) { if(!is.LazyTensor(x)) @@ -945,7 +912,6 @@ rsqrt.LazyTensor <- function(x) { #' or a scalar value. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -953,7 +919,6 @@ rsqrt.LazyTensor <- function(x) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_sp_y <- x_i | y_j # symbolic matrix -#' } #' @export "|.LazyTensor" <- function(x, y) { res <- binaryop.LazyTensor(x, y, "|", is_operator = TRUE, @@ -994,12 +959,19 @@ rsqrt.LazyTensor <- function(x) { #' @return See value of [rkeops::%*%.default()] or [rkeops::%*%.LazyTensor()]. #' @seealso [rkeops::%*%.default()], [rkeops::%*%.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' x <- matrix(runif(10 * 5), 10, 5) # arbitrary R matrix, 10 rows, 5 columns -#' x <- matrix(runif(5 * 3), 5, 3) # arbitrary R matrix, 5 rows, 3 columns +#' y <- matrix(runif(5 * 3), 5, 3) # arbitrary R matrix, 5 rows, 3 columns #' x %*% y # product matrix, 10 rows, 3 columns #' +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # LazyTensor matrix multiplication #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns @@ -1008,6 +980,10 @@ rsqrt.LazyTensor <- function(x) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_mult_y <- x_i %*% y_j # FIXME +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export "%*%" <- function(x, y) { @@ -1029,7 +1005,14 @@ rsqrt.LazyTensor <- function(x) { #' @param x,y a `LazyTensor`, a `ComplexLazyTensor`. #' @return A matrix. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -1037,6 +1020,10 @@ rsqrt.LazyTensor <- function(x) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' x_mult_y <- x_i %*% y_j # FIXME +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export "%*%.LazyTensor" <- function(x, y) { @@ -1076,7 +1063,6 @@ exp.default <- function(x) { #' [rkeops::exp.LazyTensor()]. #' @seealso [rkeops::exp.default()], [rkeops::exp.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' exp(0) #' exp(1:10) @@ -1085,7 +1071,6 @@ exp.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Exp_x <- exp(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export exp <- function(x) { UseMethod("exp") @@ -1109,7 +1094,6 @@ exp <- function(x) { #' input. #' @seealso [rkeops::exp()] #' @examples -#' \dontrun{ #' # basic example #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -1120,7 +1104,6 @@ exp <- function(x) { #' z <- matrix(1i^ (-6:5), nrow = 4) # create a complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # create a ComplexLazyTensor #' Exp_z_i <- exp(z_i) # symbolic matrix -#' } #' @export exp.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Exp")) @@ -1162,7 +1145,6 @@ log.default <- function(x, base = exp(1)) { #' [rkeops::log.LazyTensor()]. #' @seealso [rkeops::log.default()], [rkeops::log.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' log(1) #' log(1:10) @@ -1171,7 +1153,6 @@ log.default <- function(x, base = exp(1)) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Log_x <- log(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export log <- function(x, base = exp(1)) { UseMethod("log") @@ -1194,12 +1175,10 @@ log <- function(x, base = exp(1)) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::log()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Log_x <- log(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export log.LazyTensor <- function(x, base = exp(1)) { return(unaryop.LazyTensor(x, "Log")) @@ -1244,7 +1223,6 @@ inv.default <- function(x) { #' [rkeops::inv.LazyTensor()]. #' @seealso [rkeops::inv.default()], [rkeops::inv.LazyTensor()] #' @examples -#' \dontrun{ #' # Numerical input #' inv(4) #' inv(1:10) @@ -1253,7 +1231,6 @@ inv.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Inv_x <- inv(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export inv <- function(x) { UseMethod("inv") @@ -1271,12 +1248,10 @@ inv <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::inv()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Inv_x <- inv(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export inv.LazyTensor <- function(x) { res <- unaryop.LazyTensor(x, "Inv") @@ -1314,7 +1289,6 @@ cos.default <- function(x) { #' [rkeops::cos.LazyTensor()]. #' @seealso [rkeops::cos.default()], [rkeops::cos.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' cos(0) #' cos(pi) @@ -1323,7 +1297,6 @@ cos.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Cos_x <- cos(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export cos <- function(x) { UseMethod("cos") @@ -1340,12 +1313,10 @@ cos <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::cos()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Cos_x <- cos(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export cos.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Cos")) @@ -1375,7 +1346,6 @@ sin.default <- function(x) { #' [rkeops::sin.LazyTensor()]. #' @seealso [rkeops::sin.default()], [rkeops::sin.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' sin(0) #' sin(pi) @@ -1384,7 +1354,6 @@ sin.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sin_x <- sin(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sin <- function(x) { UseMethod("sin") @@ -1401,12 +1370,10 @@ sin <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sin()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sin_x <- sin(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sin.LazyTensor <- function(x){ return(unaryop.LazyTensor(x, "Sin")) @@ -1436,7 +1403,6 @@ acos.default <- function(x) { #' [rkeops::acos.LazyTensor()]. #' @seealso [rkeops::acos.default()], [rkeops::acos.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' acos(0) #' acos(-1) @@ -1445,7 +1411,6 @@ acos.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Acos_x <- acos(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export acos <- function(x) { UseMethod("acos") @@ -1462,12 +1427,10 @@ acos <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::acos()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Acos_x <- acos(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export acos.LazyTensor <- function(x) { res <- unaryop.LazyTensor(x, "Acos") @@ -1498,7 +1461,6 @@ asin.default <- function(x) { #' [rkeops::asin.LazyTensor()]. #' @seealso [rkeops::asin.default()], [rkeops::asin.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' asin(0) #' asin(-1) @@ -1507,7 +1469,6 @@ asin.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Asin_x <- asin(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export asin <- function(x) { UseMethod("asin") @@ -1524,12 +1485,10 @@ asin <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::asin()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Asin_x <- asin(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export asin.LazyTensor <- function(x) { res <- unaryop.LazyTensor(x, "Asin") @@ -1560,7 +1519,6 @@ atan.default <- function(x) { #' [rkeops::atan.LazyTensor()]. #' @seealso [rkeops::atan.default()], [rkeops::atan.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' atan(0) #' atan(-1) @@ -1569,7 +1527,6 @@ atan.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Atan_x <- atan(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export atan <- function(x) { UseMethod("atan") @@ -1586,12 +1543,10 @@ atan <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::atan()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Atan_x <- atan(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export atan.LazyTensor <- function(x) { res <- unaryop.LazyTensor(x, "Atan") @@ -1627,7 +1582,6 @@ atan2.default <- function(x, y) { #' [rkeops::atan2.LazyTensor()]. #' @seealso [rkeops::atan2.default()], [rkeops::atan2.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' atan2(0, 1) #' atan2(1, 0) @@ -1639,7 +1593,6 @@ atan2.default <- function(x, y) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' Atan2_xy <- atan2(x_i, y_j) # symbolic matrix -#' } #' @export atan2 <- function(x, y) { if(!is.LazyTensor(x) && !is.ComplexLazyTensor(x)) @@ -1665,7 +1618,6 @@ atan2 <- function(x, y) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::atan2()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -1673,7 +1625,6 @@ atan2 <- function(x, y) { #' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, #' # indexed by 'j' #' Atan2_xy <- atan2(x_i, y_j) # symbolic matrix -#' } #' @export atan2.LazyTensor <- function(x, y) { return(binaryop.LazyTensor(x, y, "Atan2", dim_check_type = "same")) @@ -1707,7 +1658,6 @@ abs.default <- function(x) { #' @seealso [rkeops::abs.default()], [rkeops::abs.LazyTensor()], #' [rkeops::Mod.default()], [rkeops::Mod.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' abs(5) #' abs(-5) @@ -1717,7 +1667,6 @@ abs.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Abs_x <- abs(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export abs <- function(x) { UseMethod("abs") @@ -1740,13 +1689,11 @@ abs <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::abs()], [rkeops::Mod()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' Abs_x <- abs(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export abs.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Abs")) @@ -1772,6 +1719,7 @@ abs.ComplexLazyTensor <- function(x) { #' @inherit base::sign examples #' @seealso [base::sign()] #' @author R core team and contributors +#' @return See 'Details' section. #' @export sign.default <- function(x) { return(base::sign(x)) @@ -1796,7 +1744,6 @@ sign.default <- function(x) { #' @return See value of [rkeops::sign.default()] or [rkeops::sign.LazyTensor()]. #' @seealso [rkeops::sign.default()], [rkeops::sign.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' sign(5) #' sign(-5) @@ -1806,7 +1753,6 @@ sign.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sign_x <- sign(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sign <- function(x) { UseMethod("sign") @@ -1829,12 +1775,10 @@ sign <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sign()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Sign_x <- sign(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sign.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "Sign")) @@ -1851,6 +1795,7 @@ sign.LazyTensor <- function(x) { #' @inherit base::round examples #' @seealso [base::round()] #' @author R core team and contributors +#' @return See 'Details' section. #' @export round.default <- function(x, digits = 0) { return(base::round(x, digits)) @@ -1869,7 +1814,6 @@ round.default <- function(x, digits = 0) { #' @return See value of [rkeops::round.default()] or [rkeops::round.LazyTensor()]. #' @seealso [rkeops::round.default()], [rkeops::round.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' round(5) #' round(runif(10), 4) @@ -1878,7 +1822,6 @@ round.default <- function(x, digits = 0) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Round_x <- round(x_i, 2) # symbolic matrix -#' } #' @export round <- function(x, digits = 0) { UseMethod("round", x) @@ -1898,12 +1841,10 @@ round <- function(x, digits = 0) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::round()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' Round_x <- round(x_i, 2) # symbolic matrix -#' } #' @export round.LazyTensor <- function(x, digits = 0) { if(is.numeric(digits) && length(digits) == 1) @@ -1952,16 +1893,14 @@ xlogx.default <- function(x) { #' [rkeops::xlogx.LazyTensor()] #' @seealso [rkeops::xlogx.default()], [rkeops::xlogx.LazyTensor()] #' @examples -#' \dontrun{ #' # Numerical input -#' xlog(4) -#' xlog(1:10) +#' xlogx(4) +#' xlogx(1:10) #' # LazyTensor symbolic element-wise `x*log(x)` #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' xlog_x <- xlogx(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export xlogx <- function(x) { UseMethod("xlogx", x) @@ -1980,12 +1919,10 @@ xlogx <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::xlogx()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' xlog_x <- xlogx(x_i) # symbolic matrix, 150 rows and 3 columnsjs -#' } #' @export xlogx.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "XLogX")) @@ -2030,7 +1967,6 @@ sinxdivx.default <- function(x) { #' [rkeops::sinxdivx.LazyTensor()] #' @seealso [rkeops::sinxdivx.default()], [rkeops::sinxdivx.LazyTensor()] #' @examples -#' \dontrun{ #' # Numerical input #' sinxdivx(4) #' sinxdivx(1:10) @@ -2039,7 +1975,6 @@ sinxdivx.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' sindiv_x <- sinxdivx(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sinxdivx <- function(x) { UseMethod("sinxdivx", x) @@ -2058,12 +1993,10 @@ sinxdivx <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sinxdivx()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' sindiv_x <- sinxdivx(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export sinxdivx.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "SinXDivX")) @@ -2100,14 +2033,12 @@ step.default <- function(object, ...) { #' @return See value of [rkeops::step.default()] or [rkeops::step.LazyTensor()]. #' @seealso [rkeops::step.default()], [rkeops::step.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation: see `?step.default` #' # LazyTensor symbolic element-wise sign #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' -#' Step_x <- step.LazyTensor(x_i) # symbolic matrix, 150 rows and 3 columns -#' } +#' Step_x <- step(x_i) # symbolic matrix, 150 rows and 3 columns #' @export step <- function(object, ...){ UseMethod("step", object) @@ -2127,12 +2058,10 @@ step <- function(object, ...){ #' @return An object of class `LazyTensor`. #' @seealso [rkeops::step()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' -#' Step_x <- step.LazyTensor(x_i) # symbolic matrix, 150 rows and 3 columns -#' } +#' Step_x <- step(x_i) # symbolic matrix, 150 rows and 3 columns #' @export step.LazyTensor <- function(object, ...) { return(unaryop.LazyTensor(object, "Step")) @@ -2179,7 +2108,6 @@ relu.default <- function(x) { #' @references #' \insertRef{fukushima_cognitron_1975}{rkeops} #' @examples -#' \dontrun{ #' # Numerical input #' relu(4) #' relu(-10:10) @@ -2188,7 +2116,6 @@ relu.default <- function(x) { #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' ReLU_x <- relu(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export relu <- function(x) { UseMethod("relu", x) @@ -2211,12 +2138,10 @@ relu <- function(x) { #' @references #' \insertRef{fukushima_cognitron_1975}{rkeops} #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' ReLU_x <- relu(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export relu.LazyTensor <- function(x) { return(unaryop.LazyTensor(x, "ReLU")) @@ -2240,7 +2165,6 @@ relu.LazyTensor <- function(x) { #' @param x,a,b A `LazyTensor`, a vector of numeric values, or a scalar value. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -2255,7 +2179,6 @@ relu.LazyTensor <- function(x) { #' #' # call clamp function #' clp <- clamp(x_i, y_j, z_i) -#' } #' @export clamp <- function(x, a, b) { if((is.ComplexLazyTensor(x) || is.ComplexLazyTensor(a)) @@ -2288,7 +2211,6 @@ clamp <- function(x, a, b) { #' @param z An `integer`. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -2297,7 +2219,6 @@ clamp <- function(x, a, b) { #' #' # call clampint function #' clp_int <- clamp(x_i, 7, 2) -#' } #' @export clampint <- function(x, y, z) { if(is.ComplexLazyTensor(x)) { @@ -2346,7 +2267,6 @@ ifelse.default <- function(test, yes, no) { #' [rkeops::ifelse.LazyTensor()] #' @seealso [rkeops::ifelse.default()], [rkeops::ifelse.LazyTensor()] #' @examples -#' \dontrun{ #' # R base operation #' x <- c(6:-4) #' sqrt(ifelse(x >= 0, x, NA)) @@ -2363,7 +2283,6 @@ ifelse.default <- function(test, yes, no) { #' z_i <- LazyTensor(z, index = 'i') #' #' if_else_xyz <- ifelse(x_i, y_j, z_i) -#' } #' @export ifelse <- function(test, yes, no) { UseMethod("ifelse", test) @@ -2387,7 +2306,6 @@ ifelse <- function(test, yes, no) { #' or a scalar value. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -2402,7 +2320,6 @@ ifelse <- function(test, yes, no) { #' #' # call ifelse function #' if_else_xyz <- ifelse(x_i, y_j, z_i) -#' } #' @export ifelse.LazyTensor <- function(test, yes, no) { if((is.ComplexLazyTensor(test) || is.ComplexLazyTensor(yes)) @@ -2433,7 +2350,6 @@ ifelse.LazyTensor <- function(test, yes, no) { #' (if existing). #' @seealso [rkeops::mod.LazyTensor()] #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -2451,7 +2367,6 @@ ifelse.LazyTensor <- function(test, yes, no) { #' #' # works also with LazyTensors with same inner dimension or dimension 1 #' mod_xyz <- mod(x_i, y_j, z_i) -#' } #' @export mod <- function(x, ...) { UseMethod("mod", x) @@ -2482,7 +2397,6 @@ mod <- function(x, ...) { #' corresponding generic function. #' @return An object of class `LazyTensor`. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -2500,7 +2414,6 @@ mod <- function(x, ...) { #' #' # works also with LazyTensors with same inner dimension or dimension 1 #' mod_xyz <- mod(x_i, y_j, z_i) -#' } #' @export mod.LazyTensor <- function(x, a, b = 0, ...) { return(ternaryop.LazyTensor(x, a, b, "Mod")) @@ -2522,16 +2435,15 @@ mod.LazyTensor <- function(x, a, b = 0, ...) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::|.LazyTensor()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' SqN_x <- sqnorm2(x_i) # symbolic matrix, 150 rows, 1 columns -#' } #' @export sqnorm2 <- function(x) { return( - unaryop.LazyTensor(x, "SqNorm2", res_type = "LazyTensor", dim_res = 1)) + unaryop.LazyTensor(x, "SqNorm2", res_type = "LazyTensor", dim_res = 1) + ) } @@ -2548,16 +2460,15 @@ sqnorm2 <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::|.LazyTensor()], [rkeops::sqrt()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' N_x <- norm2(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export norm2 <- function(x) { return( - unaryop.LazyTensor(x, "Norm2", res_type = "LazyTensor", dim_res = 1)) + unaryop.LazyTensor(x, "Norm2", res_type = "LazyTensor", dim_res = 1) + ) } @@ -2575,12 +2486,10 @@ norm2 <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sqnorm2()], [rkeops::rsqrt()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' N_x <- norm2(x_i) # symbolic matrix, 150 rows and 3 columns -#' } #' @export normalize <- function(x) { return(unaryop.LazyTensor(x, "Normalize")) @@ -2607,17 +2516,21 @@ normalize <- function(x) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sqnorm2()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns +#' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' +#' y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, +#' # indexed by 'j' #' -#' SqD_x <- sqdist(x_i) # symbolic matrix, 150 rows and 3 columns -#' } +#' SqD_x <- sqdist(x_i, y_j) # symbolic matrix, 150 rows and 3 columns #' @export sqdist <- function(x, y) { - return(binaryop.LazyTensor(x, y, "SqDist", res_type = "LazyTensor", - dim_res = 1)) + return( + binaryop.LazyTensor( + x, y, "SqDist", res_type = "LazyTensor", dim_res = 1 + ) + ) } @@ -2643,7 +2556,6 @@ sqdist <- function(x, y) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::sqnorm2()], [rkeops::weightedsqdist()] #' @examples -#' \dontrun{ #' x <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns #' s <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -2651,13 +2563,14 @@ sqdist <- function(x, y) { #' s_j <- LazyTensor(s, index = 'j') # creating LazyTensor from matrix s, #' # indexed by 'j' #' wsqn_xy <- weightedsqnorm(x_i, s_j) # symbolic matrix, 100 rows,1 columns -#' } #' @export weightedsqnorm <- function(x, s) { - return(binaryop.LazyTensor(s, x, "WeightedSqNorm", - dim_check_type = NA, - res_type = "LazyTensor", - dim_res = 1)) + return( + binaryop.LazyTensor( + s, x, "WeightedSqNorm", dim_check_type = NA, + res_type = "LazyTensor", dim_res = 1 + ) + ) } @@ -2685,7 +2598,6 @@ weightedsqnorm <- function(x, s) { #' @return An object of class `LazyTensor`. #' @seealso [rkeops::weightedsqnorm()], [rkeops::sqdist()] #' @examples -#' \dontrun{ #' x <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns #' y <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns #' s <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns @@ -2698,7 +2610,6 @@ weightedsqnorm <- function(x, s) { #' # indexed by 'i' #' #' wsqd_xy <- weightedsqdist(x_i, y_j, s_i) # symbolic matrix -#' } #' @export weightedsqdist <- function(x, y, s) { return(weightedsqnorm(x - y, s)) @@ -2720,6 +2631,7 @@ weightedsqdist <- function(x, y, s) { #' @inherit base::Re examples #' @seealso [base::Re()] #' @author R core team and contributors +#' @return See 'Details' section. #' @export Re.default <- function(z) { return(base::Re(z)) @@ -2737,7 +2649,6 @@ Re.default <- function(z) { #' @seealso [rkeops::Re.default()], [rkeops::Re.LazyTensor()], #' [rkeops::Im()], [rkeops::Arg()], [rkeops::Mod()], [rkeops::Conj()] #' @examples -#' \dontrun{ #' # R base operation #' Re(1) #' Re(1+1i) @@ -2745,7 +2656,6 @@ Re.default <- function(z) { #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Re_z <- Re(z_i) # symbolic matrix -#' } #' @export Re <- function(z) { UseMethod("Re", z) @@ -2768,11 +2678,9 @@ Re <- function(z) { #' @return An object of class `ComplexLazyTensor`. #' @seealso [rkeops::Re()] #' @examples -#' \dontrun{ #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Re_z <- Re(z_i) # symbolic matrix -#' } #' @export Re.LazyTensor <- function(z) { msg <- paste( @@ -2816,7 +2724,6 @@ Im.default <- function(z) { #' @seealso [rkeops::Im.default()], [rkeops::Im.LazyTensor()], #' [rkeops::Re()], [rkeops::Arg()], [rkeops::Mod()], [rkeops::Conj()] #' @examples -#' \dontrun{ #' # R base operation #' Im(1) #' Im(1+1i) @@ -2824,7 +2731,6 @@ Im.default <- function(z) { #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Im_z <- Im(z_i) # symbolic matrix -#' } #' @export Im <- function(z) { UseMethod("Im", z) @@ -2847,11 +2753,9 @@ Im <- function(z) { #' @return An object of class `ComplexLazyTensor`. #' @seealso [rkeops::Im()] #' @examples -#' \dontrun{ #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Im_z <- Im(z_i) # symbolic matrix -#' } #' @export Im.LazyTensor <- function(z) { msg <- paste( @@ -2895,7 +2799,6 @@ Arg.default <- function(z) { #' @seealso [rkeops::Arg.default()], [rkeops::Arg.LazyTensor()], #' [rkeops::Re()], [rkeops::Im()], [rkeops::Mod()], [rkeops::Conj()] #' @examples -#' \dontrun{ #' # R base operation #' Arg(1) #' Arg(1+1i) @@ -2903,7 +2806,6 @@ Arg.default <- function(z) { #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Arg_z <- Arg(z_i) # symbolic matrix -#' } #' @export Arg <- function(z) { UseMethod("Arg", z) @@ -2926,11 +2828,9 @@ Arg <- function(z) { #' @return An object of class `ComplexLazyTensor`. #' @seealso [rkeops::Arg()] #' @examples -#' \dontrun{ #' z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix #' z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor #' Arg_z <- Arg(z_i) # symbolic matrix -#' } #' @export Arg.LazyTensor <- function(z) { msg <- paste( @@ -2966,12 +2866,10 @@ Arg.ComplexLazyTensor <- function(z) { #' @param x a `LazyTensor`. #' @return An object of class `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, #' # indexed by 'i' #' z <- real2complex(x_i) # ComplexLazyTensor object -#' } #' @export real2complex <- function(x) { UseMethod("real2complex", x) @@ -2985,7 +2883,8 @@ real2complex <- function(x) { real2complex.LazyTensor <- function(x) { cplx_warning() return( - unaryop.LazyTensor(x, "Real2Complex", res_type = "ComplexLazyTensor")) + unaryop.LazyTensor(x, "Real2Complex", res_type = "ComplexLazyTensor") + ) } #' Element-wise "real to complex" operation @@ -3014,12 +2913,10 @@ real2complex.ComplexLazyTensor <- function(x) { #' @param x a `LazyTensor`. #' @return An object of class `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, #' # indexed by 'i' #' z <- imag2complex(x_i) # ComplexLazyTensor object -#' } #' @export imag2complex <- function(x) { UseMethod("imag2complex", x) @@ -3031,7 +2928,8 @@ imag2complex <- function(x) { #' @export imag2complex.LazyTensor <- function(x) { return( - unaryop.LazyTensor(x, "Imag2Complex", res_type = "ComplexLazyTensor")) + unaryop.LazyTensor(x, "Imag2Complex", res_type = "ComplexLazyTensor") + ) } #' Element-wise "imag 2 complex" operation @@ -3059,12 +2957,10 @@ imag2complex.ComplexLazyTensor <- function(x) { #' @param x A `LazyTensor`. #' @return An object of class "ComplexLazyTensor". #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, #' # indexed by 'i' #' z <- exp1j(x_i) # ComplexLazyTensor object -#' } #' @export exp1j <- function(x) { UseMethod("exp1j", x) @@ -3076,7 +2972,8 @@ exp1j <- function(x) { #' @export exp1j.LazyTensor <- function(x) { return( - unaryop.LazyTensor(x, "ComplexExp1j", res_type = "ComplexLazyTensor")) + unaryop.LazyTensor(x, "ComplexExp1j", res_type = "ComplexLazyTensor") + ) } #' Element-wise "complex exponential of 1j x" operation @@ -3112,7 +3009,6 @@ Conj.default <- function(z) { #' @seealso [rkeops::Conj.default()], [rkeops::Conj.LazyTensor()], #' [rkeops::Re()], [rkeops::Im()], [rkeops::Arg()], [rkeops::Mod()] #' @examples -#' \dontrun{ #' # R base operation #' Conj(1) #' Conj(1+1i) @@ -3120,7 +3016,6 @@ Conj.default <- function(z) { #' z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor #' Conj_z_i <- Conj(z_i) # symbolic matrix -#' } #' @export Conj <- function(z) { UseMethod("Conj", z) @@ -3143,11 +3038,9 @@ Conj <- function(z) { #' @return An object of class `ComplexLazyTensor`. #' @seealso [rkeops::Conj()] #' @examples -#' \dontrun{ #' z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor #' Conj_z_i <- Conj(z_i) # symbolic matrix -#' } #' @export Conj.LazyTensor <- function(z) { msg <- paste( @@ -3193,7 +3086,6 @@ Mod.default <- function(z) { #' @seealso [rkeops::Mod.default()], [rkeops::Mod.LazyTensor()], #' [rkeops::Re()], [rkeops::Im()], [rkeops::Arg()], [rkeops::Conj()] #' @examples -#' \dontrun{ #' # R base operation #' Mod(1) #' Mod(1+1i) @@ -3201,7 +3093,6 @@ Mod.default <- function(z) { #' z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor #' Mod_z_i <- Mod(z_i) # symbolic matrix -#' } #' @export Mod <- function(z) { UseMethod("Mod", z) @@ -3226,11 +3117,9 @@ Mod <- function(z) { #' @return An object of class `ComplexLazyTensor`. #' @seealso [rkeops::Mod()] #' @examples -#' \dontrun{ #' z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor #' Mod_z_i <- Mod(z_i) # symbolic matrix -#' } #' @export Mod.LazyTensor <- function(z) { msg <- paste( @@ -3270,13 +3159,11 @@ Mod.ComplexLazyTensor <- function(z) { #' the element of `x` that will be extracted. #' @return a `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' m <- 2 #' #' elem_x <- elem(x_i, m) # symbolic `m+1`-th element of `x_i`. -#' } #' @export elem <- function(x, m) { if(!is.int(m)) { @@ -3315,7 +3202,6 @@ elem <- function(x, m) { #' @param n an `integer` corresponding to the length of the vector of zeros. #' @return a `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' # basic example #' x <- 3.14 # arbitrary value #' Pm_x <- LazyTensor(x) # creating scalar parameter LazyTensor from x @@ -3324,7 +3210,6 @@ elem <- function(x, m) { #' n <- 3 #' #' elemT_x <- elemT(Pm_x, m, n) # symbolic vector -#' } #' @export elemT <- function(x, m, n) { if(!is.LazyParameter(x) && !is.ComplexLazyParameter(x)) { @@ -3369,7 +3254,6 @@ elemT <- function(x, m, n) { #' of consecutive elements from `x` that will be extracted. #' @return a `LazyTensor`. #' @examples -#' \dontrun{ #' # Two very rudimentary examples #' # ----------------------------- #' @@ -3380,6 +3264,10 @@ elemT <- function(x, m, n) { #' # [3,] 3 7 4 5 #' # [4,] 1 3 3 0 #' # [5,] 5 4 9 4 +#' g <- matrix( +#' c(1, 8, 1, 3, 2, 1, 2, 7, 3, 7, 4, 5, 1, 3, 3, 0, 5, 4, 9, 4), +#' nrow = 5, ncol = 4, byrow = TRUE +#' ) #' #' # Convert it to LazyTensor: #' g_i <- LazyTensor(g, index = 'i') @@ -3418,7 +3306,6 @@ elemT <- function(x, m, n) { #' d <- 2 #' #' extract_x <- extract(x_i, m, d) # symbolic matrix -#' } #' @export extract <- function(x, m, d) { # type check @@ -3438,9 +3325,11 @@ extract <- function(x, m, d) { D, "-m] where `m` is the starting index.", sep = "") ) } - return(unaryop.LazyTensor(x, "Extract", - opt_arg = m, opt_arg2 = d, - dim_res = d)) + return( + unaryop.LazyTensor( + x, "Extract", opt_arg = m, opt_arg2 = d, dim_res = d + ) + ) } @@ -3471,7 +3360,6 @@ extract <- function(x, m, d) { #' @param d an `integer` corresponding to the output inner dimension. #' @return A `LazyTensor`. #' @examples -#' \dontrun{ #' # I - Three very rudimentary examples #' # ----------------------------------- #' @@ -3480,6 +3368,7 @@ extract <- function(x, m, d) { #' # [1,] 1 4 #' # [2,] 2 5 #' # [3,] 3 6 +#' g <- matrix(1:6, nrow = 3, ncol = 2) #' #' # Convert it to LazyTensor: #' g_i <- LazyTensor(g, index = 'i') # indexed by 'i' (for example) @@ -3530,7 +3419,6 @@ extract <- function(x, m, d) { #' d <- 7 #' #' extractT_x <- extractT(x_i, m, d) # symbolic matrix -#' } #' @export extractT <- function(x, m, d) { # type checking @@ -3576,20 +3464,20 @@ extractT <- function(x, m, d) { #' @return a `LazyTensor` or a `ComplexLazyTensor` that encodes, symbolically, #' the concatenation of `x` and `y` along their inner dimension. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' y_j <- LazyTensor(y, index = 'j') # LazyTensor from matrix x, indexed by 'j' #' #' concat_xy <- concat(x_i, y_j) -#' } #' @export concat <- function(x, y) { dim_res <- get_inner_dim(x) + get_inner_dim(y) - return(binaryop.LazyTensor(x, y, "Concat", - dim_check_type = NA, - dim_res = dim_res)) + return( + binaryop.LazyTensor( + x, y, "Concat", dim_check_type = NA, dim_res = dim_res + ) + ) } @@ -3606,13 +3494,11 @@ concat <- function(x, y) { #' @param D an `integer` corresponding to the output dimension. #' @return a `LazyTensor`. #' @examples -#' \dontrun{ #' A <- 7 #' A_LT <- LazyTensor(A) # LazyTensor from scalar A #' D <- 7 #' #' onehot_x <- one_hot(A_LT, D) # symbolic vector of length D -#' } #' @export one_hot <- function(x, D) { if((!is.LazyTensor(x)) || (is.ComplexLazyTensor(x))) { @@ -3652,14 +3538,12 @@ one_hot <- function(x, D) { #' @param v a `LazyTensor` or a `ComplexLazyTensor` encoding a parameter vector. #' @return a `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' m <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' v <- c(1,2,3) # arbitrary R vector of length 3 #' m_i <- LazyTensor(m, index = 'i') # LazyTensor from matrix m, indexed by 'i' #' Pm_v <- LazyTensor(v) # parameter vector LazyTensor from v #' #' mv_mult <- matvecmult(m_i, Pm_v) # symbolic matrix -#' } #' @export matvecmult <- function(m, v) { if(!is.LazyMatrix(m)) { @@ -3702,14 +3586,12 @@ matvecmult <- function(m, v) { #' @param m a `LazyTensor` or a `ComplexLazyTensor` encoding a matrix. #' @return a `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' v <- c(1,2,3) # arbitrary R vector of length 3 #' m <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' Pm_v <- LazyTensor(v) # parameter vector LazyTensor from v #' m_i <- LazyTensor(m, index = 'i') # LazyTensor from matrix m, indexed by 'i' #' #' vm_mult <- vecmatmult(Pm_v, m_i) # symbolic matrix -#' } #' @export vecmatmult <- function(v, m) { if(!is.LazyVector(v)) { @@ -3750,15 +3632,12 @@ vecmatmult <- function(v, m) { #' @param y a `LazyTensor` or a `ComplexLazyTensor`. #' @return a `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(c(1, 2, 3), 2, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' y <- matrix(c(1, 1, 1), 2, 3) # arbitrary R matrix, 200 rows, 3 columns #' y_i <- LazyTensor(y, index = 'i') # LazyTensor from matrix y, indexed by 'i' #' -#' tp_xy <- tensorprod(x_i, y_i) # symbolic (4, 9) matrix. -#' -#' } +#' tp_xy <- tensorprod(x_i, y_i) # symbolic (4, 9) matrix. #' @export tensorprod <- function(x, y) { dim_res <- x$dimres * y$dimres @@ -3789,12 +3668,23 @@ tensorprod <- function(x, y) { #' if not used (default). #' @return an array storing the result of the specified reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' red_x <- reduction.LazyTensor(x_i, "Sum", "i") +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export reduction.LazyTensor <- function(x, opstr, index, opt_arg = NULL) { @@ -3850,10 +3740,17 @@ sum.default <- function(...) { #' [rkeops::sum.LazyTensor()]. #' @return Sum of input. #' @examples -#' \dontrun{ #' # R base operation #' sum(1:10) #' sum(c(NA, 1, 2), na.rm = TRUE) +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # LazyTensor operation #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -3861,6 +3758,10 @@ sum.default <- function(...) { #' #' sum_x <- sum(x_i) # LazyTensor object #' sum_red_x <- sum(x_i, "i") # sum reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export sum <- function(x, ...) { @@ -3892,15 +3793,25 @@ sum <- function(x, ...) { #' the specified sum reduction otherwise. #' @seealso [rkeops::sum_reduction()] #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' sum_x <- sum(x_i) # LazyTensor object #' sum_red_x <- sum(x_i, "i") # sum reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } -#' #' @export sum.LazyTensor <- function(x, index = NA, ...) { @@ -3931,12 +3842,23 @@ sum.LazyTensor <- function(x, index = NA, ...) { #' @details **Note**: `index` input argument cannot be `NA` for the #' `sum_reduction()` function. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' sum_reduction(x_i, "i") +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export sum_reduction <- function(x, index) { @@ -3978,10 +3900,17 @@ min.default <- function(...) { #' [rkeops::min.LazyTensor()]. #' @return Minimum of input. #' @examples -#' \dontrun{ #' # R base operation #' min(1:10) #' min(c(NA, 1, 2), na.rm = TRUE) +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # LazyTensor operation #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -3989,6 +3918,10 @@ min.default <- function(...) { #' #' min_x <- min(x_i) # LazyTensor object #' min_red_x <- min(x_i, "i") # min reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export min <- function(x, ...) { @@ -4020,13 +3953,24 @@ min <- function(x, ...) { #' @return a `LazyTensor` if `index = NA` or an array storing the result of #' the specified min reduction otherwise. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' min_x <- min(x_i) # LazyTensor object #' min_red_x <- min(x_i, "i") # min reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export min.LazyTensor <- function(x, index = NA, ...) { @@ -4049,12 +3993,23 @@ min.LazyTensor <- function(x, index = NA, ...) { #' @details **Note**: `index` input argument cannot be `NA` for the #' `min_reduction()` function. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' min_reduction(x_i, "i") +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export min_reduction <- function(x, index) { @@ -4095,13 +4050,24 @@ min_reduction <- function(x, index) { #' the specified argmin reduction otherwise. #' @seealso [rkeops::argmin_reduction()] #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' argmin_xi <- argmin(x_i, "i") # argmin reduction indexed by 'i' #' argmin_x <- argmin(x_i) # symbolic matrix +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argmin <- function(x, index = NA) { @@ -4124,12 +4090,23 @@ argmin <- function(x, index = NA) { #' @details **Note**: `index` input argument cannot be `NA` for the #' `argmin_reduction()` function. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' argmin_red <- argmin(x_i, "i") # argmin reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argmin_reduction <- function(x, index) { @@ -4164,12 +4141,23 @@ argmin_reduction <- function(x, index) { #' @return an array storing the result of the specified Min-ArgMin #' reduction otherwise. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' min_argmin_xi <- min_argmin(x_i, "i") # min argmin reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export min_argmin <- function(x, index) { @@ -4187,12 +4175,23 @@ min_argmin <- function(x, index) { #' @name min_argmin #' @aliases min_argmin_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' min_argmin_red <- min_argmin_reduction(x_i, "i") # min reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export min_argmin_reduction <- function(x, index) { @@ -4231,10 +4230,17 @@ max.default <- function(...) { #' [rkeops::max.LazyTensor()]. #' @return Maximum of input. #' @examples -#' \dontrun{ #' # R base operation #' max(1:10) #' max(c(NA, 1, 2), na.rm = TRUE) +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # LazyTensor operation #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -4242,6 +4248,10 @@ max.default <- function(...) { #' #' max_x <- max(x_i) # LazyTensor object #' max_red_x <- max(x_i, "i") # max reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export max <- function(x, ...) { @@ -4279,13 +4289,24 @@ max <- function(x, ...) { #' the specified max reduction otherwise. #' @seealso [rkeops::max_reduction()] #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' max_x <- max(x_i) # LazyTensor object #' max_red_x <- max(x_i, "i") # max reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export max.LazyTensor <- function(x, index = NA, ...) { @@ -4308,12 +4329,23 @@ max.LazyTensor <- function(x, index = NA, ...) { #' @details **Note**: `index` input argument cannot be `NA` for the #' `max_reduction()` function. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' max_reduction(x_i, "i") +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export max_reduction <- function(x, index) { @@ -4352,13 +4384,24 @@ max_reduction <- function(x, index) { #' the specified argmax reduction otherwise. #' @seealso [rkeops::argmax_reduction()] #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' argmax_xi <- argmax(x_i, "i") # argmax reduction indexed by 'i' #' argmax_x <- argmax(x_i) # symbolic matrix +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argmax <- function(x, index = NA) { @@ -4382,12 +4425,23 @@ argmax <- function(x, index = NA) { #' @details **Note**: `index` input argument cannot be `NA` for the #' `argmax_reduction()` function. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' argmax_red <- argmax_reduction(x_i, "i") # argmax reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argmax_reduction <- function(x, index) { @@ -4422,12 +4476,23 @@ argmax_reduction <- function(x, index) { #' @return an array storing the result of the specified Max-ArgMax #' reduction otherwise. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' max_argmax_x <- max_argmax(x_i, "i") # max argmax reduction indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export max_argmax <- function(x, index) { @@ -4445,13 +4510,24 @@ max_argmax <- function(x, index) { #' @name max_argmax #' @aliases max_argmax_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' max_argmax_red <- max_argmax_reduction(x_i, "i") # max argmax reduction #' # indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export max_argmax_reduction <- function(x, index) { @@ -4487,11 +4563,22 @@ max_argmax_reduction <- function(x, index) { #' required. #' @return A matrix corresponding to the Kmin reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' K <- 2 #' kmin_x <- Kmin(x_i, K, "i") # Kmin reduction, over the 'i' indices +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export Kmin <- function(x, K, index) { @@ -4510,11 +4597,22 @@ Kmin <- function(x, K, index) { #' @name Kmin #' @aliases Kmin_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' K <- 2 #' kmin_red_x <- Kmin_reduction(x_i, K, "i") # Kmin reduction, indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export Kmin_reduction <- function(x, K, index) { @@ -4548,7 +4646,14 @@ Kmin_reduction <- function(x, K, index) { #' required. #' @return A matrix corresponding to the argKmin reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' @@ -4556,6 +4661,10 @@ Kmin_reduction <- function(x, K, index) { #' argkmin_x <- argKmin(x_i, K, "i") # argKmin reduction #' # indexed by 'i' #' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argKmin <- function(x, K, index) { @@ -4574,13 +4683,24 @@ argKmin <- function(x, K, index) { #' @name argKmin #' @aliases argKmin_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' K <- 2 #' argkmin_red_x <- argKmin_reduction(x_i, K, "i") # argKmin reduction #' # indexed by 'i' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export argKmin_reduction <- function(x, K, index) { @@ -4612,7 +4732,14 @@ argKmin_reduction <- function(x, K, index) { #' required. #' @return A matrix corresponding to the Kmin-argKmin reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' @@ -4620,6 +4747,10 @@ argKmin_reduction <- function(x, K, index) { #' k_argk_x <- Kmin_argKmin(x_i, K, "i") # Kmin-argKmin reduction #' # indexed by 'i' #' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export Kmin_argKmin <- function(x, K, index) { @@ -4638,7 +4769,14 @@ Kmin_argKmin <- function(x, K, index) { #' @name Kmin_argKmin #' @aliases Kmin_argKmin_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, #' # indexed by 'i' @@ -4646,6 +4784,10 @@ Kmin_argKmin <- function(x, K, index) { #' K <- 2 #' k_argk_x <- Kmin_argKmin_reduction(x_i, K, "i") # Kmin-argKmin reduction #' # over the "i" indices +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export Kmin_argKmin_reduction <- function(x, K, index) { @@ -4675,9 +4817,17 @@ Kmin_argKmin_reduction <- function(x, K, index) { #' indexed by `"i"` or `"j"`. #' @param weight an optional object (`LazyTensor` or `ComplexLazyTensor`) that #' specifies scalar or vector-valued weights. `NULL` by default and not used. +#' **Not supported at the moment**. #' @return a matrix corresponding to the Log-Sum-Exp reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) #' x_i <- LazyTensor(x, index = 'i') #' y <- matrix(runif(100 * 3), 100, 3) @@ -4685,12 +4835,20 @@ Kmin_argKmin_reduction <- function(x, K, index) { #' w <- matrix(runif(100 * 3), 100, 3) # weight LazyTensor #' w_j <- LazyTensor(w, index = 'j') #' -#' S_ij = sum((x_i - y_j)^2) -#' logsumexp_xw <- logsumexp(S_ij, 'i', w_j) # logsumexp reduction -#' # over the 'i' indices +#' S_ij = sum((x_i - y_j)^2) #' -#' logsumexp_x <- logsumexp(S_ij, 'i') # logsumexp reduction without -#' # weight over the 'i' indices +#' logsumexp_x <- logsumexp(S_ij, 'i') # logsumexp reduction +#' # over the 'i' indices +#' +#' \dontrun{ +#' # note: expected error, not supported at the moment +#' logsumexp_xw <- logsumexp(S_ij, 'i', w_j) # logsumexp reduction with weights +#' # over the 'i' indices +#' } +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export logsumexp <- function(x, index, weight = NULL) { @@ -4701,7 +4859,7 @@ logsumexp <- function(x, index, weight = NULL) { else if(check_index(index) && !is.null(weight)) { #res <- reduction.LazyTensor(x, "Max_SumShiftExpWeight", # index, opt_arg = weight) - #res <- reduction.LazyTensor(x, "LogSumExp", + # res <- reduction.LazyTensor(x, "LogSumExp", # index, opt_arg = weight) stop(paste("`logsumexp` reduction is not yet supported with weights.", "\nThis should be fixed in a future release.", sep = "")) @@ -4718,7 +4876,14 @@ logsumexp <- function(x, index, weight = NULL) { #' @name logsumexp #' @aliases logsumexp_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) #' x_i <- LazyTensor(x, index = 'i') #' y <- matrix(runif(100 * 3), 100, 3) @@ -4726,12 +4891,20 @@ logsumexp <- function(x, index, weight = NULL) { #' w <- matrix(runif(150 * 3), 150, 3) # weight LazyTensor #' w_j <- LazyTensor(y, index = 'j') #' -#' S_ij = sum( (x_i - y_j)^2 ) -#' logsumexp_xw <- logsumexp_reduction(S_ij, 'i', w_j) # logsumexp reduction -#' # over the 'i' indices +#' S_ij = sum( (x_i - y_j)^2 ) #' #' logsumexp_x <- logsumexp_reduction(S_ij, 'i') # logsumexp reduction without #' # weight over the 'i' indices +#' +#' \dontrun{ +#' # note: expected error, not supported at the moment +#' logsumexp_xw <- logsumexp_reduction(S_ij, 'i', w_j) # logsumexp reduction +#' # over the 'i' indices +#' } +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export logsumexp_reduction <- function(x, index, weight = NULL) { @@ -4761,7 +4934,14 @@ logsumexp_reduction <- function(x, index, weight = NULL) { #' specifies scalar or vector-valued weights. #' @return a matrix corresponding to the Sum of weighted Soft-Max reduction. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) #' x_i <- LazyTensor(x, index = 'i') #' y <- matrix(runif(100 * 3), 100, 3) @@ -4772,6 +4952,10 @@ logsumexp_reduction <- function(x, index, weight = NULL) { #' #' ssmaxweight <- sumsoftmaxweight(S_ij, 'i', V_ij) # sumsoftmaxweight reduction #' # over the 'i' indices +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export sumsoftmaxweight <- function(x, index, weight) { @@ -4792,18 +4976,28 @@ sumsoftmaxweight <- function(x, index, weight) { #' @name sumsoftmaxweight #' @aliases sumsoftmaxweight_reduction #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' x <- matrix(runif(150 * 3), 150, 3) #' x_i <- LazyTensor(x, index = 'i') #' y <- matrix(runif(100 * 3), 100, 3) #' y_j <- LazyTensor(y, index = 'j') #' #' V_ij <- x_i - y_j # weight matrix -#' S_ij = sum(V-ij^2) +#' S_ij = sum(V_ij^2) #' #' # sumsoftmaxweight reduction over the 'i' indices #' ssmaxw_red <- sumsoftmaxweight_reduction(S_ij, 'i', V_ij) -#' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export sumsoftmaxweight_reduction <- function(x, index, weight) { @@ -4835,15 +5029,22 @@ sumsoftmaxweight_reduction <- function(x, index, weight) { #' (like "Sum" or "Max"). #' @param var An `integer` number indicating regarding to which #' variable/parameter (given by name or by position index starting at 0) the -#' gradient of the formula should be computed or a one of the `LazyTensor` -#' contained in `f`. +#' gradient of the formula should be computed or the variable containing +#' one of the `LazyTensor` contained in `f`. #' @param index A `character` that should be either **i** or **j** to specify #' whether if the reduction is indexed by **i** (rows), or **j** (columns). #' When the first `f` variable is indexed by **i** (resp. **j**), index cannot #' be **i** (resp. **j**). #' @return A `matrix`. #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' nx <- 100 #' ny <- 150 #' x <- matrix(runif(nx*3), nrow=nx, ncol=3) # matrix 100 x 3 @@ -4857,10 +5058,14 @@ sumsoftmaxweight_reduction <- function(x, index, weight) { #' # indexed by 'i' (like x_i) #' #' # gradient with the formula from position -#' grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = y_j$formula, "j") +#' grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = y_j, "j") #' #' # gradient with the formula from index #' grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = 0, "j") +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @export grad <- function(f, gradin, opstr, var, index) { diff --git a/rkeops/R/lazytensor_preprocess.R b/rkeops/R/lazytensor_preprocess.R index 9e10134c5..4aab1bda1 100644 --- a/rkeops/R/lazytensor_preprocess.R +++ b/rkeops/R/lazytensor_preprocess.R @@ -58,7 +58,14 @@ #' (`is_complex = FALSE`). #' @return An object of class "LazyTensor" or "ComplexLazyTensor". #' @examples -#' \dontrun{ +#' \donttest{ +#' \dontshow{ +#' # Specific setup for example runs (not necessary for standard use) +#' reticulate::py_available(initialize = TRUE) +#' set_rkeops_options() +#' # For build on CRAN, use CPU computing with 2 cores max +#' rkeops_use_cpu(ncore = 2) +#' } #' # Data #' nx <- 100 #' ny <- 150 @@ -89,7 +96,10 @@ #' z <- matrix(1i^ (-6:5), nrow = 4) # create a complex 4x3 matrix #' z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # create a ComplexLazyTensor, #' # indexed by 'i' -#' +#' \dontshow{ +#' # clean-up (for CRAN build) +#' clean_rkeops(remove_cache_dir = TRUE) +#' } #' } #' @importFrom data.table address #' @export @@ -224,11 +234,9 @@ LazyTensor <- function(x, index = NA, is_complex = FALSE) { #' @return An object of class "LazyTensor" indexed by "i". See `?LazyTensor` for #' more details. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) #' Vi_x <- Vi(x) # symbolic object representing an arbitrary row of x, #' # indexed by the letter "i" -#' } #' @export Vi <- function(x, is_complex = FALSE){ if(!is.matrix(x)) @@ -253,11 +261,9 @@ Vi <- function(x, is_complex = FALSE){ #' (`is_complex = FALSE`). #' @return An object of class "LazyTensor" indexed by "j". #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) #' Vj_x <- Vj(x) # symbolic object representing an arbitrary row of x, #' # indexed by the letter "j" -#' } #' @export Vj <- function(x, is_complex = FALSE){ if(!is.matrix(x)) @@ -283,10 +289,8 @@ Vj <- function(x, is_complex = FALSE){ #' @return An object of class "LazyTensor" in parameter category. #' See `?LazyTensor` for more details. #' @examples -#' \dontrun{ #' x <- 4 #' Pm_x <- Pm(x) -#' } #' @export Pm <- function(x, is_complex = FALSE){ if(is.LazyTensor(x)) { @@ -327,7 +331,6 @@ Pm <- function(x, is_complex = FALSE){ #' inner dimension of the input `LazyTensor`. #' @return An object of class "LazyTensor" or "ComplexLazyTensor". #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' @@ -337,10 +340,9 @@ Pm <- function(x, is_complex = FALSE){ #' #' # example with not NA dim_res: #' ## set dim_res to 1 because the "Norm2" operation results on a (symbolic) scalar -#' una3_x <- unaryop.LazyTensor(x, "Norm2", -#' res_type = "LazyTensor", -#' dim_res = 1) -#' } +#' una3_x <- unaryop.LazyTensor( +#' x_i, "Norm2", res_type = "LazyTensor", dim_res = 1 +#' ) #' @export unaryop.LazyTensor <- function(x, opstr, opt_arg = NA, opt_arg2 = NA, res_type = NA, dim_res = NA) { @@ -434,14 +436,12 @@ unaryop.LazyTensor <- function(x, opstr, opt_arg = NA, opt_arg2 = NA, #' encoding the binary operation on input LazyTensors. #' @return An object of class "LazyTensor". #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' #' y_j <- LazyTensor(y, index = 'j') # LazyTensor from matrix y, indexed by 'j' #' # symbolic matrix: #' bin_xy <- binaryop.LazyTensor(x_i, y_j, "+", is_operator = TRUE) -#' } #' @export binaryop.LazyTensor <- function(x, y, opstr, is_operator = FALSE, dim_check_type = "sameor1", res_type = NA, @@ -601,7 +601,6 @@ binaryop.LazyTensor <- function(x, y, opstr, is_operator = FALSE, #' maximum between the inner dimensions of the three input `LazyTensor`s. #' @return An object of class "LazyTensor". #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -616,7 +615,6 @@ binaryop.LazyTensor <- function(x, y, opstr, is_operator = FALSE, #' #' # symbolic matrix: #' tern_xyz <- ternaryop.LazyTensor(x_i, y_j, z_i, "IfElse") -#' } #' @export ternaryop.LazyTensor <- function(x, y, z, opstr, dim_check_type = "sameor1", dim_res = NA) { @@ -735,7 +733,6 @@ ternaryop.LazyTensor <- function(x, y, z, opstr, dim_check_type = "sameor1", #' @param x An object that we want to know if it is a `LazyTensor`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -747,7 +744,6 @@ ternaryop.LazyTensor <- function(x, y, z, opstr, dim_check_type = "sameor1", #' # call is.LazyTensor #' is.LazyTensor(x_i) # returns TRUE #' is.LazyTensor(x) # returns FALSE -#' } #' @export is.LazyTensor <- function(x){ return("LazyTensor" %in% class(x)) @@ -763,7 +759,6 @@ is.LazyTensor <- function(x){ #' @param x An object that we want to know if it is a `ComplexLazyTensor`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -777,7 +772,6 @@ is.LazyTensor <- function(x){ #' # call is.ComplexLazyTensor #' is.ComplexLazyTensor(z_i) # returns TRUE #' is.ComplexLazyTensor(x_i) # returns FALSE -#' } #' @export is.ComplexLazyTensor <- function(x){ return("ComplexLazyTensor" %in% class(x)) @@ -796,7 +790,6 @@ is.ComplexLazyTensor <- function(x){ #' `LazyParameter`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' scal <- 3.14 #' cplx <- 2 + 3i @@ -814,7 +807,6 @@ is.ComplexLazyTensor <- function(x){ #' is.LazyParameter(cplx_LT) # returns FALSE #' is.LazyParameter(v_LT) # returns FALSE #' is.LazyParameter(x_i) # returns FALSE -#' } #' @export is.LazyParameter <- function(x) { if(!is.LazyTensor(x)) { @@ -842,7 +834,6 @@ is.LazyParameter <- function(x) { #' it is a `ComplexLazyParameter`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' scal <- 3.14 #' cplx <- 2 + 3i @@ -859,8 +850,7 @@ is.LazyParameter <- function(x) { #' is.ComplexLazyParameter(scal_LT) # returns FALSE #' is.ComplexLazyParameter(cplx_LT) # returns TRUE #' is.ComplexLazyParameter(v_LT) # returns FALSE -#' is.ComplexLazyParameter(x_i) # returns FALSE -#' } +#' is.ComplexLazyParameter(z_i) # returns FALSE #' @export is.ComplexLazyParameter <- function(x) { if(!is.LazyTensor(x)) { @@ -884,7 +874,6 @@ is.ComplexLazyParameter <- function(x) { #' @param x A `LazyTensor` object that we want to know if it is a `LazyVector`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' scal <- 3.14 #' cplx <- 2 + 3i @@ -902,7 +891,6 @@ is.ComplexLazyParameter <- function(x) { #' is.LazyVector(cplx_LT) # returns TRUE #' is.LazyVector(v_LT) # returns TRUE #' is.LazyVector(x_i) # returns FALSE -#' } #' @export is.LazyVector <- function(x) { if(!is.LazyTensor(x)) { @@ -922,7 +910,6 @@ is.LazyVector <- function(x) { #' @param x A `LazyTensor` object that we want to know if it is a `LazyMatrix`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' scal <- 3.14 #' cplx <- 2 + 3i @@ -940,7 +927,6 @@ is.LazyVector <- function(x) { #' is.LazyMatrix(cplx_LT) # returns FALSE #' is.LazyMatrix(v_LT) # returns FALSE #' is.LazyMatrix(x_i) # returns TRUE -#' } #' @export is.LazyMatrix <- function(x) { if(!is.LazyTensor(x)) { @@ -959,7 +945,6 @@ is.LazyMatrix <- function(x) { #' @param x An object that we want to know if it is an `integer`. #' @return A boolean, TRUE or FALSE. #' @examples -#' \dontrun{ #' # basic example #' A <- 3 #' B <- 3.4 @@ -968,7 +953,6 @@ is.LazyMatrix <- function(x) { #' is.int(A) # returns TRUE #' is.int(B) # returns FALSE #' is.int(C) # returns FALSE -#' } #' @export is.int <- function(x) { res <- (is.numeric(x) && length(x) == 1) && ((as.integer(x) - x) == 0) @@ -991,7 +975,6 @@ is.int <- function(x) { #' @param x A `LazyTensor`. #' @return An integer corresponding to the inner dimension of `x`. #' @examples -#' \dontrun{ #' # basic example #' D <- 3 #' M <- 100 @@ -1005,7 +988,7 @@ is.int <- function(x) { #' # call get_inner_dim #' get_inner_dim(x_i) # returns 3 #' get_inner_dim(Pm_s) # returns 1 -#' } +#' @noRd get_inner_dim <- function(x) { # Grab `x` inner dimension. # `x` must be a LazyTensor or a ComplexLazyTensor. @@ -1055,6 +1038,7 @@ get_inner_dim <- function(x) { #' to specify the desired type of inner dimension verification #' (see @details section). #' @return A boolean TRUE or FALSE. +#' @noRd check_inner_dim <- function(x, y, z = NA, check_type = "sameor1") { # Inputs must be LazyTensors or ComplexLazyTensors. if(!is.LazyTensor(x) || !is.LazyTensor(y)) { @@ -1113,6 +1097,7 @@ check_inner_dim <- function(x, y, z = NA, check_type = "sameor1") { #' @author Chloe Serre-Combe, Amelie Vernay #' @param index to check. #' @return A boolean TRUE or FALSE. +#' @noRd check_index <- function(index){ res <- is.character(index) && (index %in% c("i", "j")) return(res) @@ -1127,6 +1112,7 @@ check_index <- function(index){ #' @author Chloe Serre-Combe, Amelie Vernay #' @param index A `character` that should be either `i` or `j`. #' @return An `integer`. +#' @noRd index_to_int <- function(index) { if(!check_index(index)) { stop(paste0("`index` input argument should be a character,", @@ -1153,13 +1139,12 @@ index_to_int <- function(index) { #' a `LazyTensor`. #' @return A `string`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' arg <- x_i$args[1] # argument of the form "A0x.*=Vi(3)" #' id <- identifier(arg) # extracts "A0x.*" -#' } +#' @noRd identifier <- function(arg){ if(!is.character(arg)) { stop("`arg` input argument should be a character string.") @@ -1180,7 +1165,6 @@ identifier <- function(arg){ #' @param x A `LazyTensor` or a `ComplexLazyTensor`. #' @return A `LazyTensor` or a `ComplexLazyTensor`. #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -1195,7 +1179,7 @@ identifier <- function(arg){ #' # of the form "V0" and "V1" #' b$formula # returns "V0+V1" #' b$args # returns a vector containing "V0=Vi(3)" and "V1=Vj(3)" -#' } +#' @noRd fix_variables <- function(x, is_opt = FALSE) { if(!is.LazyTensor(x)) { stop("`x` input must be a LazyTensor or a ComplexLazyTensor.") @@ -1255,6 +1239,7 @@ fix_variables <- function(x, is_opt = FALSE) { #' @param with_weight A `boolean` which is `TRUE` when there is an optional #' argument corresponding to a weight argument. #' @return A text `string`. +#' @noRd fix_op_reduction <- function(reduction_op, with_weight = FALSE) { lifecycle::deprecate_warn( @@ -1306,13 +1291,12 @@ fix_op_reduction <- function(reduction_op, with_weight = FALSE) { #' @return A `function`. #' @seealso [rkeops::reduction.LazyTensor()] #' @examples -#' \dontrun{ #' x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns #' x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, #' # indexed by 'i' #' #' op <- preprocess_reduction(x_i, "Sum", "i") -#' } +#' @noRd preprocess_reduction <- function(x, opstr, index, opt_arg = NULL) { # init @@ -1375,7 +1359,8 @@ preprocess_reduction <- function(x, opstr, index, opt_arg = NULL) { #' a `ComplexLazyTensor`. #' #' @author Chloe Serre-Combe, Amelie Vernay -#' @return A warning message. +#' @return No return value, raise a warning if requested. +#' @noRd cplx_warning <- function(warn = TRUE) { if(warn) { msg <- paste( diff --git a/rkeops/R/py_req.R b/rkeops/R/py_req.R new file mode 100644 index 000000000..3ddae1a0c --- /dev/null +++ b/rkeops/R/py_req.R @@ -0,0 +1,34 @@ +#' Setup Python requirements for RKeOps +#' +#' @keywords internal +#' +#' @author Ghislain Durif +#' +#' @description +#' Install requirements (i.e. Python version and Python packages) for +#' RKeOps to work. +#' +#' @details +#' RKeOps now uses PyKeOps Python package under the hood thanks to the +#' [`reticulate`](https://rstudio.github.io/reticulate/) R package that +#' provides an "R Interface to Python". +#' +#' This function is a wrapper around the [`reticulate::py_require()`] +#' function that allows to setup a temporary Python environment on the fly +#' for the current R session. +#' +#' **Important 1:** for the moment, Python version requirement is hard-coded +#' to be 3.12. This could change in the future depending on PyKeOps evolution. +#' +#' **Important 1:** Python is a requirement as an intern machinery for the +#' package to work but you will not need to create nor manipulate Python +#' codes to use the RKeOps package. +#' +#' @importFrom reticulate py_require +#' @noRd +setup_pyreq <- function() { + reticulate::py_require( + packages = "pykeops", + python_version = "3.12" + ) +} \ No newline at end of file diff --git a/rkeops/R/rkeops-package.R b/rkeops/R/rkeops-package.R index 7f7871f82..7c7c75540 100644 --- a/rkeops/R/rkeops-package.R +++ b/rkeops/R/rkeops-package.R @@ -11,13 +11,13 @@ #' standard R functions that can be used in any R (>=3) codes. #' #' @author -#' - [Benjamin Charlier](http://imag.umontpellier.fr/~charlier/) +#' - [Benjamin Charlier](https://miat.inrae.fr/bcharlier/) #' - Amelie Vernay #' - Chloe Serre-Combe #' - [Ghislain Durif](https://gdurif.perso.math.cnrs.fr/) #' - [Jean Feydy](https://www.jeanfeydy.com) -#' - [Joan Alexis Glaunès](http://helios.mi.parisdescartes.fr/~glaunes/) -#' - François-David Collin +#' - [Joan Alexis Glaunès](https://helios2.mi.parisdescartes.fr/~glaunes/) +#' - [François-David Collin](https://fradav.perso.math.cnrs.fr/) #' #' @details #' The KeOps library provides seamless kernel operations on GPU, with @@ -30,8 +30,7 @@ #' when the full kernel matrix does not fit into the GPU memory. #' #' For more information, please read the vignettes -#' (`browseVignettes("rkeops")`) and visit -#' . +#' (`browseVignettes("rkeops")`) and visit . #' #' @references #' \insertRef{JMLR:v22:20-275}{rkeops} diff --git a/rkeops/R/rkeops_check.R b/rkeops/R/rkeops_check.R index 86b0b296e..25b83aecd 100644 --- a/rkeops/R/rkeops_check.R +++ b/rkeops/R/rkeops_check.R @@ -17,6 +17,7 @@ #' @author Ghislain Durif #' #' @importFrom checkmate assert_flag +#' @noRd check_os <- function(startup = FALSE) { assert_flag(startup) if(.Platform$OS.type != "unix") { @@ -51,6 +52,7 @@ check_os <- function(startup = FALSE) { #' @importFrom checkmate assert_choice assert_flag test_null #' #' @author Ghislain Durif +#' @noRd check_pypkg <- function(package, verbose = TRUE) { # check input assert_choice(package, c("keopscore", "pykeops")) @@ -94,10 +96,7 @@ check_pypkg <- function(package, verbose = TRUE) { #' #' @author Ghislain Durif #' -#' @examples -#' \dontrun{ -#' check_pykeops() -#' } +#' @noRd check_pykeops <- function(verbose = TRUE) { return(check_pypkg("pykeops", verbose)) } @@ -116,10 +115,7 @@ check_pykeops <- function(verbose = TRUE) { #' #' @author Ghislain Durif #' -#' @examples -#' \dontrun{ -#' check_keopscore() -#' } +#' @noRd check_keopscore <- function(verbose = TRUE) { return(check_pypkg("keopscore", verbose)) } @@ -149,10 +145,11 @@ check_keopscore <- function(verbose = TRUE) { #' @export #' #' @examples -#' \dontrun{ +#' \donttest{ #' check_rkeops() #' } check_rkeops <- function(verbose = TRUE) { + # init check0 <- FALSE check1 <- FALSE @@ -171,16 +168,23 @@ check_rkeops <- function(verbose = TRUE) { if(check2) { setup_pykeops() + msg1 <- NULL + msg2 <- NULL out <- tryCatch({ - msg <- py_capture_output({ - pykeops$show_cuda_status() + msg1 <- py_capture_output({ + pykeops$config$cuda_config$print_use_cuda() }) - py_capture_output({ + msg2 <- py_capture_output({ pykeops$test_numpy_bindings() }) }, error = function(e) e) - if(verbose && (str_length(msg) > 0)) warning(msg) + if(verbose) { + if(!is.null(msg1) && (str_length(msg1) > 0)) + message(msg1) + if(!is.null(msg2) && (str_length(msg2) > 0)) + message(msg2) + } check3 <- !any(class(out) == "error") } diff --git a/rkeops/R/rkeops_options.R b/rkeops/R/rkeops_options.R index 495ffe0da..f56c52fe8 100644 --- a/rkeops/R/rkeops_options.R +++ b/rkeops/R/rkeops_options.R @@ -1,5 +1,4 @@ #' Define a list of options for `rkeops` package -#' @keywords internal #' #' @description #' `rkeops` operators requires specific options to manage their compilation @@ -57,6 +56,7 @@ #' associated with a LazyTensor reductions, instead of doing the actual #' computation. Default is `FALSE`, should be set to `TRUE` for debugging #' purpose only. +#' @param warn boolean flag to enable/disable warnings in function call. #' #' @return a list (of class `rkeops_options`) with the following containing #' named values corresponding to the function input parameters. @@ -67,13 +67,19 @@ #' [rkeops::get_rkeops_cache_dir()], [rkeops::set_rkeops_cache_dir()]. #' #' @importFrom tibble lst -#' @importFrom checkmate assert_choice assert_directory assert_flag +#' @importFrom checkmate assert_choice test_directory assert_flag #' assert_integerish qassert +#' @importFrom stringr str_glue str_c +#' @examples +#' def_rkeops_options() +#' +#' @export def_rkeops_options <- function( backend = "CPU", device_id = -1, precision = "float32", verbosity = TRUE, debug = FALSE, cache_dir = NULL, - formula_only = FALSE + formula_only = FALSE, + warn = TRUE ) { # check input assert_choice(backend, c("CPU", "GPU")) @@ -83,16 +89,23 @@ def_rkeops_options <- function( qassert(debug, c("B1", "X[0,1]")) assert_string(cache_dir, null.ok = TRUE) assert_flag(formula_only) + assert_flag(warn) # cast input device_id <- as.integer(device_id) verbosity <- as.integer(verbosity) debug <- as.integer(debug) - # build dir + # cache dir if(is.null(cache_dir)) { cache_dir <- default_rkeops_cache_dir() - } else { - assert_directory(cache_dir, "rw") + } else if(!test_directory(cache_dir, "rw")) { + msg <- str_glue(str_c( + "Input directory `{cache_dir}` for cache directory", + "does not exist and will be created at computing time.", + sep = " " + )) + if(warn) warning(msg) } + # output out <- lst( backend, device_id, precision, verbosity, debug, cache_dir, @@ -188,7 +201,7 @@ get_rkeops_options <- function(option = NULL) { return(out) } -#' Get or set the current `rkeops` options in `R` global options scope +#' Set the current `rkeops` options in `R` global options scope #' #' @description #' `rkeops` operators requires specific options to manage their compilation @@ -247,6 +260,10 @@ get_rkeops_options <- function(option = NULL) { #' @examples #' set_rkeops_options() #' set_rkeops_options(list(verbosity = 0)) +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() +#' } #' #' @export set_rkeops_options <- function(input = NULL) { @@ -274,7 +291,8 @@ set_rkeops_options <- function(input = NULL) { input <- c( input, current_rkeops_options[ - setdiff(names(current_rkeops_options), names(input))] + setdiff(names(current_rkeops_options), names(input)) + ] ) } @@ -321,8 +339,10 @@ set_rkeops_options <- function(input = NULL) { #' @importFrom checkmate qassert #' #' @examples -#' \dontrun{ #' rkeops_use_gpu() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_use_gpu <- function(device = -1) { @@ -366,8 +386,10 @@ rkeops_use_gpu <- function(device = -1) { #' @importFrom checkmate assert_count test_null #' #' @examples -#' \dontrun{ #' rkeops_use_cpu() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_use_cpu <- function(ncore = NULL) { @@ -411,8 +433,10 @@ rkeops_use_cpu <- function(ncore = NULL) { #' @seealso [rkeops::rkeops_use_float64()], [rkeops::set_rkeops_options()] #' #' @examples -#' \dontrun{ #' rkeops_use_float32() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_use_float32 <- function() { @@ -442,8 +466,10 @@ rkeops_use_float32 <- function() { #' @seealso [rkeops::rkeops_use_float32()], [rkeops::set_rkeops_options()] #' #' @examples -#' \dontrun{ #' rkeops_use_float64() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_use_float64 <- function() { @@ -462,8 +488,10 @@ rkeops_use_float64 <- function() { #' @seealso [rkeops::rkeops_disable_verbosity()], [rkeops::set_rkeops_options()] #' #' @examples -#' \dontrun{ #' rkeops_enable_verbosity() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_enable_verbosity <- function() { @@ -482,8 +510,10 @@ rkeops_enable_verbosity <- function() { #' @seealso [rkeops::rkeops_enable_verbosity()], [rkeops::set_rkeops_options()] #' #' @examples -#' \dontrun{ #' rkeops_disable_verbosity() +#' \dontshow{ +#' # set options back to default +#' set_rkeops_options() #' } #' @export rkeops_disable_verbosity <- function() { @@ -526,9 +556,7 @@ rkeops_disable_verbosity <- function() { #' [rkeops::clean_rkeops()] #' #' @examples -#' \dontrun{ #' get_rkeops_cache_dir() -#' } #' @export get_rkeops_cache_dir <- function() { return(get_rkeops_options("cache_dir")) @@ -560,7 +588,11 @@ get_rkeops_cache_dir <- function() { #' **Note:** see [rkeops::default_rkeops_cache_dir()] for more details about #' the default rkeops cache directory. #' -#' @inheritParams def_rkeops_options +#' @param cache_dir string, path to cache directory where rkeops operator +#' compilation byproducts will be stored to be re-used for further use (and +#' avoid unnecessary recompilation). Default is `NULL` and default build +#' directory (see [rkeops::default_rkeops_cache_dir()] is used. Otherwise +#' `cache_dir` should be an existing writable directory on the system. #' @param verbose logical, enables verbosity or not. Default is `TRUE`. #' @return None #' @@ -568,21 +600,33 @@ get_rkeops_cache_dir <- function() { #' #' @importFrom tibble lst #' @importFrom checkmate assert_directory assert_flag -#' @importFrom stringr str_c +#' @importFrom stringr str_c str_glue #' #' @seealso [rkeops::get_rkeops_cache_dir()], [rkeops::stat_rkeops_cache_dir()], #' [rkeops::clean_rkeops()] #' #' @examples +#' # use default cache directory +#' set_rkeops_cache_dir() #' \dontrun{ -#' set_rkeops_build_dir() +#' # edit path at your convenience +#' set_rkeops_cache_dir("/path/to/a/specific/directory") #' } +#' #' @export set_rkeops_cache_dir <- function(cache_dir = NULL, verbose = TRUE) { # check input checkmate::assert_string(cache_dir, null.ok = TRUE) - if(!is.null(cache_dir)) checkmate::assert_directory(cache_dir) checkmate::assert_flag(verbose) + # check cache dir + if(!is.null(cache_dir) && !test_directory(cache_dir, "rw")) { + msg <- str_glue(str_c( + "Input directory `{cache_dir}` for cache directory", + "does not exist and will created at computing time.", + sep = " " + )) + if(verbose) warning(msg) + } # inform the user about the previous cache dir if(verbose) { cache_dir_du <- stat_rkeops_cache_dir(verbose = FALSE) @@ -616,7 +660,6 @@ set_rkeops_cache_dir <- function(cache_dir = NULL, verbose = TRUE) { } #' Default cache directory for RKeOps -#' @keywords internal #' #' @description #' Default value for the path to the cache folder where rkeops operator @@ -652,6 +695,9 @@ set_rkeops_cache_dir <- function(cache_dir = NULL, verbose = TRUE) { #' @importFrom checkmate assert_flag #' #' @return string, path to default rkeops cache directory. +#' @examples +#' default_rkeops_cache_dir(create = FALSE) +#' @export default_rkeops_cache_dir <- function(create = TRUE) { assert_flag(create) diff --git a/rkeops/R/rkeops_utils.R b/rkeops/R/rkeops_utils.R index ac86465ce..04d325d46 100644 --- a/rkeops/R/rkeops_utils.R +++ b/rkeops/R/rkeops_utils.R @@ -36,15 +36,14 @@ #' @importFrom checkmate assert_flag #' #' @examples -#' \dontrun{ #' stat_rkeops_cache_dir() -#' } +#' #' @export stat_rkeops_cache_dir <- function(verbose = TRUE, startup = FALSE) { assert_flag(verbose) assert_flag(startup) cache_dir <- get_rkeops_cache_dir() - dir_du <- stat_dir(cache_dir) + dir_du <- stat_dir(cache_dir, warn = FALSE) if(verbose) { msg <- str_c( str_c("- rkeops cache directory:", cache_dir, sep = " "), @@ -97,14 +96,13 @@ stat_rkeops_cache_dir <- function(verbose = TRUE, startup = FALSE) { #' #' @return None #' -#' @importFrom stringr str_c +#' @importFrom stringr str_c str_glue #' @importFrom checkmate assert_flag #' @importFrom fs dir_exists dir_ls file_delete #' #' @examples -#' \dontrun{ -#' clean_rkeops() -#' } +#' clean_rkeops(remove_cache_dir = TRUE) +#' #' @export clean_rkeops <- function(verbose = TRUE, all = TRUE, remove_cache_dir = FALSE) { # check input @@ -132,18 +130,23 @@ clean_rkeops <- function(verbose = TRUE, all = TRUE, remove_cache_dir = FALSE) { # verbosity msg <- NULL if(all) { - msg <- str_c( - "rkeops cache directory '", cache_dir, "' has been cleaned ", - "and deleted.\n", - "You should restard your R session and reload rkeops after ", - "cleaning." - ) + if(remove_cache_dir) { + msg <- str_glue(str_c( + "rkeops cache directory `{cache_dir}` has been cleaned", + "and deleted.", + sep = " " + )) + } else { + msg <- str_glue( + "rkeops cache directory `{cache_dir}` has been cleaned." + ) + } } else { - msg <- str_c( - "rkeops cache directory '", cache_dir, - "' has been partially cleaned ", - "(only out-dated contents have been removed)." - ) + msg <- str_glue(str_c( + "rkeops cache directory `{cache_dir}` has been partially cleaned", + "(only out-dated contents have been removed).", + sep = " " + )) } if(verbose) msg_warn_error(msg, type = "msg", startup = FALSE) diff --git a/rkeops/R/starting.R b/rkeops/R/starting.R deleted file mode 100644 index 9cb234000..000000000 --- a/rkeops/R/starting.R +++ /dev/null @@ -1,9 +0,0 @@ -#' @title helloWorld -#' @keywords internal -#' @name helloWorld -#' @description dummy function to init package -#' @return None -#' @export -helloWorld <- function() { - print("Hello user of KeOps") -} diff --git a/rkeops/R/utils.R b/rkeops/R/utils.R index 46fc8db09..b8a865a92 100644 --- a/rkeops/R/utils.R +++ b/rkeops/R/utils.R @@ -7,6 +7,7 @@ #' @return a character string containing the OS name. #' @importFrom stringr str_c str_extract #' @author Ghislain Durif +#' @noRd get_os <- function() { # get OS id given by R os_id <- str_extract(string = R.version$os, @@ -51,6 +52,7 @@ get_os <- function() { #' @author Ghislain Durif #' #' @importFrom checkmate assert_choice assert_string assert_flag +#' @noRd msg_warn_error <- function(msg, type, startup = FALSE) { assert_string(msg) assert_choice(type, c("msg", "warn", "error")) @@ -80,6 +82,7 @@ msg_warn_error <- function(msg, type, startup = FALSE) { #' #' @importFrom checkmate assert_string assert_count #' @importFrom stringi stri_rand_strings +#' @noRd random_varname <- function(prefix = "", len = 5) { checkmate::assert_string(prefix) checkmate::assert_count(len) @@ -114,6 +117,7 @@ random_varname <- function(prefix = "", len = 5) { #' #' @importFrom checkmate assert_count assert_string assert_flag #' @importFrom stringr str_c str_length str_to_lower str_trim +#' @noRd confirm_choice <- function( question = "Are you sure?", default_answer = TRUE, timeout = 20, max_tries = 10) { @@ -165,14 +169,33 @@ confirm_choice <- function( #' #' @param path character string, path to directory for which the disk #' usage will be computed. +#' @param warn bollean flag to enable/disable warning verbosity. #' #' @return character string, a disk usage in (G/M/K)bytes. #' #' @importFrom fs dir_info as_fs_bytes -stat_dir <- function(path) { - dir_size <- as.character(fs::as_fs_bytes(sum(as.numeric( - fs::dir_info(path, recurse = TRUE)$size - )))) +#' @importFrom checkmate assert_string assert_flag test_directory +#' @importFrom stringr str_c str_glue +#' @noRd +stat_dir <- function(path, warn = FALSE) { + # check input + assert_string(path) + assert_flag(warn) + # default results (if directory does not exist) + dir_size <- "0" + # check if directory exists + if(!test_directory(path)) { + if(warn) { + msg <- str_glue(str_c( + "`{path}` directory does not exists." + )) + warning(msg) + } + } else { + dir_size <- as.character(fs::as_fs_bytes(sum(as.numeric( + fs::dir_info(path, recurse = TRUE)$size + )))) + } return(dir_size) } diff --git a/rkeops/R/zzz.R b/rkeops/R/zzz.R index 1fa26cc07..7a8278357 100644 --- a/rkeops/R/zzz.R +++ b/rkeops/R/zzz.R @@ -18,6 +18,7 @@ #' @return the `pykeops` Python module #' @usage NULL #' @format An object of class `python.builtin.module` +#' @noRd pykeops <- NULL .onLoad <- function(libname, pkgname) { @@ -25,6 +26,8 @@ pykeops <- NULL check_os(startup = TRUE) # set up rkeops global options set_rkeops_options() + # setup Python requirements + setup_pyreq() # disable pykeops import verbosity Sys.setenv("PYKEOPS_VERBOSE" = "0") if(reticulate::py_available()) diff --git a/rkeops/README.md b/rkeops/README.md index e3c1a71c2..f31322551 100644 --- a/rkeops/README.md +++ b/rkeops/README.md @@ -27,10 +27,10 @@ tracker](https://github.com/getkeops/keops/issues)! **Core library - KeOps, PyKeOps, KeOpsLab:** -- [Benjamin Charlier](https://imag.umontpellier.fr/~charlier/), from the +- [Benjamin Charlier](https://miat.inrae.fr/bcharlier/), from the University of Montpellier. - [Jean Feydy](https://www.jeanfeydy.com), from Inria. -- [Joan Alexis Glaunès](http://helios.mi.parisdescartes.fr/~glaunes/), +- [Joan Alexis Glaunès](https://helios2.mi.parisdescartes.fr/~glaunes/), from the University of Paris. **R bindings - RKeOps:** @@ -41,7 +41,7 @@ tracker](https://github.com/getkeops/keops/issues)! **Contributors:** -- [François-David Collin](https://github.com/fradav), from the +- [François-David Collin](https://fradav.perso.math.cnrs.fr/), from the University of Montpellier: Tensordot operation, CI setup. - [Tanguy Lefort](https://github.com/tanglef), from the University of Montpellier: conjugate gradient solver. @@ -49,8 +49,8 @@ tracker](https://github.com/getkeops/keops/issues)! setup. - [Benoît Martin](https://github.com/benoitmartin88), from the Aramis Inria team: multi-GPU support. -- [Francis Williams](https://www.fwilliams.info), from New York - University: maths operations. +- [Francis Williams](https://fwilliams.info/), from New York University: + maths operations. - [Kshiteej Kalambarkar](https://github.com/kshitij12345), from Quansight: maths operations. - [D. J. Sutherland](https://djsutherland.ml), from the TTI-Chicago: bug @@ -201,15 +201,12 @@ remotes::install_github("getkeops/keops", subdir = "rkeops") ``` r # load rkeops library(rkeops) -# create a dedicated Python environment with reticulate (!!to be done only once) -reticulate::virtualenv_create("rkeops") -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -# install rkeops requirements (!!to be done only once) -install_rkeops() +# check rkeops setup +check_rkeops() ``` -For more details, see the specific **“Using RKeOps” +**Important:** for more details (especially in case of problems), see +the specific **“Using RKeOps” [article](https://www.kernel-operations.io/rkeops/articles/using_rkeops.html)** or the corresponding vignette: diff --git a/rkeops/recipe.md b/rkeops/README_dev.md similarity index 86% rename from rkeops/recipe.md rename to rkeops/README_dev.md index 2a093d5da..bdc27ce96 100644 --- a/rkeops/recipe.md +++ b/rkeops/README_dev.md @@ -5,6 +5,10 @@ You can either use Rstudio machinery with the [attached](#rstudio) Rstudio project file, or use R commands and follow the recipe described [below](#r-command-tools). +## Development pipeline + +Refer to [`dev_history.Rmd`](dev_history.Rmd) for information and details about RKeOps pipeline development. + ## Set up environment ### Set up a CRAN repository @@ -31,10 +35,6 @@ apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev install.packages("devtools") ``` -## Development pipeline - -Refer to [`dev_history.Rmd`](dev_history.Rmd) for information and details about RKeOps pipeline development. - ## Continuous Integration (CI) See the [dedicated file](./ci/README.md) for more details. @@ -46,6 +46,15 @@ should be defined with the value `1` before running the CI scripts, i.e. ```bash export TEST_GPU=1 ``` +To run all tests (including all computation tests), the environment variable +`RUN_LONG_TEST` should be defined with the value `1` before running the +CI scripts, i.e. +```bash +export RUN_LONG_TEST=1 +``` + +**Note**: some tests are skipped by default to avoid consumming too much +resources during package checks on CRAN. ## Documentation and webpage generation @@ -92,6 +101,8 @@ devtools::load_all(pkg_dir) devtools::document(pkg_dir, roclets = c('rd', 'collate', 'namespace', 'vignette')) ``` +**Note:** internal functions have a `@noRd` tag in their documentation chunk to avoid generating man pages. + ### Package build and check ```R @@ -126,4 +137,5 @@ For submission on CRAN, visit . ### Vignette creation You can compile vignettes (in `rkeops/vignettes`) directly in Rstudio or -in R command line with the package knitr. +in R command line with the package knitr (c.f. +[`dev_history.Rmd`](dev_history.Rmd)). diff --git a/rkeops/_pkgdown.yml b/rkeops/_pkgdown.yml index c360679b7..11cc57c48 100644 --- a/rkeops/_pkgdown.yml +++ b/rkeops/_pkgdown.yml @@ -15,8 +15,6 @@ home: navbar: type: default left: - - text: Intro - href: articles/introduction_to_rkeops.html - text: Getting started href: articles/using_rkeops.html - text: Reference diff --git a/rkeops/benchmarks/benchmark_rr2023_gaussian.R b/rkeops/benchmarks/benchmark_rr2023_gaussian.R index a1dfed2bd..188444192 100644 --- a/rkeops/benchmarks/benchmark_rr2023_gaussian.R +++ b/rkeops/benchmarks/benchmark_rr2023_gaussian.R @@ -101,7 +101,7 @@ bench_gaussian <- function(N, D, n_rep = 10) { ) write.table( res, file = paste0("res_benchmark_gaussian_N_", as.integer(N), ".csv"), - \row.names = FALSE, col.names = TRUE) + row.names = FALSE, col.names = TRUE) return(res) } diff --git a/rkeops/ci/run_check.R b/rkeops/ci/run_check.R index 00aa26742..3986f4f46 100644 --- a/rkeops/ci/run_check.R +++ b/rkeops/ci/run_check.R @@ -9,19 +9,8 @@ withr::with_temp_libpaths({ devtools::load_all(pkg_dir) # reticulate config - envname <- "rkeops-ci" - if(reticulate::virtualenv_exists(envname)) - reticulate::virtualenv_remove(envname, confirm = FALSE) - reticulate::virtualenv_create(envname) - reticulate::use_virtualenv(virtualenv = envname, required = TRUE) reticulate::py_config() - # install requirements - install_rkeops() - - # check - check_rkeops() - # run check devtools::check(pkg_dir, error_on = "error") }) \ No newline at end of file diff --git a/rkeops/ci/run_tests.R b/rkeops/ci/run_tests.R index 28c161980..ba740d725 100644 --- a/rkeops/ci/run_tests.R +++ b/rkeops/ci/run_tests.R @@ -9,19 +9,8 @@ withr::with_temp_libpaths({ devtools::load_all(pkg_dir) # reticulate config - envname <- "rkeops-ci" - if(reticulate::virtualenv_exists(envname)) - reticulate::virtualenv_remove(envname, confirm = FALSE) - reticulate::virtualenv_create(envname) - reticulate::use_virtualenv(virtualenv = envname, required = TRUE) reticulate::py_config() - # install requirements - install_rkeops() - - # check - check_rkeops() - # run tests devtools::test(pkg_dir, reporter = c('Progress', 'fail')) }) diff --git a/rkeops/dev/test_gaussian_kernel.R b/rkeops/dev/test_gaussian_kernel.R new file mode 100644 index 000000000..463933f70 --- /dev/null +++ b/rkeops/dev/test_gaussian_kernel.R @@ -0,0 +1,41 @@ +# set working dir to `./rkeops` beforehand +# (see `./rkeops/dev_history.Rmd` for that) + +# load +devtools::load_all() + +# check rkeops setup +check_rkeops() + +# Data +M <- 10000 +N <- 15000 +x <- matrix(runif(M * 3), nrow = M, ncol = 3) # arbitrary R matrix representing +# 10000 data points in R^3 +y <- matrix(runif(N * 3), nrow = N, ncol = 3) # arbitrary R matrix representing +# 15000 data points in R^3 +s <- 0.1 # scale parameter + +# Turn our Tensors into KeOps symbolic variables: +x_i <- LazyTensor(x, "i") # symbolic object representing an arbitrary row + # of x, indexed by the letter "i" +y_j <- LazyTensor(y, "j") # symbolic object representing an arbitrary row + # of y, indexed by the letter "j" + +# Perform large-scale computations, without memory overflows: +D_ij <- sum((x_i - y_j)^2) # symbolic matrix of pairwise squared distances, + # with 10000 rows and 15000 columns + +K_ij <- exp(- D_ij / s^2) # symbolic matrix, 10000 rows and 15000 columns + +# D_ij and K_ij are only symbolic at that point, no computation is done + +# Computing the result without storing D_ij and K_ij: +a_j <- sum(K_ij, index = "i") # actual R matrix (in fact a row vector of + # length 15000 here) + # containing the column sums of K_ij + # (i.e. the sums over the "i" index, for each + # "j" index) + +# clean +clean_rkeops(remove_cache_dir = TRUE) diff --git a/rkeops/dev_history.Rmd b/rkeops/dev_history.Rmd index 371eff9a2..faa489329 100644 --- a/rkeops/dev_history.Rmd +++ b/rkeops/dev_history.Rmd @@ -16,24 +16,20 @@ usethis::proj_set(pkg_dir, force = TRUE) usethis::proj_sitrep() ``` -## Reticulate config +## Reticulate config (use only if issue with Python) ```{r dev-reticulate} -# create virtualenv -reticulate::virtualenv_create("rkeops-dev") -# install pykeops -reticulate::virtualenv_install("rkeops-dev", "pykeops") -# activate python environment -reticulate::use_virtualenv(virtualenv = "rkeops-dev", required = TRUE) +# choose a python version +reticulate::py_require(packages="pykeops", python_version="3.12") # check Python config reticulate::py_config() ``` ## Package development -### Metadata +### Metadata (do not run if no modification) -:warning: Code chunk in this section should be run only once. :warning: +:warning: Code chunk in this section should be run only if something is modified. :warning: ```{r dev-metadata} # description @@ -124,6 +120,7 @@ usethis::use_package("ggplot2", type = "Suggests") usethis::use_package("dplyr", type = "Suggests") usethis::use_package("pracma", type = "Suggests") usethis::use_package("plotly", type = "Suggests") +usethis::use_package("remotes", type = "Suggests") usethis::use_package("reshape", type = "Suggests") ``` @@ -140,11 +137,19 @@ devtools::build_vignettes(pkg_dir) pkgdown::build_site(pkg = pkg_dir) ``` -### Test and check +### Test and checkS + +```{r dev-req} +library(tictoc) +``` ```{r dev-test} # run the unit tests +Sys.setenv(TEST_GPU = 1) +Sys.setenv(RUN_LONG_TEST = 1) +tic("Unit tests run") devtools::test(pkg_dir) +toc() ``` ```{r dev-cov} @@ -155,10 +160,23 @@ covr::zero_coverage(cov) ```{r dev-check-doc} # check the package doc +tic("Man page check") devtools::check_man(pkg_dir) +toc() +``` + +```{r dev-examples} +# Run examples +tic("Example run") +devtools::run_examples(pkg_dir, fresh = TRUE, run_donttest = TRUE) +toc() ``` ```{r dev-check} # fully check the package +Sys.setenv(TEST_GPU = 0) +Sys.setenv(RUN_LONG_TEST = 0) +tic("Package check") devtools::check(pkg_dir) +toc() ``` diff --git a/rkeops/man/Arg.LazyTensor.Rd b/rkeops/man/Arg.LazyTensor.Rd index 150e49a5f..cc53216a9 100644 --- a/rkeops/man/Arg.LazyTensor.Rd +++ b/rkeops/man/Arg.LazyTensor.Rd @@ -29,12 +29,10 @@ part of complex \code{z}. a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Arg_z <- Arg(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Arg]{Arg()}} } diff --git a/rkeops/man/Arg.Rd b/rkeops/man/Arg.Rd index d5cdb3e2b..76f3aba61 100644 --- a/rkeops/man/Arg.Rd +++ b/rkeops/man/Arg.Rd @@ -22,7 +22,6 @@ If \code{z} is a \code{LazyTensor}, see \code{\link[=Arg.LazyTensor]{Arg.LazyTen see \code{\link[=Arg.default]{Arg.default()}}. } \examples{ -\dontrun{ # R base operation Arg(1) Arg(1+1i) @@ -31,7 +30,6 @@ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Arg_z <- Arg(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Arg.default]{Arg.default()}}, \code{\link[=Arg.LazyTensor]{Arg.LazyTensor()}}, \code{\link[=Re]{Re()}}, \code{\link[=Im]{Im()}}, \code{\link[=Mod]{Mod()}}, \code{\link[=Conj]{Conj()}} diff --git a/rkeops/man/Conj.LazyTensor.Rd b/rkeops/man/Conj.LazyTensor.Rd index 136c0f17a..841736d02 100644 --- a/rkeops/man/Conj.LazyTensor.Rd +++ b/rkeops/man/Conj.LazyTensor.Rd @@ -29,12 +29,10 @@ conjugate of \code{z}. a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor Conj_z_i <- Conj(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Conj]{Conj()}} } diff --git a/rkeops/man/Conj.Rd b/rkeops/man/Conj.Rd index 8ab161776..abe6503e3 100644 --- a/rkeops/man/Conj.Rd +++ b/rkeops/man/Conj.Rd @@ -22,7 +22,6 @@ If \code{z} is a \code{LazyTensor}, see \code{\link[=Conj.LazyTensor]{Conj.LazyT see \code{\link[=Conj.default]{Conj.default()}}. } \examples{ -\dontrun{ # R base operation Conj(1) Conj(1+1i) @@ -31,7 +30,6 @@ z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor Conj_z_i <- Conj(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Conj.default]{Conj.default()}}, \code{\link[=Conj.LazyTensor]{Conj.LazyTensor()}}, \code{\link[=Re]{Re()}}, \code{\link[=Im]{Im()}}, \code{\link[=Arg]{Arg()}}, \code{\link[=Mod]{Mod()}} diff --git a/rkeops/man/Im.LazyTensor.Rd b/rkeops/man/Im.LazyTensor.Rd index ded9ea7e5..fb97f28bc 100644 --- a/rkeops/man/Im.LazyTensor.Rd +++ b/rkeops/man/Im.LazyTensor.Rd @@ -29,12 +29,10 @@ part of complex \code{z}. a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Im_z <- Im(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Im]{Im()}} } diff --git a/rkeops/man/Im.Rd b/rkeops/man/Im.Rd index a1e1f64a4..ae904b118 100644 --- a/rkeops/man/Im.Rd +++ b/rkeops/man/Im.Rd @@ -22,7 +22,6 @@ If \code{z} is a \code{LazyTensor}, see \code{\link[=Im.LazyTensor]{Im.LazyTenso see \code{\link[=Im.default]{Im.default()}}. } \examples{ -\dontrun{ # R base operation Im(1) Im(1+1i) @@ -31,7 +30,6 @@ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Im_z <- Im(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Im.default]{Im.default()}}, \code{\link[=Im.LazyTensor]{Im.LazyTensor()}}, \code{\link[=Re]{Re()}}, \code{\link[=Arg]{Arg()}}, \code{\link[=Mod]{Mod()}}, \code{\link[=Conj]{Conj()}} diff --git a/rkeops/man/Kmin.Rd b/rkeops/man/Kmin.Rd index fcae6ba12..31d9cc637 100644 --- a/rkeops/man/Kmin.Rd +++ b/rkeops/man/Kmin.Rd @@ -40,17 +40,39 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' K <- 2 kmin_x <- Kmin(x_i, K, "i") # Kmin reduction, over the 'i' indices +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' K <- 2 kmin_red_x <- Kmin_reduction(x_i, K, "i") # Kmin reduction, indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/Kmin_argKmin.Rd b/rkeops/man/Kmin_argKmin.Rd index 206e69839..09cfa9de3 100644 --- a/rkeops/man/Kmin_argKmin.Rd +++ b/rkeops/man/Kmin_argKmin.Rd @@ -40,7 +40,14 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' @@ -48,8 +55,19 @@ K <- 2 k_argk_x <- Kmin_argKmin(x_i, K, "i") # Kmin-argKmin reduction # indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, # indexed by 'i' @@ -57,6 +75,10 @@ x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, K <- 2 k_argk_x <- Kmin_argKmin_reduction(x_i, K, "i") # Kmin-argKmin reduction # over the "i" indices +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/LazyTensor.Rd b/rkeops/man/LazyTensor.Rd index 3a5e31ada..1cb9b6772 100644 --- a/rkeops/man/LazyTensor.Rd +++ b/rkeops/man/LazyTensor.Rd @@ -71,7 +71,14 @@ Run \code{browseVignettes("rkeops")} to access the vignettes and see how to use \code{LazyTensors}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # Data nx <- 100 ny <- 150 @@ -102,7 +109,10 @@ res <- sum(K_ij, index = "i") # actual R matrix (in fact a row vector of z <- matrix(1i^ (-6:5), nrow = 4) # create a complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # create a ComplexLazyTensor, # indexed by 'i' - +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/Mod.LazyTensor.Rd b/rkeops/man/Mod.LazyTensor.Rd index b816c150e..5018bef3e 100644 --- a/rkeops/man/Mod.LazyTensor.Rd +++ b/rkeops/man/Mod.LazyTensor.Rd @@ -31,12 +31,10 @@ a \code{ComplexLazyTensor}. \strong{Warning}: Do not confuse with \code{\link[=mod]{mod()}}. } \examples{ -\dontrun{ z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor Mod_z_i <- Mod(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Mod]{Mod()}} } diff --git a/rkeops/man/Mod.Rd b/rkeops/man/Mod.Rd index d3a8f104d..e4bfe8672 100644 --- a/rkeops/man/Mod.Rd +++ b/rkeops/man/Mod.Rd @@ -24,7 +24,6 @@ see \code{\link[=Mod.default]{Mod.default()}}. \strong{Warning}: Do not confuse with \code{\link[=mod]{mod()}}. } \examples{ -\dontrun{ # R base operation Mod(1) Mod(1+1i) @@ -33,7 +32,6 @@ z <- matrix(1i^ (-6:5), nrow = 4) # complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor Mod_z_i <- Mod(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Mod.default]{Mod.default()}}, \code{\link[=Mod.LazyTensor]{Mod.LazyTensor()}}, \code{\link[=Re]{Re()}}, \code{\link[=Im]{Im()}}, \code{\link[=Arg]{Arg()}}, \code{\link[=Conj]{Conj()}} diff --git a/rkeops/man/Pm.Rd b/rkeops/man/Pm.Rd index 481ac4615..54902bad1 100644 --- a/rkeops/man/Pm.Rd +++ b/rkeops/man/Pm.Rd @@ -25,11 +25,9 @@ Equivalent to \code{LazyTensor(x)}. See \code{?LazyTensor} for more details. } \examples{ -\dontrun{ x <- 4 Pm_x <- Pm(x) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/Re.LazyTensor.Rd b/rkeops/man/Re.LazyTensor.Rd index ffefa44b9..43caca365 100644 --- a/rkeops/man/Re.LazyTensor.Rd +++ b/rkeops/man/Re.LazyTensor.Rd @@ -29,12 +29,10 @@ of complex \code{z}. a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Re_z <- Re(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Re]{Re()}} } diff --git a/rkeops/man/Re.Rd b/rkeops/man/Re.Rd index a0cc828e2..a9b0140d9 100644 --- a/rkeops/man/Re.Rd +++ b/rkeops/man/Re.Rd @@ -21,7 +21,6 @@ If \code{z} is a \code{ComplexLazyTensor}, see \code{\link[=Re.LazyTensor]{Re.LazyTensor()}}, else see \code{\link[=Re.default]{Re.default()}}. } \examples{ -\dontrun{ # R base operation Re(1) Re(1+1i) @@ -30,7 +29,6 @@ z <- matrix(2 + 1i^ (-6:5), nrow = 4) # complex matrix z_i <- LazyTensor(z, "i", is_complex = TRUE) # creating ComplexLazyTensor Re_z <- Re(z_i) # symbolic matrix } -} \seealso{ \code{\link[=Re.default]{Re.default()}}, \code{\link[=Re.LazyTensor]{Re.LazyTensor()}}, \code{\link[=Im]{Im()}}, \code{\link[=Arg]{Arg()}}, \code{\link[=Mod]{Mod()}}, \code{\link[=Conj]{Conj()}} diff --git a/rkeops/man/ScalarProduct.or.OR.Rd b/rkeops/man/ScalarProduct.or.OR.Rd index 8b099e989..05b4323ba 100644 --- a/rkeops/man/ScalarProduct.or.OR.Rd +++ b/rkeops/man/ScalarProduct.or.OR.Rd @@ -23,7 +23,6 @@ If \code{x} or \code{y} is a \code{LazyTensor}, see \code{\link[=|.LazyTensor]{| \code{\link[=|.default]{|.default()}}. } \examples{ -\dontrun{ # R base element-wise logical or operation TRUE | FALSE x <- 1:10 @@ -38,7 +37,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, x_sp_y <- x_i | y_j # symbolic matrix } -} \seealso{ \code{\link[=|.default]{|.default()}}, \code{\link[=|.LazyTensor]{|.LazyTensor()}} } diff --git a/rkeops/man/Vi.Rd b/rkeops/man/Vi.Rd index 61c498be5..3d7361208 100644 --- a/rkeops/man/Vi.Rd +++ b/rkeops/man/Vi.Rd @@ -25,12 +25,10 @@ Equivalent to \code{LazyTensor(x, index = "i")}. See \code{?LazyTensor} for more details. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) Vi_x <- Vi(x) # symbolic object representing an arbitrary row of x, # indexed by the letter "i" } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/Vj.Rd b/rkeops/man/Vj.Rd index 512a85fc5..9ff705fc1 100644 --- a/rkeops/man/Vj.Rd +++ b/rkeops/man/Vj.Rd @@ -24,12 +24,10 @@ Equivalent to \code{LazyTensor(x, index = "j")}. See \code{?LazyTensor} for more details. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) Vj_x <- Vj(x) # symbolic object representing an arbitrary row of x, # indexed by the letter "j" } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/abs.LazyTensor.Rd b/rkeops/man/abs.LazyTensor.Rd index c79432764..6c5056d0d 100644 --- a/rkeops/man/abs.LazyTensor.Rd +++ b/rkeops/man/abs.LazyTensor.Rd @@ -29,14 +29,12 @@ encodes, symbolically, the complex absolute value or modulus of \code{x}, i.e. \code{abs(x) = Mod(x)}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Abs_x <- abs(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=abs]{abs()}}, \code{\link[=Mod]{Mod()}} } diff --git a/rkeops/man/abs.Rd b/rkeops/man/abs.Rd index a8b6fa34a..9c0a97129 100644 --- a/rkeops/man/abs.Rd +++ b/rkeops/man/abs.Rd @@ -25,7 +25,6 @@ see \code{\link[=abs.default]{abs.default()}}. corresponds to the complex modulus \code{abs(z) = Mod(z)}. } \examples{ -\dontrun{ # R base operation abs(5) abs(-5) @@ -36,7 +35,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Abs_x <- abs(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=abs.default]{abs.default()}}, \code{\link[=abs.LazyTensor]{abs.LazyTensor()}}, \code{\link[=Mod.default]{Mod.default()}}, \code{\link[=Mod.LazyTensor]{Mod.LazyTensor()}} diff --git a/rkeops/man/acos.LazyTensor.Rd b/rkeops/man/acos.LazyTensor.Rd index 21b4f6d01..9a7ff24ce 100644 --- a/rkeops/man/acos.LazyTensor.Rd +++ b/rkeops/man/acos.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{acos(x)} returns a \code{LazyTensor} t encodes, symbolically, the element-wise arc-cosine of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Acos_x <- acos(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=acos]{acos()}} } diff --git a/rkeops/man/acos.Rd b/rkeops/man/acos.Rd index 9bb6e4b99..182cbc60c 100644 --- a/rkeops/man/acos.Rd +++ b/rkeops/man/acos.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=acos.LazyTensor]{acos.LazyT see \code{\link[=acos.default]{acos.default()}}. } \examples{ -\dontrun{ # R base operation acos(0) acos(-1) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Acos_x <- acos(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=acos.default]{acos.default()}}, \code{\link[=acos.LazyTensor]{acos.LazyTensor()}} } diff --git a/rkeops/man/argKmin.Rd b/rkeops/man/argKmin.Rd index 25762584b..57332f593 100644 --- a/rkeops/man/argKmin.Rd +++ b/rkeops/man/argKmin.Rd @@ -40,7 +40,14 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' @@ -48,14 +55,29 @@ K <- 2 argkmin_x <- argKmin(x_i, K, "i") # argKmin reduction # indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' K <- 2 argkmin_red_x <- argKmin_reduction(x_i, K, "i") # argKmin reduction # indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/argmax.Rd b/rkeops/man/argmax.Rd index 492e3503f..1103ed74d 100644 --- a/rkeops/man/argmax.Rd +++ b/rkeops/man/argmax.Rd @@ -44,20 +44,42 @@ section \emph{"Reductions"}. \code{argmax_reduction()} function. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' argmax_xi <- argmax(x_i, "i") # argmax reduction indexed by 'i' argmax_x <- argmax(x_i) # symbolic matrix +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' argmax_red <- argmax_reduction(x_i, "i") # argmax reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/argmin.Rd b/rkeops/man/argmin.Rd index ea79d1bb5..99311376e 100644 --- a/rkeops/man/argmin.Rd +++ b/rkeops/man/argmin.Rd @@ -44,20 +44,42 @@ section \emph{"Reductions"}. \code{argmin_reduction()} function. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' argmin_xi <- argmin(x_i, "i") # argmin reduction indexed by 'i' argmin_x <- argmin(x_i) # symbolic matrix +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' argmin_red <- argmin(x_i, "i") # argmin reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/arithmetic.add.LazyTensor.Rd b/rkeops/man/arithmetic.add.LazyTensor.Rd index 69766b158..2f3f2959c 100644 --- a/rkeops/man/arithmetic.add.LazyTensor.Rd +++ b/rkeops/man/arithmetic.add.LazyTensor.Rd @@ -34,7 +34,6 @@ to \code{LazyTensor}). or be of dimension 1. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -43,7 +42,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' Sum_xy <- x_i + y_j # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=+]{+()}} } diff --git a/rkeops/man/arithmetic.add.Rd b/rkeops/man/arithmetic.add.Rd index 8e70695f2..5a1fa038e 100644 --- a/rkeops/man/arithmetic.add.Rd +++ b/rkeops/man/arithmetic.add.Rd @@ -30,7 +30,6 @@ or \code{x + y}. } } \examples{ -\dontrun{ # R base operation +5 1 + 3 @@ -43,7 +42,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' Sum_xy <- x_i + y_j # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=+.default]{+.default()}}, \code{\link[=+.LazyTensor]{+.LazyTensor()}}, \code{\link[=+.ComplexLazyTensor]{+.ComplexLazyTensor()}} diff --git a/rkeops/man/arithmetic.divide.LazyTensor.Rd b/rkeops/man/arithmetic.divide.LazyTensor.Rd index abaacb769..5ce2b10af 100644 --- a/rkeops/man/arithmetic.divide.LazyTensor.Rd +++ b/rkeops/man/arithmetic.divide.LazyTensor.Rd @@ -30,7 +30,6 @@ to \code{LazyTensor}). or be of dimension 1. } \examples{ -\dontrun{ # LazyTensor symbolic division x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns @@ -40,7 +39,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_div_y <- x_i / y_j # symbolic matrix } -} \seealso{ \code{\link[=/]{/()}} } diff --git a/rkeops/man/arithmetic.divide.Rd b/rkeops/man/arithmetic.divide.Rd index 27c2796a4..81b81f961 100644 --- a/rkeops/man/arithmetic.divide.Rd +++ b/rkeops/man/arithmetic.divide.Rd @@ -22,7 +22,6 @@ If \code{x} or \code{y} is a \code{LazyTensor}, see \code{\link[=/.LazyTensor]{/ \code{\link[=/.default]{/.default()}}. } \examples{ -\dontrun{ # R base operation +5 1 + 3 @@ -35,7 +34,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_div_y <- x_i / y_j # symbolic matrix } -} \seealso{ \code{\link[=/.default]{/.default()}}, \code{\link[=/.LazyTensor]{/.LazyTensor()}}, \code{\link[=/.ComplexLazyTensor]{/.ComplexLazyTensor()}} diff --git a/rkeops/man/arithmetic.multiply.LazyTensor.Rd b/rkeops/man/arithmetic.multiply.LazyTensor.Rd index 2fdb4d3c2..536b890cc 100644 --- a/rkeops/man/arithmetic.multiply.LazyTensor.Rd +++ b/rkeops/man/arithmetic.multiply.LazyTensor.Rd @@ -30,7 +30,6 @@ to \code{LazyTensor}). or be of dimension 1. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -39,7 +38,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_times_y <- x_i * y_j # symbolic matrix } -} \seealso{ \code{\link[=*]{*()}} } diff --git a/rkeops/man/arithmetic.multiply.Rd b/rkeops/man/arithmetic.multiply.Rd index 5b32f2c77..c8de42baf 100644 --- a/rkeops/man/arithmetic.multiply.Rd +++ b/rkeops/man/arithmetic.multiply.Rd @@ -22,7 +22,6 @@ If \code{x} or \code{y} is a \code{LazyTensor}, see \code{\link[=*.LazyTensor]{* \code{\link[=*.default]{*.default()}}. } \examples{ -\dontrun{ # R base operation +5 1 + 3 @@ -35,7 +34,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_times_y <- x_i * y_j # symbolic matrix } -} \seealso{ \code{\link[=*.default]{*.default()}}, \code{\link[=*.LazyTensor]{*.LazyTensor()}}, \code{\link[=*.ComplexLazyTensor]{*.ComplexLazyTensor()}} diff --git a/rkeops/man/arithmetic.power.LazyTensor.Rd b/rkeops/man/arithmetic.power.LazyTensor.Rd index c772253b1..7d9f608a1 100644 --- a/rkeops/man/arithmetic.power.LazyTensor.Rd +++ b/rkeops/man/arithmetic.power.LazyTensor.Rd @@ -33,7 +33,6 @@ to \code{LazyTensor}). } } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -42,7 +41,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_pow_y <- x_i^y_j # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/arithmetic.power.Rd b/rkeops/man/arithmetic.power.Rd index 489033b93..b7a822e89 100644 --- a/rkeops/man/arithmetic.power.Rd +++ b/rkeops/man/arithmetic.power.Rd @@ -23,7 +23,6 @@ If \code{x} or \code{y} is a \code{LazyTensor}, see \code{\link[=^.LazyTensor]{^ \code{\link[=^.default]{^.default()}}. } \examples{ -\dontrun{ # R base operation 3^2 (1:10)^3 @@ -38,7 +37,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_pow_y <- x_i^y_j # symbolic matrix } -} \seealso{ \code{\link[=^.default]{^.default()}}, \code{\link[=^.LazyTensor]{^.LazyTensor()}} } diff --git a/rkeops/man/arithmetic.subtract.LazyTensor.Rd b/rkeops/man/arithmetic.subtract.LazyTensor.Rd index d2e7ea83f..1826b8f81 100644 --- a/rkeops/man/arithmetic.subtract.LazyTensor.Rd +++ b/rkeops/man/arithmetic.subtract.LazyTensor.Rd @@ -37,7 +37,6 @@ to \code{LazyTensor}). or be of dimension 1. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -47,7 +46,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, Sub_xy <- x_i - y_j # symbolic matrix Minus_x <- -x_i # symbolic matrix } -} \seealso{ \code{\link[=-]{-()}} } diff --git a/rkeops/man/arithmetic.subtract.Rd b/rkeops/man/arithmetic.subtract.Rd index e9f5538e7..a1ad56119 100644 --- a/rkeops/man/arithmetic.subtract.Rd +++ b/rkeops/man/arithmetic.subtract.Rd @@ -27,7 +27,6 @@ implementing the subtraction, or a unary operator, e.g. \code{- x}, implementing the "minus sign", both for \code{LazyTensor} objects or other types. } \examples{ -\dontrun{ # R base operation +5 1 + 3 @@ -41,7 +40,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, Sub_xy <- x_i - y_j # symbolic matrix Minus_x <- -x_i # symbolic matrix } -} \seealso{ \code{\link[=-.default]{-.default()}}, \code{\link[=-.LazyTensor]{-.LazyTensor()}}, \code{\link[=-.ComplexLazyTensor]{-.ComplexLazyTensor()}} diff --git a/rkeops/man/asin.LazyTensor.Rd b/rkeops/man/asin.LazyTensor.Rd index 635046741..7858a5762 100644 --- a/rkeops/man/asin.LazyTensor.Rd +++ b/rkeops/man/asin.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{asin(x)} returns a \code{LazyTensor} t encodes, symbolically, the element-wise arc-sine of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Asin_x <- asin(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=asin]{asin()}} } diff --git a/rkeops/man/asin.Rd b/rkeops/man/asin.Rd index 932a266df..d42a2ef72 100644 --- a/rkeops/man/asin.Rd +++ b/rkeops/man/asin.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=asin.LazyTensor]{asin.LazyT see \code{\link[=asin.default]{asin.default()}}. } \examples{ -\dontrun{ # R base operation asin(0) asin(-1) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Asin_x <- asin(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=asin.default]{asin.default()}}, \code{\link[=asin.LazyTensor]{asin.LazyTensor()}} } diff --git a/rkeops/man/atan.LazyTensor.Rd b/rkeops/man/atan.LazyTensor.Rd index df2c8e948..0350b994d 100644 --- a/rkeops/man/atan.LazyTensor.Rd +++ b/rkeops/man/atan.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{atan(x)} returns a \code{LazyTensor} t encodes, symbolically, the element-wise arc-tangent of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Atan_x <- atan(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=atan]{atan()}} } diff --git a/rkeops/man/atan.Rd b/rkeops/man/atan.Rd index 81ee4f5dd..d6aa5c09e 100644 --- a/rkeops/man/atan.Rd +++ b/rkeops/man/atan.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=atan.LazyTensor]{atan.LazyT see \code{\link[=atan.default]{atan.default()}}. } \examples{ -\dontrun{ # R base operation atan(0) atan(-1) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Atan_x <- atan(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=atan.default]{atan.default()}}, \code{\link[=atan.LazyTensor]{atan.LazyTensor()}} } diff --git a/rkeops/man/atan2.LazyTensor.Rd b/rkeops/man/atan2.LazyTensor.Rd index f6d8df5b9..c4ef6c7d9 100644 --- a/rkeops/man/atan2.LazyTensor.Rd +++ b/rkeops/man/atan2.LazyTensor.Rd @@ -27,7 +27,6 @@ a vector or a scalar, it is first converted to \code{LazyTensor}). \strong{Note}: \code{x} and \code{y} input arguments should have the same inner dimension. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -36,7 +35,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' Atan2_xy <- atan2(x_i, y_j) # symbolic matrix } -} \seealso{ \code{\link[=atan2]{atan2()}} } diff --git a/rkeops/man/atan2.Rd b/rkeops/man/atan2.Rd index 8270d312c..1eefa3caa 100644 --- a/rkeops/man/atan2.Rd +++ b/rkeops/man/atan2.Rd @@ -28,7 +28,6 @@ between the x-axis and the vector from the origin to (x, y), i.e., for positive arguments \code{atan2(y, x) == atan(y/x)}. } \examples{ -\dontrun{ # R base operation atan2(0, 1) atan2(1, 0) @@ -41,7 +40,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' Atan2_xy <- atan2(x_i, y_j) # symbolic matrix } -} \seealso{ \code{\link[=atan2.default]{atan2.default()}}, \code{\link[=atan2.LazyTensor]{atan2.LazyTensor()}} } diff --git a/rkeops/man/binaryop.LazyTensor.Rd b/rkeops/man/binaryop.LazyTensor.Rd index e283f97d0..96bab92eb 100644 --- a/rkeops/man/binaryop.LazyTensor.Rd +++ b/rkeops/man/binaryop.LazyTensor.Rd @@ -55,7 +55,6 @@ An object of class "LazyTensor". Symbolically applies \code{opstr} operation to \code{x} and \code{y}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' @@ -63,7 +62,6 @@ y_j <- LazyTensor(y, index = 'j') # LazyTensor from matrix y, indexed by 'j' # symbolic matrix: bin_xy <- binaryop.LazyTensor(x_i, y_j, "+", is_operator = TRUE) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/check_index.Rd b/rkeops/man/check_index.Rd deleted file mode 100644 index 7d462ab6e..000000000 --- a/rkeops/man/check_index.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{check_index} -\alias{check_index} -\title{Check index.} -\usage{ -check_index(index) -} -\arguments{ -\item{index}{to check.} -} -\value{ -A boolean TRUE or FALSE. -} -\description{ -Checks index for operation. -} -\details{ -\code{check_index(index)} will return a boolean to check if \code{index} is -a character and corresponding to \code{"i"} or \code{"j"}. -\itemize{ -\item if \code{index = "i"}, return \code{TRUE}. -\item if \code{index = "j"}, return \code{TRUE}. -\item else return \code{FALSE}. -} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/check_inner_dim.Rd b/rkeops/man/check_inner_dim.Rd deleted file mode 100644 index 986352ae7..000000000 --- a/rkeops/man/check_inner_dim.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{check_inner_dim} -\alias{check_inner_dim} -\title{Check inner dimensions for binary or ternary operations.} -\usage{ -check_inner_dim(x, y, z = NA, check_type = "sameor1") -} -\arguments{ -\item{x}{A \code{LazyTensor} or a \code{ComplexLazyTensor}.} - -\item{y}{A \code{LazyTensor} or a \code{ComplexLazyTensor}.} - -\item{z}{A \code{LazyTensor} or a \code{ComplexLazyTensor} (optional, default = NA).} - -\item{check_type}{A character string among "same" and "sameor1" (default), -to specify the desired type of inner dimension verification -(see @details section).} -} -\value{ -A boolean TRUE or FALSE. -} -\description{ -Verifies that the inner dimensions of two or three given \code{LazyTensor} -are the same. -} -\details{ -If \code{x} and \code{y} are of class \code{LazyTensor} or \code{ComplexLazyTensor}, -\code{check_inner_dim(x, y, check_type = "same")} returns \code{TRUE} if \code{x} and \code{y} -inner dimensions are the same, and \code{FALSE} otherwise, while -\code{check_inner_dim(x, y, check_type = "sameor1")} returns \code{TRUE} if \code{x} and \code{y} -inner dimensions are the same or if at least one of these equals 1, -and \code{FALSE} otherwise. -Same idea with a third input \code{z}. -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/check_keopscore.Rd b/rkeops/man/check_keopscore.Rd deleted file mode 100644 index f3f6e6190..000000000 --- a/rkeops/man/check_keopscore.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rkeops_check.R -\name{check_keopscore} -\alias{check_keopscore} -\title{Check if \code{keopscore} Python package is available} -\usage{ -check_keopscore(verbose = TRUE) -} -\arguments{ -\item{verbose}{boolean, if TRUE (default), inform user about check result.} -} -\value{ -boolean value indicating if the \code{keopscore} package is available. -} -\description{ -In practice, check if \code{keopscore} Python package is installed (which is done -at \code{rkeops} package install). -} -\examples{ -\dontrun{ -check_keopscore() -} -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/check_os.Rd b/rkeops/man/check_os.Rd deleted file mode 100644 index 863e39757..000000000 --- a/rkeops/man/check_os.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rkeops_check.R -\name{check_os} -\alias{check_os} -\title{Check OS} -\usage{ -check_os(startup = FALSE) -} -\arguments{ -\item{startup}{boolean indicating if the function is used when loading -the package (to avoid the error in this case).} -} -\value{ -a boolean value indicating if check is ok or not. -} -\description{ -This function checks the OS. Only \code{Unix} (Linux and MacOS) are supported -at the moment. Windows is not supported. -} -\details{ -Return 0 if run on Windows and 1 otherwise, with a possible warning. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/check_pykeops.Rd b/rkeops/man/check_pykeops.Rd deleted file mode 100644 index 959c6ca8d..000000000 --- a/rkeops/man/check_pykeops.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rkeops_check.R -\name{check_pykeops} -\alias{check_pykeops} -\title{Check if \code{pykeops} Python package is available} -\usage{ -check_pykeops(verbose = TRUE) -} -\arguments{ -\item{verbose}{boolean, if TRUE (default), inform user about check result.} -} -\value{ -boolean value indicating if the \code{pykeops} package is available. -} -\description{ -In practice, check if \code{pykeops} Python package is installed (which is done -at \code{rkeops} package install). -} -\examples{ -\dontrun{ -check_pykeops() -} -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/check_pypkg.Rd b/rkeops/man/check_pypkg.Rd deleted file mode 100644 index 582da4348..000000000 --- a/rkeops/man/check_pypkg.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rkeops_check.R -\name{check_pypkg} -\alias{check_pypkg} -\title{Check if a given Python package is installed and available.} -\usage{ -check_pypkg(package, verbose = TRUE) -} -\arguments{ -\item{package}{character string, name of package to be checked among -\code{"keopscore"} and \code{"pykeops"}.} - -\item{verbose}{boolean, if TRUE (default), inform user about check result.} -} -\value{ -boolean value indicating if the \code{pykeops} package is available. -} -\description{ -In practice, check if the given Python package is installed (which is -normally done at \code{rkeops} package install). - -Should be used to test the availability of \code{keopscore} and of \code{pykeops} -packages. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/check_rkeops.Rd b/rkeops/man/check_rkeops.Rd index 503cf5b6b..a364bc0a5 100644 --- a/rkeops/man/check_rkeops.Rd +++ b/rkeops/man/check_rkeops.Rd @@ -26,7 +26,7 @@ Under the hood, several verifications are made: } } \examples{ -\dontrun{ +\donttest{ check_rkeops() } } diff --git a/rkeops/man/clamp.Rd b/rkeops/man/clamp.Rd index 8dbf5c2ca..12f6c3abe 100644 --- a/rkeops/man/clamp.Rd +++ b/rkeops/man/clamp.Rd @@ -26,7 +26,6 @@ Broadcasting rules apply. inner dimension as \code{x}. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -42,7 +41,6 @@ z_i <- LazyTensor(z, index = 'i') # call clamp function clp <- clamp(x_i, y_j, z_i) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/clampint.Rd b/rkeops/man/clampint.Rd index a5fd31f40..e278aba33 100644 --- a/rkeops/man/clampint.Rd +++ b/rkeops/man/clampint.Rd @@ -27,7 +27,6 @@ integers. See \code{\link[=clamp]{clamp()}} for more details. Broadcasting rules apply. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -37,7 +36,6 @@ x_i <- LazyTensor(x, index = 'i') # call clampint function clp_int <- clamp(x_i, 7, 2) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/clean_rkeops.Rd b/rkeops/man/clean_rkeops.Rd index f0453e67a..2683f46a8 100644 --- a/rkeops/man/clean_rkeops.Rd +++ b/rkeops/man/clean_rkeops.Rd @@ -42,9 +42,8 @@ directory. Python setup, but \code{clean_rkeops(all = FALSE)} will not. } \examples{ -\dontrun{ -clean_rkeops() -} +clean_rkeops(remove_cache_dir = TRUE) + } \seealso{ \code{\link[=get_rkeops_cache_dir]{get_rkeops_cache_dir()}}, \code{\link[=stat_rkeops_cache_dir]{stat_rkeops_cache_dir()}} diff --git a/rkeops/man/complex.default.Rd b/rkeops/man/complex.default.Rd index 4170c1989..84fd588e4 100644 --- a/rkeops/man/complex.default.Rd +++ b/rkeops/man/complex.default.Rd @@ -23,6 +23,9 @@ \item{z}{an object of mode \code{complex}, or one of a class for which a methods has been defined.} } +\value{ +See 'Details' section. +} \description{ Basic functions which support complex arithmetic in \R, in addition to the arithmetic operators \code{+}, \code{-}, \code{*}, \code{/}, and \code{^}. @@ -111,7 +114,7 @@ NAs <- vapply(list(NA, NA_integer_, NA_real_, NA_character_, NA_complex_), stopifnot(is.na(NAs), is.na(Re(NAs))) # has always been true showC <- function(z) noquote(paste0("(", Re(z), ",", Im(z), ")")) showC(NAs) -Im(NAs) # [0 0 0 NA NA] \\ in R <= 4.3.x was [NA NA 0 NA NA] +Im(NAs) # [0 0 0 NA NA] \\\\ in R <= 4.3.x was [NA NA 0 NA NA] stopifnot(Im(NAs)[1:3] == 0) diff --git a/rkeops/man/concat.Rd b/rkeops/man/concat.Rd index c343f7eab..fd402ba81 100644 --- a/rkeops/man/concat.Rd +++ b/rkeops/man/concat.Rd @@ -24,7 +24,6 @@ If \code{x} and \code{y} are two \code{LazyTensor} or \code{ComplexLazyTensor}, their inner dimension. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' @@ -32,7 +31,6 @@ y_j <- LazyTensor(y, index = 'j') # LazyTensor from matrix x, indexed by 'j' concat_xy <- concat(x_i, y_j) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/confirm_choice.Rd b/rkeops/man/confirm_choice.Rd deleted file mode 100644 index ff58a0274..000000000 --- a/rkeops/man/confirm_choice.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{confirm_choice} -\alias{confirm_choice} -\title{Function to ask for user confirmation} -\usage{ -confirm_choice( - question = "Are you sure?", - default_answer = TRUE, - timeout = 20, - max_tries = 10 -) -} -\arguments{ -\item{question}{character string, the question that is asked to the user.} - -\item{default_answer}{logical, the default answer (if no answer is given).} - -\item{max_tries}{integer, maximum number of repetition of the question in -case of bad user input.} -} -\value{ -a logical \code{TRUE}/\code{FALSE} value depending on user input. -} -\description{ -Return a logical \code{TRUE}/\code{FALSE} value depending on user input. -} -\details{ -In non interactive mode, \code{default_answer} value is returned. - -In interactive mode, the user is asked for a \code{"yes"}/\code{"no"}. If the user -provide any other answer, the question is asked again for -\code{max_tries} times. - -\strong{ATTENTION}: this function may be hung indefinitely if the user does -not provide any input. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/cos.LazyTensor.Rd b/rkeops/man/cos.LazyTensor.Rd index 6241b9f42..858b04cae 100644 --- a/rkeops/man/cos.LazyTensor.Rd +++ b/rkeops/man/cos.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{cos(x)} returns a \code{LazyTensor} th encodes, symbolically, the element-wise cosine of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Cos_x <- cos(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=cos]{cos()}} } diff --git a/rkeops/man/cos.Rd b/rkeops/man/cos.Rd index 7d2a18290..f255351a9 100644 --- a/rkeops/man/cos.Rd +++ b/rkeops/man/cos.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=cos.LazyTensor]{cos.LazyTen see \code{\link[=cos.default]{cos.default()}}. } \examples{ -\dontrun{ # R base operation cos(0) cos(pi) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Cos_x <- cos(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=cos.default]{cos.default()}}, \code{\link[=cos.LazyTensor]{cos.LazyTensor()}} } diff --git a/rkeops/man/cplx_warning.Rd b/rkeops/man/cplx_warning.Rd deleted file mode 100644 index 897b8d9ed..000000000 --- a/rkeops/man/cplx_warning.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{cplx_warning} -\alias{cplx_warning} -\title{Warning for ComplexLazyTensor/LazyTensor operations.} -\usage{ -cplx_warning(warn = TRUE) -} -\value{ -A warning message. -} -\description{ -Returns a warning message when binary operations are used with a -\code{LazyTensor} and a \code{ComplexLazyTensor}. These operations might not work -with the current rkeops version. - -This function is only called in \code{real2complex.LazyTensor}, which is only -used with binary operations involving a \code{LazyTensor} and -a \code{ComplexLazyTensor}. -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/def_rkeops_options.Rd b/rkeops/man/def_rkeops_options.Rd index 5e6f840f5..b7eef181c 100644 --- a/rkeops/man/def_rkeops_options.Rd +++ b/rkeops/man/def_rkeops_options.Rd @@ -11,7 +11,8 @@ def_rkeops_options( verbosity = TRUE, debug = FALSE, cache_dir = NULL, - formula_only = FALSE + formula_only = FALSE, + warn = TRUE ) } \arguments{ @@ -43,6 +44,8 @@ directory (see \code{\link[=default_rkeops_cache_dir]{default_rkeops_cache_dir() associated with a LazyTensor reductions, instead of doing the actual computation. Default is \code{FALSE}, should be set to \code{TRUE} for debugging purpose only.} + +\item{warn}{boolean flag to enable/disable warnings in function call.} } \value{ a list (of class \code{rkeops_options}) with the following containing @@ -79,6 +82,10 @@ manage GPU assignment outside R by setting the environment variable the cache directory where rkeops operator compilation byproducts will be stored to be re-used for further use (and avoid unnecessary recompilation). +} +\examples{ +def_rkeops_options() + } \seealso{ \code{\link[=rkeops_use_float32]{rkeops_use_float32()}}, \code{\link[=rkeops_use_float64]{rkeops_use_float64()}}, @@ -89,4 +96,3 @@ recompilation). \author{ Ghislain Durif } -\keyword{internal} diff --git a/rkeops/man/default.math.fun.Rd b/rkeops/man/default.math.fun.Rd index d36e7e1cd..af89e3978 100644 --- a/rkeops/man/default.math.fun.Rd +++ b/rkeops/man/default.math.fun.Rd @@ -13,6 +13,9 @@ \arguments{ \item{x}{a numeric or \code{\link[base]{complex}} vector or array.} } +\value{ +See 'Details' section. +} \description{ \code{abs(x)} computes the absolute value of x, \code{sqrt(x)} computes the (principal) square root of x, \eqn{\sqrt{x}}.% Details for complex x are below diff --git a/rkeops/man/default_rkeops_cache_dir.Rd b/rkeops/man/default_rkeops_cache_dir.Rd index c0e2be3aa..a2b8c8c3d 100644 --- a/rkeops/man/default_rkeops_cache_dir.Rd +++ b/rkeops/man/default_rkeops_cache_dir.Rd @@ -41,4 +41,6 @@ You can use \code{\link[=stat_rkeops_cache_dir]{stat_rkeops_cache_dir()}} to ver directory disk usage, and you can use \code{\link[=clean_rkeops]{clean_rkeops()}} to (fully or partially) delete its content. } -\keyword{internal} +\examples{ +default_rkeops_cache_dir(create = FALSE) +} diff --git a/rkeops/man/elem.Rd b/rkeops/man/elem.Rd index 5c281ce52..684e15d81 100644 --- a/rkeops/man/elem.Rd +++ b/rkeops/man/elem.Rd @@ -27,14 +27,12 @@ standard R notation. be in \verb{[0, n)}, where \code{n} is the inner dimension of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' m <- 2 elem_x <- elem(x_i, m) # symbolic `m+1`-th element of `x_i`. } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/elemT.Rd b/rkeops/man/elemT.Rd index d62e5e430..c7c3dd8e3 100644 --- a/rkeops/man/elemT.Rd +++ b/rkeops/man/elemT.Rd @@ -34,7 +34,6 @@ value. be in \verb{[0, n)}. } \examples{ -\dontrun{ # basic example x <- 3.14 # arbitrary value Pm_x <- LazyTensor(x) # creating scalar parameter LazyTensor from x @@ -44,7 +43,6 @@ n <- 3 elemT_x <- elemT(Pm_x, m, n) # symbolic vector } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/exp.LazyTensor.Rd b/rkeops/man/exp.LazyTensor.Rd index 1c2a1d622..6e0ccd1d0 100644 --- a/rkeops/man/exp.LazyTensor.Rd +++ b/rkeops/man/exp.LazyTensor.Rd @@ -31,7 +31,6 @@ encodes, symbolically, the element-wise complex exponential of \code{x} } } \examples{ -\dontrun{ # basic example x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -43,7 +42,6 @@ z <- matrix(1i^ (-6:5), nrow = 4) # create a complex 4x3 matrix z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # create a ComplexLazyTensor Exp_z_i <- exp(z_i) # symbolic matrix } -} \seealso{ \code{\link[=exp]{exp()}} } diff --git a/rkeops/man/exp.Rd b/rkeops/man/exp.Rd index 7aeaa7dbf..ae48f56e1 100644 --- a/rkeops/man/exp.Rd +++ b/rkeops/man/exp.Rd @@ -24,7 +24,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=exp.LazyTensor]{exp.LazyTen see \code{\link[=exp.default]{exp.default()}}. } \examples{ -\dontrun{ # R base operation exp(0) exp(1:10) @@ -34,7 +33,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Exp_x <- exp(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=exp.default]{exp.default()}}, \code{\link[=exp.LazyTensor]{exp.LazyTensor()}} } diff --git a/rkeops/man/exp1j.Rd b/rkeops/man/exp1j.Rd index e86193462..422d216f5 100644 --- a/rkeops/man/exp1j.Rd +++ b/rkeops/man/exp1j.Rd @@ -30,13 +30,11 @@ the multiplication of \verb{1j} with \code{x}. a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, # indexed by 'i' z <- exp1j(x_i) # ComplexLazyTensor object } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/extract.Rd b/rkeops/man/extract.Rd index e05bbbb5f..090d548e7 100644 --- a/rkeops/man/extract.Rd +++ b/rkeops/man/extract.Rd @@ -34,7 +34,6 @@ in \verb{[0, n-m]}. use of \code{extract()}. } \examples{ -\dontrun{ # Two very rudimentary examples # ----------------------------- @@ -45,6 +44,10 @@ use of \code{extract()}. # [3,] 3 7 4 5 # [4,] 1 3 3 0 # [5,] 5 4 9 4 +g <- matrix( + c(1, 8, 1, 3, 2, 1, 2, 7, 3, 7, 4, 5, 1, 3, 3, 0, 5, 4, 9, 4), + nrow = 5, ncol = 4, byrow = TRUE +) # Convert it to LazyTensor: g_i <- LazyTensor(g, index = 'i') @@ -84,7 +87,6 @@ d <- 2 extract_x <- extract(x_i, m, d) # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/extractT.Rd b/rkeops/man/extractT.Rd index 70041de7b..77e93f097 100644 --- a/rkeops/man/extractT.Rd +++ b/rkeops/man/extractT.Rd @@ -38,7 +38,6 @@ operation works the same way as in the case of a vector of values. use of \code{extractT()}. } \examples{ -\dontrun{ # I - Three very rudimentary examples # ----------------------------------- @@ -47,6 +46,7 @@ use of \code{extractT()}. # [1,] 1 4 # [2,] 2 5 # [3,] 3 6 +g <- matrix(1:6, nrow = 3, ncol = 2) # Convert it to LazyTensor: g_i <- LazyTensor(g, index = 'i') # indexed by 'i' (for example) @@ -98,7 +98,6 @@ d <- 7 extractT_x <- extractT(x_i, m, d) # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/fix_op_reduction.Rd b/rkeops/man/fix_op_reduction.Rd deleted file mode 100644 index 3b34d7df0..000000000 --- a/rkeops/man/fix_op_reduction.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{fix_op_reduction} -\alias{fix_op_reduction} -\title{Fix internal reduction operation.} -\usage{ -fix_op_reduction(reduction_op, with_weight = FALSE) -} -\arguments{ -\item{reduction_op}{A text \code{string} corresponding to a reduction.} - -\item{with_weight}{A \code{boolean} which is \code{TRUE} when there is an optional -argument corresponding to a weight argument.} -} -\value{ -A text \code{string}. -} -\description{ -Returns the internal reduction operation. - -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} \code{fix_op_reduction()} is not useful -anymore because \code{rkeops} is using \code{pykeops} Python package as an internal -engine where this is managed. -} -\details{ -\code{fix_op_reduction(reduction_op, with_weight)} will return the -internal reduction operation according to \code{reduction_op} and a possible -optional weight argument. Some advance operations defined at user level use, -in fact, other internal reductions: -\itemize{ -\item If \code{reduction_op == "LogSumExp"}, the internal reduction operation -is \code{"Max_SumShiftExp"} or \code{"Max_SumShiftExpWeight"} depending on -\code{with_weight}; -\item If \code{reduction_op == "SumSoftMax"}, the internal reduction operation -is \code{"Max_SumShiftExpWeight"}; -\item Else, for every other value of \code{reduction_op}, the internal -reduction operation is \code{reduction_op}. -} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/fix_variables.Rd b/rkeops/man/fix_variables.Rd deleted file mode 100644 index f894e83d8..000000000 --- a/rkeops/man/fix_variables.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{fix_variables} -\alias{fix_variables} -\title{Fix variables.} -\usage{ -fix_variables(x, is_opt = FALSE) -} -\arguments{ -\item{x}{A \code{LazyTensor} or a \code{ComplexLazyTensor}.} -} -\value{ -A \code{LazyTensor} or a \code{ComplexLazyTensor}. -} -\description{ -Assigns final labels to each variable for the \code{KeOps} routine. -} -\details{ -\code{fix_variables(x)} will change the identifiers of \code{x} variables in -\code{x$args} and \code{x$formula} into simpler ordered labels of the form \verb{V} where -\code{n} is the apparition order of the variable in the formula. -} -\examples{ -\dontrun{ -x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns -y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns -x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, - # indexed by 'i' -y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, - # indexed by 'j' - -a <- x_i + y_j # combination of LazyTensors with variable labels - # of the form "A0x.*" - -b <- fix_variables(a) # combination of LazyTensors with variable labels - # of the form "V0" and "V1" -b$formula # returns "V0+V1" -b$args # returns a vector containing "V0=Vi(3)" and "V1=Vj(3)" -} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/get_gradient_formula.Rd b/rkeops/man/get_gradient_formula.Rd deleted file mode 100644 index 70ff50bfa..000000000 --- a/rkeops/man/get_gradient_formula.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/keops_grad.R -\name{get_gradient_formula} -\alias{get_gradient_formula} -\title{Generate formula and input args list for the Gradient of an existing formula} -\usage{ -get_gradient_formula(formula, args, var, args_info) -} -\arguments{ -\item{formula}{text string, an operator formula (see Details).} - -\item{args}{vector of text string, formula arguments (see Details).} - -\item{var}{a text string or an integer number indicating regarding to which -variable/parameter (given by name or by position starting at 0) the -gradient of the formula should be computed.} - -\item{args_info}{list, internal (output of -\code{rkeops:::parse_args(formula,args)})} -} -\value{ -a list with the following element: -\itemize{ -\item \code{new_formula}: character string corresponding to the Gradient formula. -\item \code{new_args}: corresponding enriched arguments (see \code{\link[=keops_grad]{keops_grad()}} -for more details). -} -} -\description{ -Generate formula and input args list for the Gradient of an existing formula -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/get_inner_dim.Rd b/rkeops/man/get_inner_dim.Rd deleted file mode 100644 index 4448a4f84..000000000 --- a/rkeops/man/get_inner_dim.Rd +++ /dev/null @@ -1,42 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{get_inner_dim} -\alias{get_inner_dim} -\title{Get inner dimension.} -\usage{ -get_inner_dim(x) -} -\arguments{ -\item{x}{A \code{LazyTensor}.} -} -\value{ -An integer corresponding to the inner dimension of \code{x}. -} -\description{ -Returns the inner dimension of a given \code{LazyTensor}. -} -\details{ -If \code{x} is a \code{LazyTensor}, \code{get_inner_dim(x)} returns an integer -corresponding to the inner dimension of \code{x}. -} -\examples{ -\dontrun{ -# basic example -D <- 3 -M <- 100 -s <- 0.25 -x <- matrix(runif(M * D), M, D) - -# create LazyTensor -x_i <- LazyTensor(x, index = 'i') -Pm_s <- LazyTensor(s, index = NA) - -# call get_inner_dim -get_inner_dim(x_i) # returns 3 -get_inner_dim(Pm_s) # returns 1 -} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/get_os.Rd b/rkeops/man/get_os.Rd deleted file mode 100644 index b161e637b..000000000 --- a/rkeops/man/get_os.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{get_os} -\alias{get_os} -\title{Find which OS is running} -\usage{ -get_os() -} -\value{ -a character string containing the OS name. -} -\description{ -Return the name of the currently running OS. -} -\details{ -Possible output among \code{"linux"}, \code{"macos"}, \code{"windows"}. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/get_pykeops_formula.Rd b/rkeops/man/get_pykeops_formula.Rd deleted file mode 100644 index fc9cfdd69..000000000 --- a/rkeops/man/get_pykeops_formula.Rd +++ /dev/null @@ -1,57 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/keops_utils.R -\name{get_pykeops_formula} -\alias{get_pykeops_formula} -\title{Format RKeOps formula for PyKeOps} -\usage{ -get_pykeops_formula( - formula, - grad = FALSE, - var_to_diff = NULL, - input_grad = NULL -) -} -\arguments{ -\item{formula}{character string, RKeOps formula defining an operator} - -\item{grad}{boolean, used for recursive call involving \code{Grad}. Default is -\code{FALSE}.} - -\item{var_to_diff}{character string, used for recursive call -involving \code{Grad}. Default is \code{NULL}.} - -\item{input_grad}{character string, used for recursive call -involving \code{Grad}. Default is \code{NULL}.} -} -\value{ -list with items: -\itemize{ -\item \code{reduction_op}: character string, name of the reduction that will be -applied. -\item \code{main_formula}: formula defining the symbolic matrix on which the -reduction will be applied. -\item \code{axis}: integer, axis along which the reduction will be applied (see -details). -\item \code{opt_arg}: integer, optional additional argument for the reduction. -} -} -\description{ -\code{pykeops.numpy.Genred} and \code{pykeops.torch.Genred} do not handle cases where -the reduction and the axis are given directly in the formula, such as -\code{formula = "Sum_Reduction(SqNorm2(x-y), 0)"}. Instead we need to pass -arguments as -\code{Genred(formula="SqNorm2(x-y)", aliases=..., reduction_op="Sum", axis=0, ...)} - -The function \code{get_pykeops_formula()} breaks RKeOps formula into relevant -parts for \code{pykeops} \code{Genred} function. -} -\details{ -\code{axis=0} means a reduction over \code{i} (meaning that the result is a \code{Vj} -variable). -\code{axis=1} means a reduction over \code{j} (meaning that the result is a \code{Vi} -variable). -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/get_rkeops_cache_dir.Rd b/rkeops/man/get_rkeops_cache_dir.Rd index ba6d1da9f..1aebb4086 100644 --- a/rkeops/man/get_rkeops_cache_dir.Rd +++ b/rkeops/man/get_rkeops_cache_dir.Rd @@ -34,10 +34,8 @@ to (fully or partially) delete its content. the default rkeops cache directory. } \examples{ -\dontrun{ get_rkeops_cache_dir() } -} \seealso{ \code{\link[=set_rkeops_cache_dir]{set_rkeops_cache_dir()}}, \code{\link[=stat_rkeops_cache_dir]{stat_rkeops_cache_dir()}}, \code{\link[=clean_rkeops]{clean_rkeops()}} diff --git a/rkeops/man/grad.Rd b/rkeops/man/grad.Rd index 8d3a00e43..d9ec10298 100644 --- a/rkeops/man/grad.Rd +++ b/rkeops/man/grad.Rd @@ -19,8 +19,8 @@ the number of rows of the first \code{x} variable (in \code{x$data}).} \item{var}{An \code{integer} number indicating regarding to which variable/parameter (given by name or by position index starting at 0) the -gradient of the formula should be computed or a one of the \code{LazyTensor} -contained in \code{f}.} +gradient of the formula should be computed or the variable containing +one of the \code{LazyTensor} contained in \code{f}.} \item{index}{A \code{character} that should be either \strong{i} or \strong{j} to specify whether if the reduction is indexed by \strong{i} (rows), or \strong{j} (columns). @@ -43,7 +43,14 @@ dimension corresponds to columns, i.e. \code{index = 'j'} or rows, i.e. \code{index = 'i'}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} nx <- 100 ny <- 150 x <- matrix(runif(nx*3), nrow=nx, ncol=3) # matrix 100 x 3 @@ -57,10 +64,14 @@ eta_i <- LazyTensor(eta, index = 'i') # LazyTensor from matrix eta, # indexed by 'i' (like x_i) # gradient with the formula from position -grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = y_j$formula, "j") +grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = y_j, "j") # gradient with the formula from index grad_xy <- grad(sqnorm2(x_i-y_j), eta_i, "Sum", var = 0, "j") +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/helloWorld.Rd b/rkeops/man/helloWorld.Rd deleted file mode 100644 index a7028847a..000000000 --- a/rkeops/man/helloWorld.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/starting.R -\name{helloWorld} -\alias{helloWorld} -\title{helloWorld} -\usage{ -helloWorld() -} -\value{ -None -} -\description{ -dummy function to init package -} -\keyword{internal} diff --git a/rkeops/man/identifier.Rd b/rkeops/man/identifier.Rd deleted file mode 100644 index a185a1ead..000000000 --- a/rkeops/man/identifier.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{identifier} -\alias{identifier} -\title{Identifier.} -\usage{ -identifier(arg) -} -\arguments{ -\item{arg}{A \code{string} corresponding to an element of the attribute \code{args} of -a \code{LazyTensor}.} -} -\value{ -A \code{string}. -} -\description{ -Returns the identifier/label of a \code{LazyTensor} which is contained in \code{arg}. -} -\details{ -\code{identifier(arg)} will extract a unique identifier of the form -\code{"A0x.*"} from the argument \code{arg} which has the form \code{"A0x.*=Vi(3)"}. -} -\examples{ -\dontrun{ -x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns -x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, - # indexed by 'i' -arg <- x_i$args[1] # argument of the form "A0x.*=Vi(3)" -id <- identifier(arg) # extracts "A0x.*" -} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/ifelse.LazyTensor.Rd b/rkeops/man/ifelse.LazyTensor.Rd index 582ba5dab..20f36ea36 100644 --- a/rkeops/man/ifelse.LazyTensor.Rd +++ b/rkeops/man/ifelse.LazyTensor.Rd @@ -28,7 +28,6 @@ Broadcasting rules apply. inner dimension as \code{test}. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -44,7 +43,6 @@ z_i <- LazyTensor(z, index = 'i') # call ifelse function if_else_xyz <- ifelse(x_i, y_j, z_i) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/ifelse.Rd b/rkeops/man/ifelse.Rd index b28cee64f..2d178bdb7 100644 --- a/rkeops/man/ifelse.Rd +++ b/rkeops/man/ifelse.Rd @@ -23,7 +23,6 @@ If \code{test} is a \code{LazyTensor}, see \code{\link[=ifelse.LazyTensor]{ifels see \code{\link[=ifelse.default]{ifelse.default()}}. } \examples{ -\dontrun{ # R base operation x <- c(6:-4) sqrt(ifelse(x >= 0, x, NA)) @@ -41,7 +40,6 @@ z_i <- LazyTensor(z, index = 'i') if_else_xyz <- ifelse(x_i, y_j, z_i) } -} \seealso{ \code{\link[=ifelse.default]{ifelse.default()}}, \code{\link[=ifelse.LazyTensor]{ifelse.LazyTensor()}} } diff --git a/rkeops/man/imaginary2complex.Rd b/rkeops/man/imaginary2complex.Rd index 0983eec0c..62a03d2a5 100644 --- a/rkeops/man/imaginary2complex.Rd +++ b/rkeops/man/imaginary2complex.Rd @@ -31,13 +31,11 @@ of \code{x} (i.e. with additional zero real part: \code{0 + x*i}). a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, # indexed by 'i' z <- imag2complex(x_i) # ComplexLazyTensor object } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/index_to_int.Rd b/rkeops/man/index_to_int.Rd deleted file mode 100644 index d2a169264..000000000 --- a/rkeops/man/index_to_int.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{index_to_int} -\alias{index_to_int} -\title{Index to int.} -\usage{ -index_to_int(index) -} -\arguments{ -\item{index}{A \code{character} that should be either \code{i} or \code{j}.} -} -\value{ -An \code{integer}. -} -\description{ -Transforms \code{string} index input into integer. -} -\details{ -\code{index_to_int(index)} returns an \code{integer}: \code{1} if -\code{index == "i"} and \code{0} if \code{index == "j"}. -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/install_rkeops.Rd b/rkeops/man/install_rkeops.Rd deleted file mode 100644 index 1f0229477..000000000 --- a/rkeops/man/install_rkeops.Rd +++ /dev/null @@ -1,90 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/install.R -\name{install_rkeops} -\alias{install_rkeops} -\title{Install RKeOps requirements} -\usage{ -install_rkeops( - envname = NULL, - method = c("auto", "virtualenv", "conda"), - conda = "auto", - python_version = NULL, - pip = FALSE, - ..., - pip_ignore_installed = ignore_installed, - ignore_installed = FALSE -) -} -\arguments{ -\item{envname}{The name, or full path, of the environment in which Python -packages are to be installed. When \code{NULL} (the default), the active -environment as set by the \code{RETICULATE_PYTHON_ENV} variable will be used; -if that is unset, then the \code{r-reticulate} environment will be used.} - -\item{method}{Installation method. By default, "auto" automatically finds a -method that will work in the local environment. Change the default to force -a specific installation method. Note that the "virtualenv" method is not -available on Windows.} - -\item{conda}{The path to a \code{conda} executable. Use \code{"auto"} to allow -\code{reticulate} to automatically find an appropriate \code{conda} binary. -See \strong{Finding Conda} and \code{\link[reticulate:conda_binary]{conda_binary()}} for more details.} - -\item{python_version}{The requested Python version. Ignored when attempting -to install with a Python virtual environment.} - -\item{pip}{Boolean; use \code{pip} for package installation? This is only relevant -when Conda environments are used, as otherwise packages will be installed -from the Conda repositories.} - -\item{...}{Additional arguments passed to \code{\link[reticulate:conda_install]{conda_install()}} -or \code{\link[reticulate:virtualenv_install]{virtualenv_install()}}.} - -\item{pip_ignore_installed, ignore_installed}{Boolean; whether pip should -ignore previously installed versions of the requested packages. Setting -this to \code{TRUE} causes pip to install the latest versions of all -dependencies into the requested environment. This ensure that no -dependencies are satisfied by a package that exists either in the site -library or was previously installed from a different--potentially -incompatible--distribution channel. (\code{ignore_installed} is an alias for -\code{pip_ignore_installed}, \code{pip_ignore_installed} takes precedence).} -} -\description{ -Install requirements (i.e. Python packages) for RKeOps to work. -} -\details{ -RKeOps now uses PyKeOps Python package under the hood thanks to the -\href{https://rstudio.github.io/reticulate/}{\code{reticulate}} R package that -provides an "R Interface to Python". - -We recommend to use a dedicated Python environment (through \code{reticulate}) -to install and use RKeOps Python dependencies. - -\code{install_rkeops()} is just a wrapper around \code{\link[reticulate:py_install]{reticulate::py_install()}} -and takes the same input arguments. - -See the specific \strong{"Using RKeOps" \href{https://www.kernel-operations.io/rkeops/articles/using_rkeops.html}{article}} -or the corresponding vignette: \code{vignette("using_rkeops", package = "rkeops")} - -\strong{Important:} Python is a requirement as an intern machinery for the -package to work but you will not need to create nor manipulate Python -codes to use the RKeOps package. -} -\examples{ -\dontrun{ -## setup Python virtual environment -# create Python virtualenv -reticulate::virtualenv_create("rkeops") -# activate python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) - -## install rkeops requirements in Python virtual environment -install_rkeops() - -## check install -check_rkeops() -} -} -\author{ -Ghislain Durif -} diff --git a/rkeops/man/inv.LazyTensor.Rd b/rkeops/man/inv.LazyTensor.Rd index 495bbe22b..be559c637 100644 --- a/rkeops/man/inv.LazyTensor.Rd +++ b/rkeops/man/inv.LazyTensor.Rd @@ -22,13 +22,11 @@ If \code{x} is a \code{LazyTensor}, \code{inv(x)} returns a \code{LazyTensor} th encodes, symbolically, the element-wise inverse of \code{x}, i.e. \code{1/x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Inv_x <- inv(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=inv]{inv()}} } diff --git a/rkeops/man/inv.Rd b/rkeops/man/inv.Rd index 8232e730f..0823bd3d3 100644 --- a/rkeops/man/inv.Rd +++ b/rkeops/man/inv.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=inv.LazyTensor]{inv.LazyTen see \code{\link[=inv.default]{inv.default()}}. } \examples{ -\dontrun{ # Numerical input inv(4) inv(1:10) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Inv_x <- inv(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=inv.default]{inv.default()}}, \code{\link[=inv.LazyTensor]{inv.LazyTensor()}} } diff --git a/rkeops/man/is.ComplexLazyParameter.Rd b/rkeops/man/is.ComplexLazyParameter.Rd index c106a4d9d..0fe5218b4 100644 --- a/rkeops/man/is.ComplexLazyParameter.Rd +++ b/rkeops/man/is.ComplexLazyParameter.Rd @@ -24,7 +24,6 @@ single complex value, \code{is.ComplexLazyParameter(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example scal <- 3.14 cplx <- 2 + 3i @@ -41,8 +40,7 @@ z_i <- LazyTensor(z, index = 'i') is.ComplexLazyParameter(scal_LT) # returns FALSE is.ComplexLazyParameter(cplx_LT) # returns TRUE is.ComplexLazyParameter(v_LT) # returns FALSE -is.ComplexLazyParameter(x_i) # returns FALSE -} +is.ComplexLazyParameter(z_i) # returns FALSE } \author{ Chloe Serre-Combe, Amelie Vernay diff --git a/rkeops/man/is.ComplexLazyTensor.Rd b/rkeops/man/is.ComplexLazyTensor.Rd index 7ce6cbc2a..892081cb4 100644 --- a/rkeops/man/is.ComplexLazyTensor.Rd +++ b/rkeops/man/is.ComplexLazyTensor.Rd @@ -20,7 +20,6 @@ If \code{x} is a \code{ComplexLazyTensor}, \code{is.ComplexLazyTensor(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -35,7 +34,6 @@ z_i <- LazyTensor(z, index = 'i', is_complex = TRUE) # ComplexLazyTensor is.ComplexLazyTensor(z_i) # returns TRUE is.ComplexLazyTensor(x_i) # returns FALSE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/is.LazyMatrix.Rd b/rkeops/man/is.LazyMatrix.Rd index 2b0dacade..a05925596 100644 --- a/rkeops/man/is.LazyMatrix.Rd +++ b/rkeops/man/is.LazyMatrix.Rd @@ -21,7 +21,6 @@ If \code{x} is a matrix \code{LazyTensor}, \code{is.LazyMatrix(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example scal <- 3.14 cplx <- 2 + 3i @@ -40,7 +39,6 @@ is.LazyMatrix(cplx_LT) # returns FALSE is.LazyMatrix(v_LT) # returns FALSE is.LazyMatrix(x_i) # returns TRUE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/is.LazyParameter.Rd b/rkeops/man/is.LazyParameter.Rd index 150478738..bdd74435e 100644 --- a/rkeops/man/is.LazyParameter.Rd +++ b/rkeops/man/is.LazyParameter.Rd @@ -23,7 +23,6 @@ If \code{x} is a fixed scalar parameter \code{LazyTensor}, \code{is.LazyParameter(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example scal <- 3.14 cplx <- 2 + 3i @@ -42,7 +41,6 @@ is.LazyParameter(cplx_LT) # returns FALSE is.LazyParameter(v_LT) # returns FALSE is.LazyParameter(x_i) # returns FALSE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/is.LazyTensor.Rd b/rkeops/man/is.LazyTensor.Rd index 4b295ab8c..82d1f1a3b 100644 --- a/rkeops/man/is.LazyTensor.Rd +++ b/rkeops/man/is.LazyTensor.Rd @@ -20,7 +20,6 @@ If \code{x} is a \code{LazyTensor}, \code{is.LazyTensor(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') is.LazyTensor(x_i) # returns TRUE is.LazyTensor(x) # returns FALSE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/is.LazyVector.Rd b/rkeops/man/is.LazyVector.Rd index 44934f5fa..f169770ff 100644 --- a/rkeops/man/is.LazyVector.Rd +++ b/rkeops/man/is.LazyVector.Rd @@ -21,7 +21,6 @@ If \code{x} is a vector parameter \code{LazyTensor}, \code{is.LazyVector(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example scal <- 3.14 cplx <- 2 + 3i @@ -40,7 +39,6 @@ is.LazyVector(cplx_LT) # returns TRUE is.LazyVector(v_LT) # returns TRUE is.LazyVector(x_i) # returns FALSE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/is.int.Rd b/rkeops/man/is.int.Rd index ba70686c1..b314d216d 100644 --- a/rkeops/man/is.int.Rd +++ b/rkeops/man/is.int.Rd @@ -20,7 +20,6 @@ If \code{x} is a scalar\code{integer}, \code{is.int(x)} returns TRUE, else, returns FALSE. } \examples{ -\dontrun{ # basic example A <- 3 B <- 3.4 @@ -30,7 +29,6 @@ is.int(A) # returns TRUE is.int(B) # returns FALSE is.int(C) # returns FALSE } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/keops_grad.Rd b/rkeops/man/keops_grad.Rd index 3c0582693..b17a5b74a 100644 --- a/rkeops/man/keops_grad.Rd +++ b/rkeops/man/keops_grad.Rd @@ -54,9 +54,14 @@ as the variable chosen to differentiate the formula and of dimension \code{1} so that the final computation give the corresponding gradient. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) set_rkeops_options() - +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # defining an operator (reduction on squared distance) formula <- "Sum_Reduction(SqNorm2(x-y), 0)" args <- c("x=Vi(0,3)", "y=Vj(1,3)") @@ -92,6 +97,10 @@ eta <- matrix(1, nrow=nx, ncol=1) # matrix 100 x 1 # computation input <- list(x, y, eta) res <- op(input) +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/keops_kernel.Rd b/rkeops/man/keops_kernel.Rd index e9d2e9af2..57f81d643 100644 --- a/rkeops/man/keops_kernel.Rd +++ b/rkeops/man/keops_kernel.Rd @@ -78,16 +78,23 @@ It is possible to compute partial derivatives of user defined operators with the function \code{\link[=keops_grad]{keops_grad()}}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) set_rkeops_options() - +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} ## Example 1 # Defining a function that computes for each j the sum over i # of the scalar products between `x_i` and `y_j` (both 3d vectors), # i.e. the sum over the rows of the result of the matrix product `X * t(Y)` # where `x_i` and `y_j` are the respective rows of the matrices `X` and `Y`. op <- keops_kernel( - formula = "Sum_Reduction((x|y), 1)", args = c("x=Vi(3)", "y=Vj(3)")) + formula = "Sum_Reduction((x|y), 1)", + args = c("x=Vi(3)", "y=Vj(3)") +) # data nx <- 10 ny <- 15 @@ -118,11 +125,12 @@ res <- op(list(X,Y), inner_dim="row") ## Example 2 # Defining a function that computes the convolution with a Gaussian kernel -# i.e. the sum over i of `e^(lambda * ||x_i - y_j||^2) * beta_j` where `x_i`, -# `y_j` and `beta_j` are 3d vectors, and `lambda` is a scalar parameter. -op = keops_kernel( - formula = "Sum_Reduction(Exp(lambda*SqNorm2(x-y))*beta, 1)", - args = c("x=Vi(3)", "y=Vj(3)", "beta=Vj(3)", "lambda=Pm(1)")) +# i.e. the sum over i of `e^(sigma * ||x_i - y_j||^2) * beta_j` where `x_i`, +# `y_j` and `beta_j` are 3d vectors, and `sigma` is a scalar parameter. +op <- keops_kernel( + formula = "Sum_Reduction(Exp(sigma*SqNorm2(x-y))*beta, 1)", + args = c("x=Vi(3)", "y=Vj(3)", "beta=Vj(3)", "sigma=Pm(1)") +) # data nx <- 10 @@ -136,10 +144,14 @@ beta <- matrix(runif(ny*3), nrow=ny, ncol=3) # !! important !! y and beta should have the same dimension # parameter -lambda <- 0.25 +sigma <- 0.25 # compute the result -res <- op(list(X, Y, beta, lambda)) +res <- op(list(X, Y, beta, sigma)) +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/log.LazyTensor.Rd b/rkeops/man/log.LazyTensor.Rd index 970a1030c..8c3a60fd9 100644 --- a/rkeops/man/log.LazyTensor.Rd +++ b/rkeops/man/log.LazyTensor.Rd @@ -26,13 +26,11 @@ encodes, symbolically, the element-wise natural logarithm of \code{x}, i.e. \eqn{\log{x}}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Log_x <- log(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=log]{log()}} } diff --git a/rkeops/man/log.Rd b/rkeops/man/log.Rd index 08f6410d4..b4c47cbcf 100644 --- a/rkeops/man/log.Rd +++ b/rkeops/man/log.Rd @@ -27,7 +27,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=log.LazyTensor]{log.LazyTen see \code{\link[=log.default]{log.default()}}. } \examples{ -\dontrun{ # R base operation log(1) log(1:10) @@ -37,7 +36,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Log_x <- log(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=log.default]{log.default()}}, \code{\link[=log.LazyTensor]{log.LazyTensor()}} } diff --git a/rkeops/man/logsumexp.Rd b/rkeops/man/logsumexp.Rd index 7a378bd7b..37dbb5bfb 100644 --- a/rkeops/man/logsumexp.Rd +++ b/rkeops/man/logsumexp.Rd @@ -17,7 +17,8 @@ should be either \code{"i"} or \code{"j"} to specify whether if the reduction is indexed by \code{"i"} or \code{"j"}.} \item{weight}{an optional object (\code{LazyTensor} or \code{ComplexLazyTensor}) that -specifies scalar or vector-valued weights. \code{NULL} by default and not used.} +specifies scalar or vector-valued weights. \code{NULL} by default and not used. +\strong{Not supported at the moment}.} } \value{ a matrix corresponding to the Log-Sum-Exp reduction. @@ -40,7 +41,14 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) x_i <- LazyTensor(x, index = 'i') y <- matrix(runif(100 * 3), 100, 3) @@ -48,14 +56,29 @@ y_j <- LazyTensor(y, index = 'j') w <- matrix(runif(100 * 3), 100, 3) # weight LazyTensor w_j <- LazyTensor(w, index = 'j') -S_ij = sum((x_i - y_j)^2) -logsumexp_xw <- logsumexp(S_ij, 'i', w_j) # logsumexp reduction - # over the 'i' indices +S_ij = sum((x_i - y_j)^2) -logsumexp_x <- logsumexp(S_ij, 'i') # logsumexp reduction without - # weight over the 'i' indices -} +logsumexp_x <- logsumexp(S_ij, 'i') # logsumexp reduction + # over the 'i' indices + \dontrun{ +# note: expected error, not supported at the moment +logsumexp_xw <- logsumexp(S_ij, 'i', w_j) # logsumexp reduction with weights + # over the 'i' indices +} +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) x_i <- LazyTensor(x, index = 'i') y <- matrix(runif(100 * 3), 100, 3) @@ -63,12 +86,20 @@ y_j <- LazyTensor(y, index = 'j') w <- matrix(runif(150 * 3), 150, 3) # weight LazyTensor w_j <- LazyTensor(y, index = 'j') -S_ij = sum( (x_i - y_j)^2 ) -logsumexp_xw <- logsumexp_reduction(S_ij, 'i', w_j) # logsumexp reduction - # over the 'i' indices +S_ij = sum( (x_i - y_j)^2 ) logsumexp_x <- logsumexp_reduction(S_ij, 'i') # logsumexp reduction without # weight over the 'i' indices + +\dontrun{ +# note: expected error, not supported at the moment +logsumexp_xw <- logsumexp_reduction(S_ij, 'i', w_j) # logsumexp reduction + # over the 'i' indices +} +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/matmult.LazyTensor.Rd b/rkeops/man/matmult.LazyTensor.Rd index 249b887e5..04025c79d 100644 --- a/rkeops/man/matmult.LazyTensor.Rd +++ b/rkeops/man/matmult.LazyTensor.Rd @@ -23,7 +23,14 @@ If \code{x} or \code{y} is a \code{LazyTensor}, \code{x \%*\% y} returns the sum reduction of the product \code{x * y}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -31,6 +38,10 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_mult_y <- x_i \%*\% y_j # FIXME +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/matmult.Rd b/rkeops/man/matmult.Rd index c8c0355f2..d2980efb5 100644 --- a/rkeops/man/matmult.Rd +++ b/rkeops/man/matmult.Rd @@ -22,12 +22,19 @@ If \code{x} or \code{y} is a \code{LazyTensor}, see \code{\link[=\%*\%.LazyTenso \code{\link[=\%*\%.default]{\%*\%.default()}}. } \examples{ -\dontrun{ # R base operation x <- matrix(runif(10 * 5), 10, 5) # arbitrary R matrix, 10 rows, 5 columns -x <- matrix(runif(5 * 3), 5, 3) # arbitrary R matrix, 5 rows, 3 columns +y <- matrix(runif(5 * 3), 5, 3) # arbitrary R matrix, 5 rows, 3 columns x \%*\% y # product matrix, 10 rows, 3 columns +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # LazyTensor matrix multiplication x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns @@ -36,6 +43,10 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_mult_y <- x_i \%*\% y_j # FIXME +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/matvecmult.Rd b/rkeops/man/matvecmult.Rd index 1410b6521..4f0ba1834 100644 --- a/rkeops/man/matvecmult.Rd +++ b/rkeops/man/matvecmult.Rd @@ -25,7 +25,6 @@ of matrix \code{m} and vector \code{v}. of dimension 1. } \examples{ -\dontrun{ m <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns v <- c(1,2,3) # arbitrary R vector of length 3 m_i <- LazyTensor(m, index = 'i') # LazyTensor from matrix m, indexed by 'i' @@ -33,7 +32,6 @@ Pm_v <- LazyTensor(v) # parameter vector LazyTensor from v mv_mult <- matvecmult(m_i, Pm_v) # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/max.LazyTensor.Rd b/rkeops/man/max.LazyTensor.Rd index 642916b9e..aa732e39a 100644 --- a/rkeops/man/max.LazyTensor.Rd +++ b/rkeops/man/max.LazyTensor.Rd @@ -50,20 +50,42 @@ section \emph{"Reductions"}. \code{max_reduction()} function. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' max_x <- max(x_i) # LazyTensor object max_red_x <- max(x_i, "i") # max reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' max_reduction(x_i, "i") +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/max.Rd b/rkeops/man/max.Rd index e34f1a388..218e25dec 100644 --- a/rkeops/man/max.Rd +++ b/rkeops/man/max.Rd @@ -24,10 +24,17 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=max.LazyTensor]{max.LazyTen \code{\link[=max.default]{max.default()}}. } \examples{ -\dontrun{ # R base operation max(1:10) max(c(NA, 1, 2), na.rm = TRUE) +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # LazyTensor operation x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -35,6 +42,10 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, max_x <- max(x_i) # LazyTensor object max_red_x <- max(x_i, "i") # max reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/max_argmax.Rd b/rkeops/man/max_argmax.Rd index eb18e9725..42f5c961e 100644 --- a/rkeops/man/max_argmax.Rd +++ b/rkeops/man/max_argmax.Rd @@ -37,20 +37,42 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' max_argmax_x <- max_argmax(x_i, "i") # max argmax reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' max_argmax_red <- max_argmax_reduction(x_i, "i") # max argmax reduction # indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/min.LazyTensor.Rd b/rkeops/man/min.LazyTensor.Rd index c5d1e0dd1..b108921f0 100644 --- a/rkeops/man/min.LazyTensor.Rd +++ b/rkeops/man/min.LazyTensor.Rd @@ -45,20 +45,42 @@ section \emph{"Reductions"}. \code{min_reduction()} function. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' min_x <- min(x_i) # LazyTensor object min_red_x <- min(x_i, "i") # min reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' min_reduction(x_i, "i") +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/min.Rd b/rkeops/man/min.Rd index 63fe56e17..c3aea4a23 100644 --- a/rkeops/man/min.Rd +++ b/rkeops/man/min.Rd @@ -24,10 +24,17 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=min.LazyTensor]{min.LazyTen \code{\link[=min.default]{min.default()}}. } \examples{ -\dontrun{ # R base operation min(1:10) min(c(NA, 1, 2), na.rm = TRUE) +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # LazyTensor operation x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -35,6 +42,10 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, min_x <- min(x_i) # LazyTensor object min_red_x <- min(x_i, "i") # min reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/min_argmin.Rd b/rkeops/man/min_argmin.Rd index cdca05591..64aee4aa9 100644 --- a/rkeops/man/min_argmin.Rd +++ b/rkeops/man/min_argmin.Rd @@ -37,19 +37,41 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' min_argmin_xi <- min_argmin(x_i, "i") # min argmin reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' min_argmin_red <- min_argmin_reduction(x_i, "i") # min reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/modulo.LazyTensor.Rd b/rkeops/man/modulo.LazyTensor.Rd index 0af801dfe..5de5a3f2c 100644 --- a/rkeops/man/modulo.LazyTensor.Rd +++ b/rkeops/man/modulo.LazyTensor.Rd @@ -36,7 +36,6 @@ inner dimension as \code{x}. \strong{Warning}: Do not confuse with \code{\link[=Mod]{Mod()}}. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -55,7 +54,6 @@ mod_x72 <- mod(x_i, 7, 2) # works also with LazyTensors with same inner dimension or dimension 1 mod_xyz <- mod(x_i, y_j, z_i) } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/modulo.Rd b/rkeops/man/modulo.Rd index a7db84f25..2fbf03d72 100644 --- a/rkeops/man/modulo.Rd +++ b/rkeops/man/modulo.Rd @@ -27,7 +27,6 @@ see the corresponding \code{mod} function (if existing) help page. \strong{Warning}: Do not confuse with \code{\link[=Mod]{Mod()}}. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -46,7 +45,6 @@ mod_x72 <- mod(x_i, 7, 2) # works also with LazyTensors with same inner dimension or dimension 1 mod_xyz <- mod(x_i, y_j, z_i) } -} \seealso{ \code{\link[=mod.LazyTensor]{mod.LazyTensor()}} } diff --git a/rkeops/man/msg_warn_error.Rd b/rkeops/man/msg_warn_error.Rd deleted file mode 100644 index 78a36d4a4..000000000 --- a/rkeops/man/msg_warn_error.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{msg_warn_error} -\alias{msg_warn_error} -\title{Print message or raise warning or error} -\usage{ -msg_warn_error(msg, type, startup = FALSE) -} -\arguments{ -\item{msg}{character string, text message.} - -\item{type}{character string, among \code{"msg"} to print a message, \code{"warn"} for -to raise a warning, and \code{"error"} to raise an error.} - -\item{startup}{boolean indicating if the function is called at startup or -not.} -} -\description{ -Different behavior to provide information to the user (either a message, -a warning or an error). -} -\details{ -If \code{type = "msg"}, then a message with content \code{msg} is printed. If -\code{type = "warning"}, then a warning with message \code{msg} is raised. And if -\code{type = "error"}, then an error with message \code{msg} is raised. - -If \code{type = "msg"} and \code{startup = TRUE}, then \code{packageStartupMessage()} -function is used instead of \code{message()}. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/norm2.Rd b/rkeops/man/norm2.Rd index 95f87822f..f4b101662 100644 --- a/rkeops/man/norm2.Rd +++ b/rkeops/man/norm2.Rd @@ -21,13 +21,11 @@ Symbolic Euclidean norm operation for \code{LazyTensor} objects. the Euclidean norm of \code{x}, same as \code{sqrt(x|x)}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' N_x <- norm2(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=|.LazyTensor]{|.LazyTensor()}}, \code{\link[=sqrt]{sqrt()}} } diff --git a/rkeops/man/normalize.Rd b/rkeops/man/normalize.Rd index 9e7635249..7b6f09183 100644 --- a/rkeops/man/normalize.Rd +++ b/rkeops/man/normalize.Rd @@ -22,13 +22,11 @@ the vector normalization of \code{x} (with the Euclidean norm), same as \code{rsqrt(sqnorm2(x)) * x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' N_x <- norm2(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sqnorm2]{sqnorm2()}}, \code{\link[=rsqrt]{rsqrt()}} } diff --git a/rkeops/man/one_hot.Rd b/rkeops/man/one_hot.Rd index 01c41001a..4d323ecce 100644 --- a/rkeops/man/one_hot.Rd +++ b/rkeops/man/one_hot.Rd @@ -23,14 +23,12 @@ If \code{x} is a scalar value encoded as a \code{LazyTensor}, where round(\code{x})-th coordinate is equal to 1, and the other ones to 0. } \examples{ -\dontrun{ A <- 7 A_LT <- LazyTensor(A) # LazyTensor from scalar A D <- 7 onehot_x <- one_hot(A_LT, D) # symbolic vector of length D } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/parse_args.Rd b/rkeops/man/parse_args.Rd deleted file mode 100644 index 4c82ff732..000000000 --- a/rkeops/man/parse_args.Rd +++ /dev/null @@ -1,77 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/formula_args.R -\name{parse_args} -\alias{parse_args} -\title{Parse formula argument list in triplet (type, dimension, position)} -\usage{ -parse_args(formula, args) -} -\arguments{ -\item{formula}{text string, an operator formula (see Details).} - -\item{args}{vector of text string, formula input arguments (see Details).} -} -\value{ -a list with different information about formula input arguments: -\itemize{ -\item \code{args}: vector of text string, input parameter \code{args}. -\item \code{var_name} vector of text string, corresponding name of formula -arguments. -\item \code{var_type}: vector of text string, corresponding type of formula -arguments (among \code{Vi}, \code{Vj}, \code{Pm}). -\item \code{var_pos}: vector of integer, corresponding arguments positions. -\item \code{var_dim}: vector of integer, corresponding arguments inner dimensions. -\item \code{decl}: character string, either \code{"dim"} if \verb{Vi|Vj|Pm()} argument -declaration convention is used, or \code{"pos_dim"} if -\verb{Vi|Vj|Pm(,)} argument declaration convention is used. -} -} -\description{ -The function \code{parse_args} formats KeOps formula arguments to be -understood by the C++ code. -} -\details{ -Mathematical formula: \verb{sum_i e^(lambda*||x_i - y_j||^2)} where \code{x_i}, \code{y_j} -are 3d vectors, and \code{lambda} is a scaler parameter. - -Corresponding KeOps formula and input parameters: - -\if{html}{\out{
}}\preformatted{formula = "Sum_Reduction(Exp(lambda * SqNorm2(x-y)), 0)" -args = c("x=Vi(3)", "y=Vj(3)", "lambda=Pm(1)") -}\if{html}{\out{
}} - -Input arguments can be of different types: - -|---------|-------------------------|-----------|\tabular{lll}{ - keyword \tab meaning \tab type \cr - \code{Vi} \tab variable indexed by \code{i} \tab \code{0} \cr - \code{Vj} \tab variable indexed by \code{j} \tab \code{1} \cr - \code{Pm} \tab parameter \tab \code{2} \cr - --------- \tab ------------------------- \tab ----------- \cr -} - - -An input parameters should be defined as follows \code{"x=YY(dim)"} or -\code{"x=YY(pos, dim)"} where \code{YY} can be \code{Vi}, \code{Vj} or \code{Pm}: -\itemize{ -\item \code{dim} is the dimension of the variable or parameter. For \code{Vi} and \code{Vj}, -the range of \code{i} or \code{j} is not known at compile time, only at runtime. -\item \code{pos} is the position of the variable as it will be supplied to the -operator, starting from \code{0}. This position should be specify for all -variable or none, if not specify the natural order in the vector \code{args} is -used. -} - -For the formula \code{"Sum_Reduction(Exp(lambda * SqNorm2(x-y)), 0)"}, both -\code{args = c("x=Vi(3)", "y=Vj(3)", "lambda=Pm(1)")} and -\code{args <- c("x=Vi(0,3)", "y=Vj(1,3)", "beta=Vj(2,3)", "lambda=Pm(3,1)")} are -equivalent. When specifying the \code{pos} parameter, the natural order in the -vector \code{args} may not correspond to the order of the formula input arguments. - -\strong{Note:} we recommend to use the \code{Vi(dim)} notation and let the position be -determined by the argument order. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/parse_extra_args.Rd b/rkeops/man/parse_extra_args.Rd deleted file mode 100644 index 90f0d04b4..000000000 --- a/rkeops/man/parse_extra_args.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/formula_args.R -\name{parse_extra_args} -\alias{parse_extra_args} -\title{Parse formula for extra arguments in the formula not defined with an -alias in the argument list.} -\usage{ -parse_extra_args(formula) -} -\arguments{ -\item{formula}{text string, an operator formula (see Details).} -} -\value{ -a boolean value indicating if extra args were found in the formula. -} -\description{ -RKeOps does not support direct encoding of argument in the formula without -an alias in the argument list. This function check if any argument are -directly encoded in the formula without an alias. -} -\details{ -Parse the formula for string such as -\itemize{ -\item \code{"YY(,)"} where \code{YY} can be a formula input argument type -(\code{Vi}, \code{Vj} or \code{Pm}), \verb{} is the position of the corresponding input -argument, and \verb{} its inner dimension. -\item \code{"Var(,,)"} where \verb{} and \verb{} are the position and -inner dimension (c.f. previous point) and \verb{} is an integer encoding -the formula input argument type with the following relation: -} - -|---------|-------------------------|-----------|\tabular{lll}{ - keyword \tab meaning \tab type \cr - \code{Vi} \tab variable indexed by \code{i} \tab \code{0} \cr - \code{Vj} \tab variable indexed by \code{j} \tab \code{1} \cr - \code{Pm} \tab parameter \tab \code{2} \cr - --------- \tab ------------------------- \tab ----------- \cr -} -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/preprocess_reduction.Rd b/rkeops/man/preprocess_reduction.Rd deleted file mode 100644 index 8a847caf1..000000000 --- a/rkeops/man/preprocess_reduction.Rd +++ /dev/null @@ -1,52 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/lazytensor_preprocess.R -\name{preprocess_reduction} -\alias{preprocess_reduction} -\title{Preprocess reduction operation.} -\usage{ -preprocess_reduction(x, opstr, index, opt_arg = NULL) -} -\arguments{ -\item{x}{A \code{LazyTensor} or a \code{ComplexLazyTensor}.} - -\item{opstr}{A \code{string} formula (like "Sum" or "Max").} - -\item{index}{A \code{character} that should be either \code{i} or \code{j} to specify -whether if the reduction is indexed by \code{i} (rows), or \code{j} (columns).} - -\item{opt_arg}{An optional argument: an \code{integer} (e.g. for "Kmin" -reduction), a \code{character}, a \code{LazyTensor} or a \code{ComplexLazyTensor}. \code{NULL} -if not used (default).} -} -\value{ -A \code{function}. -} -\description{ -Returns a \code{function} for a reduction to a \code{LazyTensor} and it is called in -\code{rkeops::reduction.LazyTensor()}. -} -\details{ -\code{preprocess_reduction(x, opstr, index)} will: -\itemize{ -\item if \code{index = "i"}, return a \code{function} corresponding to the -\code{opstr} reduction of \code{x} over the \code{i} indexes; -\item if \code{index = "j"}, return a \code{function} corresponding to the -\code{opstr} reduction of \code{x} over the \code{j} indexes. -} -} -\examples{ -\dontrun{ -x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns -x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, - # indexed by 'i' - -op <- preprocess_reduction(x_i, "Sum", "i") -} -} -\seealso{ -\code{\link[=reduction.LazyTensor]{reduction.LazyTensor()}} -} -\author{ -Chloe Serre-Combe, Amelie Vernay -} -\keyword{internal} diff --git a/rkeops/man/pykeops.Rd b/rkeops/man/pykeops.Rd deleted file mode 100644 index 96e3dfc0e..000000000 --- a/rkeops/man/pykeops.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/zzz.R -\docType{data} -\name{pykeops} -\alias{pykeops} -\title{Global reference to main PyKeOps module} -\format{ -An object of class \code{python.builtin.module} -} -\value{ -the \code{pykeops} Python module -} -\description{ -The \code{pykeops} module object is an internal reference to the PyKeOps -Python package that is used under the hood by \code{rkeops}. -} -\keyword{internal} diff --git a/rkeops/man/random_varname.Rd b/rkeops/man/random_varname.Rd deleted file mode 100644 index 8d538dfcd..000000000 --- a/rkeops/man/random_varname.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{random_varname} -\alias{random_varname} -\title{Helper function to generate random variable name for gradient input in -formula} -\usage{ -random_varname(prefix = "", len = 5) -} -\arguments{ -\item{prefix}{character string, prefix to add to the variable name.} - -\item{len}{integer, number of random character in the variable name.} -} -\value{ -character string, name of the python environment. -} -\description{ -Helper function to generate random variable name for gradient input in -formula -} -\keyword{internal} diff --git a/rkeops/man/real2complex.Rd b/rkeops/man/real2complex.Rd index e08bc18c6..4fe2a0e8b 100644 --- a/rkeops/man/real2complex.Rd +++ b/rkeops/man/real2complex.Rd @@ -30,13 +30,11 @@ symbolically, the element-wise "real to complex" transformation of \code{x} a \code{ComplexLazyTensor}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, "i") # creating LazyTensor from matrix x, # indexed by 'i' z <- real2complex(x_i) # ComplexLazyTensor object } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/reduction.LazyTensor.Rd b/rkeops/man/reduction.LazyTensor.Rd index 63cefbb6b..0fb6c0d41 100644 --- a/rkeops/man/reduction.LazyTensor.Rd +++ b/rkeops/man/reduction.LazyTensor.Rd @@ -33,12 +33,23 @@ Applies a reduction to a \code{LazyTensor}. } } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' red_x <- reduction.LazyTensor(x_i, "Sum", "i") +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/relu.LazyTensor.Rd b/rkeops/man/relu.LazyTensor.Rd index 95de17789..d0c129903 100644 --- a/rkeops/man/relu.LazyTensor.Rd +++ b/rkeops/man/relu.LazyTensor.Rd @@ -25,13 +25,11 @@ The ReLU function \insertCite{fukushima_cognitron_1975}{rkeops} is defined as follows: \code{relu(x)} returns \code{0} if \code{x < 0}, \code{x} if \code{x >= 0}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' ReLU_x <- relu(x_i) # symbolic matrix, 150 rows and 3 columns } -} \references{ \insertRef{fukushima_cognitron_1975}{rkeops} } diff --git a/rkeops/man/relu.Rd b/rkeops/man/relu.Rd index 6b48481b2..776869d98 100644 --- a/rkeops/man/relu.Rd +++ b/rkeops/man/relu.Rd @@ -26,7 +26,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=relu.LazyTensor]{relu.LazyT see \code{\link[=relu.default]{relu.default()}}. } \examples{ -\dontrun{ # Numerical input relu(4) relu(-10:10) @@ -36,7 +35,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' ReLU_x <- relu(x_i) # symbolic matrix, 150 rows and 3 columns } -} \references{ \insertRef{fukushima_cognitron_1975}{rkeops} } diff --git a/rkeops/man/rkeops-package.Rd b/rkeops/man/rkeops-package.Rd index 9cdedabf0..11bd07d3a 100644 --- a/rkeops/man/rkeops-package.Rd +++ b/rkeops/man/rkeops-package.Rd @@ -23,8 +23,7 @@ the computation of Kernel dot products and the associated gradients, even when the full kernel matrix does not fit into the GPU memory. For more information, please read the vignettes -(\code{browseVignettes("rkeops")}) and visit -\url{https://www.kernel-operations.io/}. +(\code{browseVignettes("rkeops")}) and visit \url{https://www.kernel-operations.io/}. } \references{ \insertRef{JMLR:v22:20-275}{rkeops} @@ -40,12 +39,12 @@ Useful links: } \author{ \itemize{ -\item \href{http://imag.umontpellier.fr/~charlier/}{Benjamin Charlier} +\item \href{https://miat.inrae.fr/bcharlier/}{Benjamin Charlier} \item Amelie Vernay \item Chloe Serre-Combe \item \href{https://gdurif.perso.math.cnrs.fr/}{Ghislain Durif} \item \href{https://www.jeanfeydy.com}{Jean Feydy} -\item \href{http://helios.mi.parisdescartes.fr/~glaunes/}{Joan Alexis Glaunès} -\item François-David Collin +\item \href{https://helios2.mi.parisdescartes.fr/~glaunes/}{Joan Alexis Glaunès} +\item \href{https://fradav.perso.math.cnrs.fr/}{François-David Collin} } } diff --git a/rkeops/man/rkeops_disable_verbosity.Rd b/rkeops/man/rkeops_disable_verbosity.Rd index 94e9a17aa..a615066f7 100644 --- a/rkeops/man/rkeops_disable_verbosity.Rd +++ b/rkeops/man/rkeops_disable_verbosity.Rd @@ -13,8 +13,10 @@ None Disable verbosity during operator compilation process. } \examples{ -\dontrun{ rkeops_disable_verbosity() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/rkeops_enable_verbosity.Rd b/rkeops/man/rkeops_enable_verbosity.Rd index f12c37f92..cfaadb8a3 100644 --- a/rkeops/man/rkeops_enable_verbosity.Rd +++ b/rkeops/man/rkeops_enable_verbosity.Rd @@ -13,8 +13,10 @@ None Enable verbosity during operator compilation process. } \examples{ -\dontrun{ rkeops_enable_verbosity() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/rkeops_use_cpu.Rd b/rkeops/man/rkeops_use_cpu.Rd index 316416b2e..fcaf5e47d 100644 --- a/rkeops/man/rkeops_use_cpu.Rd +++ b/rkeops/man/rkeops_use_cpu.Rd @@ -29,8 +29,10 @@ the number of cores used by \code{rkeops} user-defined operators, you can used the input parameter \code{ncore}. } \examples{ -\dontrun{ rkeops_use_cpu() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/rkeops_use_float32.Rd b/rkeops/man/rkeops_use_float32.Rd index cb1180f1d..fb677f46d 100644 --- a/rkeops/man/rkeops_use_float32.Rd +++ b/rkeops/man/rkeops_use_float32.Rd @@ -27,8 +27,10 @@ output are converted to 32bit float before computation and back to 64bit float after computation. } \examples{ -\dontrun{ rkeops_use_float32() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/rkeops_use_float64.Rd b/rkeops/man/rkeops_use_float64.Rd index b4f6f0919..843821d4d 100644 --- a/rkeops/man/rkeops_use_float64.Rd +++ b/rkeops/man/rkeops_use_float64.Rd @@ -24,8 +24,10 @@ accuracy of your computation and validity of your results in certain applications. } \examples{ -\dontrun{ rkeops_use_float64() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/rkeops_use_gpu.Rd b/rkeops/man/rkeops_use_gpu.Rd index 2b4626887..4f493838d 100644 --- a/rkeops/man/rkeops_use_gpu.Rd +++ b/rkeops/man/rkeops_use_gpu.Rd @@ -35,8 +35,10 @@ computations on GPU. To disable GPU computing, run \code{\link[=rkeops_use_cpu]{rkeops_use_cpu()}}. } \examples{ -\dontrun{ rkeops_use_gpu() +\dontshow{ +# set options back to default +set_rkeops_options() } } \seealso{ diff --git a/rkeops/man/round.LazyTensor.Rd b/rkeops/man/round.LazyTensor.Rd index de5131139..b8f02ff76 100644 --- a/rkeops/man/round.LazyTensor.Rd +++ b/rkeops/man/round.LazyTensor.Rd @@ -25,13 +25,11 @@ that encodes, symbolically, the element-wise rounding of \code{x} to \code{digit decimal places. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Round_x <- round(x_i, 2) # symbolic matrix } -} \seealso{ \code{\link[=round]{round()}} } diff --git a/rkeops/man/round.Rd b/rkeops/man/round.Rd index bcddcaa58..d875db001 100644 --- a/rkeops/man/round.Rd +++ b/rkeops/man/round.Rd @@ -24,7 +24,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=round.LazyTensor]{round.Laz see \code{\link[=round.default]{round.default()}}. } \examples{ -\dontrun{ # R base operation round(5) round(runif(10), 4) @@ -34,7 +33,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Round_x <- round(x_i, 2) # symbolic matrix } -} \seealso{ \code{\link[=round.default]{round.default()}}, \code{\link[=round.LazyTensor]{round.LazyTensor()}} } diff --git a/rkeops/man/round.default.Rd b/rkeops/man/round.default.Rd index 52fb6d248..7d96d40f0 100644 --- a/rkeops/man/round.default.Rd +++ b/rkeops/man/round.default.Rd @@ -14,6 +14,9 @@ (\code{round}) or significant digits (\code{signif}) to be used. For \code{round}, negative values are allowed (see \sQuote{Details}).} } +\value{ +See 'Details' section. +} \description{ \code{ceiling} takes a single numeric argument \code{x} and returns a numeric vector containing the smallest integers not less than the diff --git a/rkeops/man/rsqrt.LazyTensor.Rd b/rkeops/man/rsqrt.LazyTensor.Rd index 8cbe9ae71..c0501fa5b 100644 --- a/rkeops/man/rsqrt.LazyTensor.Rd +++ b/rkeops/man/rsqrt.LazyTensor.Rd @@ -23,13 +23,11 @@ encodes, symbolically, the element-wise inverse square root of \code{x}, i.e. \eqn{1/\sqrt{x}}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Rsqrt_x <- rsqrt(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=rsqrt]{rsqrt()}} } diff --git a/rkeops/man/rsqrt.Rd b/rkeops/man/rsqrt.Rd index 9269ae1c7..03372b75f 100644 --- a/rkeops/man/rsqrt.Rd +++ b/rkeops/man/rsqrt.Rd @@ -24,7 +24,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=rsqrt.LazyTensor]{rsqrt.Laz see \code{\link[=rsqrt.default]{rsqrt.default()}}. } \examples{ -\dontrun{ # Numerical input rsqrt(4) rsqrt(c(1,4,9,16)) @@ -34,7 +33,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Rsqrt_x <- rsqrt(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=rsqrt.default]{rsqrt.default()}}, \code{\link[=rsqrt.LazyTensor]{rsqrt.LazyTensor()}} } diff --git a/rkeops/man/scalar.product.LazyTensor.Rd b/rkeops/man/scalar.product.LazyTensor.Rd index 032f9bf34..cfc4bf87c 100644 --- a/rkeops/man/scalar.product.LazyTensor.Rd +++ b/rkeops/man/scalar.product.LazyTensor.Rd @@ -27,7 +27,6 @@ a vector or a scalar, it is first converted to \code{LazyTensor}). \strong{Note}: \code{x} and \code{y} input arguments should have the same inner dimension. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns y <- matrix(runif(250 * 3), 250, 3) # arbitrary R matrix, 250 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -36,7 +35,6 @@ y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, # indexed by 'j' x_sp_y <- x_i | y_j # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/set_pykeops_verbosity.Rd b/rkeops/man/set_pykeops_verbosity.Rd deleted file mode 100644 index ac8e4b941..000000000 --- a/rkeops/man/set_pykeops_verbosity.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/keops_setup.R -\name{set_pykeops_verbosity} -\alias{set_pykeops_verbosity} -\title{Set PyKeOps verbosity} -\usage{ -set_pykeops_verbosity() -} -\value{ -None -} -\description{ -Enable or disable verbosity during operator compilation process in PyKeops -using current verbosity status in RKeOps options. -} -\details{ -\strong{Note:} this is an internal function, user should use -\code{\link[=rkeops_enable_verbosity]{rkeops_enable_verbosity()}} or \code{\link[=rkeops_disable_verbosity]{rkeops_disable_verbosity()}}. -} -\examples{ -\dontrun{ -set_pykeops_verbosity() -} -} -\seealso{ -\code{\link[=setup_pykeops]{setup_pykeops()}} -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/set_rkeops_cache_dir.Rd b/rkeops/man/set_rkeops_cache_dir.Rd index 3dd8cf5df..ef448ad5c 100644 --- a/rkeops/man/set_rkeops_cache_dir.Rd +++ b/rkeops/man/set_rkeops_cache_dir.Rd @@ -43,9 +43,13 @@ to (fully or partially) delete its content. the default rkeops cache directory. } \examples{ +# use default cache directory +set_rkeops_cache_dir() \dontrun{ -set_rkeops_build_dir() +# edit path at your convenience +set_rkeops_cache_dir("/path/to/a/specific/directory") } + } \seealso{ \code{\link[=get_rkeops_cache_dir]{get_rkeops_cache_dir()}}, \code{\link[=stat_rkeops_cache_dir]{stat_rkeops_cache_dir()}}, diff --git a/rkeops/man/set_rkeops_options.Rd b/rkeops/man/set_rkeops_options.Rd index ebe8f1396..097ba4634 100644 --- a/rkeops/man/set_rkeops_options.Rd +++ b/rkeops/man/set_rkeops_options.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/rkeops_options.R \name{set_rkeops_options} \alias{set_rkeops_options} -\title{Get or set the current \code{rkeops} options in \code{R} global options scope} +\title{Set the current \code{rkeops} options in \code{R} global options scope} \usage{ set_rkeops_options(input = NULL) } @@ -55,6 +55,10 @@ recompilation). \examples{ set_rkeops_options() set_rkeops_options(list(verbosity = 0)) +\dontshow{ +# set options back to default +set_rkeops_options() +} } \seealso{ diff --git a/rkeops/man/setup_pykeops.Rd b/rkeops/man/setup_pykeops.Rd deleted file mode 100644 index 244e00019..000000000 --- a/rkeops/man/setup_pykeops.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/keops_setup.R -\name{setup_pykeops} -\alias{setup_pykeops} -\title{Setup PyKeOps before using it} -\usage{ -setup_pykeops() -} -\value{ -None -} -\description{ -Wrapper function to call all setup functions for PyKeOps including: -\itemize{ -\item \code{\link[=set_pykeops_verbosity]{set_pykeops_verbosity()}} to set verbosity -\item \code{\link[=set_pykeops_build_dir]{set_pykeops_build_dir()}} to set build directory -} -} -\details{ -\strong{Note:} this is an internal function, user should use -\code{\link[=rkeops_enable_verbosity]{rkeops_enable_verbosity()}} or \code{\link[=rkeops_disable_verbosity]{rkeops_disable_verbosity()}} -for verbosity setup, \code{\link[=get_rkeops_cache_dir]{get_rkeops_cache_dir()}} or -\code{\link[=set_rkeops_cache_dir]{set_rkeops_cache_dir()}} for cache/build directory setup. -} -\examples{ -\dontrun{ -setup_pykeops() -} -} -\seealso{ -\code{\link[=set_pykeops_verbosity]{set_pykeops_verbosity()}}, \code{\link[=set_pykeops_build_dir]{set_pykeops_build_dir()}} -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/sign.LazyTensor.Rd b/rkeops/man/sign.LazyTensor.Rd index aa10d6bcf..bfd02ee4f 100644 --- a/rkeops/man/sign.LazyTensor.Rd +++ b/rkeops/man/sign.LazyTensor.Rd @@ -27,13 +27,11 @@ encodes, symbolically, the element-wise sign of \code{x}, i.e. \end{array}\right.} } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sign_x <- sign(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sign]{sign()}} } diff --git a/rkeops/man/sign.Rd b/rkeops/man/sign.Rd index 49dc8f0c6..90971da83 100644 --- a/rkeops/man/sign.Rd +++ b/rkeops/man/sign.Rd @@ -29,7 +29,6 @@ The sign function is defined as follows: \end{array}\right.} } \examples{ -\dontrun{ # R base operation sign(5) sign(-5) @@ -40,7 +39,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sign_x <- sign(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sign.default]{sign.default()}}, \code{\link[=sign.LazyTensor]{sign.LazyTensor()}} } diff --git a/rkeops/man/sign.default.Rd b/rkeops/man/sign.default.Rd index 000cfca91..7ac692df1 100644 --- a/rkeops/man/sign.default.Rd +++ b/rkeops/man/sign.default.Rd @@ -9,6 +9,9 @@ \arguments{ \item{x}{a numeric vector} } +\value{ +See 'Details' section. +} \description{ \code{sign} returns a vector with the signs of the corresponding elements of \code{x} (the sign of a real number is 1, 0, or \eqn{-1} diff --git a/rkeops/man/sin.LazyTensor.Rd b/rkeops/man/sin.LazyTensor.Rd index a90bd2d26..07ada1db6 100644 --- a/rkeops/man/sin.LazyTensor.Rd +++ b/rkeops/man/sin.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{sin(x)} returns a \code{LazyTensor} th encodes, symbolically, the element-wise sine of \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sin_x <- sin(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sin]{sin()}} } diff --git a/rkeops/man/sin.Rd b/rkeops/man/sin.Rd index 1cb2e1e05..8d8d63fa1 100644 --- a/rkeops/man/sin.Rd +++ b/rkeops/man/sin.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=sin.LazyTensor]{sin.LazyTen see \code{\link[=sin.default]{sin.default()}}. } \examples{ -\dontrun{ # R base operation sin(0) sin(pi) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sin_x <- sin(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sin.default]{sin.default()}}, \code{\link[=sin.LazyTensor]{sin.LazyTensor()}} } diff --git a/rkeops/man/sinxdivx.LazyTensor.Rd b/rkeops/man/sinxdivx.LazyTensor.Rd index 59fd91df3..a24986f0b 100644 --- a/rkeops/man/sinxdivx.LazyTensor.Rd +++ b/rkeops/man/sinxdivx.LazyTensor.Rd @@ -23,13 +23,11 @@ encodes, symbolically, the element-wise \code{sin(x)/x} values for \code{x}. \strong{Note}: by convention \code{sinxdivx(0)} returns \code{1}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' sindiv_x <- sinxdivx(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sinxdivx]{sinxdivx()}} } diff --git a/rkeops/man/sinxdivx.Rd b/rkeops/man/sinxdivx.Rd index 7ea858f96..bc23e94db 100644 --- a/rkeops/man/sinxdivx.Rd +++ b/rkeops/man/sinxdivx.Rd @@ -25,7 +25,6 @@ else see \code{\link[=sinxdivx.default]{sinxdivx.default()}}. \strong{Note}: by convention \code{sinxdivx(0)} returns \code{1}. } \examples{ -\dontrun{ # Numerical input sinxdivx(4) sinxdivx(1:10) @@ -35,7 +34,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' sindiv_x <- sinxdivx(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sinxdivx.default]{sinxdivx.default()}}, \code{\link[=sinxdivx.LazyTensor]{sinxdivx.LazyTensor()}} } diff --git a/rkeops/man/sqdist.Rd b/rkeops/man/sqdist.Rd index 891f1b86d..c9fc3fc9a 100644 --- a/rkeops/man/sqdist.Rd +++ b/rkeops/man/sqdist.Rd @@ -28,13 +28,14 @@ the squared Euclidean distance between \code{x} and \code{y}, same as \code{sqno or be of dimension 1. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns +y <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' +y_j <- LazyTensor(y, index = 'j') # creating LazyTensor from matrix y, + # indexed by 'j' -SqD_x <- sqdist(x_i) # symbolic matrix, 150 rows and 3 columns -} +SqD_x <- sqdist(x_i, y_j) # symbolic matrix, 150 rows and 3 columns } \seealso{ \code{\link[=sqnorm2]{sqnorm2()}} diff --git a/rkeops/man/sqnorm2.Rd b/rkeops/man/sqnorm2.Rd index d4424b02c..bd8315d84 100644 --- a/rkeops/man/sqnorm2.Rd +++ b/rkeops/man/sqnorm2.Rd @@ -21,13 +21,11 @@ Symbolic squared Euclidean norm operation for \code{LazyTensor} objects. the squared Euclidean norm of \code{x}, same as \code{(x|x)}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' SqN_x <- sqnorm2(x_i) # symbolic matrix, 150 rows, 1 columns } -} \seealso{ \code{\link[=|.LazyTensor]{|.LazyTensor()}} } diff --git a/rkeops/man/sqrt.LazyTensor.Rd b/rkeops/man/sqrt.LazyTensor.Rd index ca2776070..211a35965 100644 --- a/rkeops/man/sqrt.LazyTensor.Rd +++ b/rkeops/man/sqrt.LazyTensor.Rd @@ -22,13 +22,11 @@ encodes, symbolically, the element-wise square root of \code{x}, i.e. \eqn{\sqrt{x}}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sqrt_x <- sqrt(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sqrt]{sqrt()}} } diff --git a/rkeops/man/sqrt.Rd b/rkeops/man/sqrt.Rd index 4f95fb1a7..d72b454fa 100644 --- a/rkeops/man/sqrt.Rd +++ b/rkeops/man/sqrt.Rd @@ -25,7 +25,6 @@ see \code{\link[=sqrt.default]{sqrt.default()}}. corresponds to the complex modulus \code{sqrt(z) = z^0.5}. } \examples{ -\dontrun{ # R base operation sqrt(4) sqrt(c(1,4,9,16)) @@ -35,7 +34,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Sqrt_x <- sqrt(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=sqrt.default]{sqrt.default()}}, \code{\link[=sqrt.LazyTensor]{sqrt.LazyTensor()}} } diff --git a/rkeops/man/square.LazyTensor.Rd b/rkeops/man/square.LazyTensor.Rd index 96f98ac89..ad9cb130f 100644 --- a/rkeops/man/square.LazyTensor.Rd +++ b/rkeops/man/square.LazyTensor.Rd @@ -21,13 +21,11 @@ If \code{x} is a \code{LazyTensor}, \code{square(x)} returns a \code{LazyTensor} encodes, symbolically, the element-wise square of \code{x}, i.e. \eqn{x^2}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Square_x <- square(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=square]{square()}} } diff --git a/rkeops/man/square.Rd b/rkeops/man/square.Rd index f5522eeb8..0f49b6875 100644 --- a/rkeops/man/square.Rd +++ b/rkeops/man/square.Rd @@ -23,7 +23,6 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=square.LazyTensor]{square.L see \code{\link[=square.default]{square.default()}}. } \examples{ -\dontrun{ # Numerical input square(4) square(1:4) @@ -33,7 +32,6 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' Square_x <- square(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=square.default]{square.default()}}, \code{\link[=square.LazyTensor]{square.LazyTensor()}} } diff --git a/rkeops/man/stat_dir.Rd b/rkeops/man/stat_dir.Rd deleted file mode 100644 index 5e7989e31..000000000 --- a/rkeops/man/stat_dir.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{stat_dir} -\alias{stat_dir} -\title{Disk usage of a given directory} -\usage{ -stat_dir(path) -} -\arguments{ -\item{path}{character string, path to directory for which the disk -usage will be computed.} -} -\value{ -character string, a disk usage in (G/M/K)bytes. -} -\description{ -Sum the sizes of all files in a given folder and its sub-directories. -} -\author{ -Ghislain Durif -} -\keyword{internal} diff --git a/rkeops/man/stat_rkeops_cache_dir.Rd b/rkeops/man/stat_rkeops_cache_dir.Rd index d58a2d95f..87de0bcbf 100644 --- a/rkeops/man/stat_rkeops_cache_dir.Rd +++ b/rkeops/man/stat_rkeops_cache_dir.Rd @@ -38,9 +38,8 @@ directory, and you can use \code{\link[=clean_rkeops]{clean_rkeops()}} to (fully delete its content. } \examples{ -\dontrun{ stat_rkeops_cache_dir() -} + } \seealso{ \code{\link[=get_rkeops_cache_dir]{get_rkeops_cache_dir()}}, \code{\link[=clean_rkeops]{clean_rkeops()}} diff --git a/rkeops/man/step.LazyTensor.Rd b/rkeops/man/step.LazyTensor.Rd index 5f216d246..35f619cff 100644 --- a/rkeops/man/step.LazyTensor.Rd +++ b/rkeops/man/step.LazyTensor.Rd @@ -25,12 +25,10 @@ that encodes, symbolically, the element-wise 0-1 step of \code{x}, i.e. \code{0} if \code{x < 0}, \code{1} if \code{x >= 0}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' -Step_x <- step.LazyTensor(x_i) # symbolic matrix, 150 rows and 3 columns -} +Step_x <- step(x_i) # symbolic matrix, 150 rows and 3 columns } \seealso{ \code{\link[=step]{step()}} diff --git a/rkeops/man/step.Rd b/rkeops/man/step.Rd index a6a4ed717..5f06c2f3d 100644 --- a/rkeops/man/step.Rd +++ b/rkeops/man/step.Rd @@ -26,14 +26,12 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=step.LazyTensor]{step.LazyT see \code{\link[=step.default]{step.default()}}. } \examples{ -\dontrun{ # R base operation: see `?step.default` # LazyTensor symbolic element-wise sign x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' -Step_x <- step.LazyTensor(x_i) # symbolic matrix, 150 rows and 3 columns -} +Step_x <- step(x_i) # symbolic matrix, 150 rows and 3 columns } \seealso{ \code{\link[=step.default]{step.default()}}, \code{\link[=step.LazyTensor]{step.LazyTensor()}} diff --git a/rkeops/man/sum.LazyTensor.Rd b/rkeops/man/sum.LazyTensor.Rd index 7d7b587ee..87778cab9 100644 --- a/rkeops/man/sum.LazyTensor.Rd +++ b/rkeops/man/sum.LazyTensor.Rd @@ -44,21 +44,42 @@ section \emph{"Reductions"}. \code{sum_reduction()} function. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' sum_x <- sum(x_i) # LazyTensor object sum_red_x <- sum(x_i, "i") # sum reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) } - -\dontrun{ +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' sum_reduction(x_i, "i") +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \seealso{ diff --git a/rkeops/man/sum.Rd b/rkeops/man/sum.Rd index 50af4c8af..285fa0137 100644 --- a/rkeops/man/sum.Rd +++ b/rkeops/man/sum.Rd @@ -24,10 +24,17 @@ If \code{x} is a \code{LazyTensor}, see \code{\link[=sum.LazyTensor]{sum.LazyTen \code{\link[=sum.default]{sum.default()}}. } \examples{ -\dontrun{ # R base operation sum(1:10) sum(c(NA, 1, 2), na.rm = TRUE) +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} # LazyTensor operation x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -35,6 +42,10 @@ x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, sum_x <- sum(x_i) # LazyTensor object sum_red_x <- sum(x_i, "i") # sum reduction indexed by 'i' +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/sumsoftmaxweight.Rd b/rkeops/man/sumsoftmaxweight.Rd index 7dd22a198..9c39b128e 100644 --- a/rkeops/man/sumsoftmaxweight.Rd +++ b/rkeops/man/sumsoftmaxweight.Rd @@ -42,7 +42,14 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Reductions"}. } \examples{ -\dontrun{ +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) +} x <- matrix(runif(150 * 3), 150, 3) x_i <- LazyTensor(x, index = 'i') y <- matrix(runif(100 * 3), 100, 3) @@ -53,19 +60,33 @@ S_ij = sum(V_ij^2) ssmaxweight <- sumsoftmaxweight(S_ij, 'i', V_ij) # sumsoftmaxweight reduction # over the 'i' indices +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} +} +\donttest{ +\dontshow{ +# Specific setup for example runs (not necessary for standard use) +reticulate::py_available(initialize = TRUE) +set_rkeops_options() +# For build on CRAN, use CPU computing with 2 cores max +rkeops_use_cpu(ncore = 2) } -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) x_i <- LazyTensor(x, index = 'i') y <- matrix(runif(100 * 3), 100, 3) y_j <- LazyTensor(y, index = 'j') V_ij <- x_i - y_j # weight matrix -S_ij = sum(V-ij^2) +S_ij = sum(V_ij^2) # sumsoftmaxweight reduction over the 'i' indices ssmaxw_red <- sumsoftmaxweight_reduction(S_ij, 'i', V_ij) - +\dontshow{ +# clean-up (for CRAN build) +clean_rkeops(remove_cache_dir = TRUE) +} } } \author{ diff --git a/rkeops/man/tensorprod.Rd b/rkeops/man/tensorprod.Rd index 7f19db5d7..2dd5510ad 100644 --- a/rkeops/man/tensorprod.Rd +++ b/rkeops/man/tensorprod.Rd @@ -24,15 +24,12 @@ symbolically, the tensor product between matrix \code{x} and \code{y}, which is a symbolic matrix of dimension (\code{nx*ny}, \code{px*py}). } \examples{ -\dontrun{ x <- matrix(c(1, 2, 3), 2, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # LazyTensor from matrix x, indexed by 'i' y <- matrix(c(1, 1, 1), 2, 3) # arbitrary R matrix, 200 rows, 3 columns y_i <- LazyTensor(y, index = 'i') # LazyTensor from matrix y, indexed by 'i' -tp_xy <- tensorprod(x_i, y_i) # symbolic (4, 9) matrix. - -} +tp_xy <- tensorprod(x_i, y_i) # symbolic (4, 9) matrix. } \author{ Chloe Serre-Combe, Amelie Vernay diff --git a/rkeops/man/ternaryop.LazyTensor.Rd b/rkeops/man/ternaryop.LazyTensor.Rd index 3bd5d04b6..588f85160 100644 --- a/rkeops/man/ternaryop.LazyTensor.Rd +++ b/rkeops/man/ternaryop.LazyTensor.Rd @@ -39,7 +39,6 @@ An object of class "LazyTensor". Symbolically applies \code{opstr} operation to \code{x}, \code{y} and \code{z}. } \examples{ -\dontrun{ # basic example D <- 3 M <- 100 @@ -55,7 +54,6 @@ z_i <- LazyTensor(z, index = 'i') # symbolic matrix: tern_xyz <- ternaryop.LazyTensor(x_i, y_j, z_i, "IfElse") } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/unaryop.LazyTensor.Rd b/rkeops/man/unaryop.LazyTensor.Rd index ae1650fff..de4fe9a4f 100644 --- a/rkeops/man/unaryop.LazyTensor.Rd +++ b/rkeops/man/unaryop.LazyTensor.Rd @@ -39,7 +39,6 @@ An object of class "LazyTensor" or "ComplexLazyTensor". Symbolically applies \code{opstr} operation to \code{x}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' @@ -49,10 +48,9 @@ una2_x <- unaryop.LazyTensor(x_i, "Pow", opt_arg = 3) # symbolic matrix # example with not NA dim_res: ## set dim_res to 1 because the "Norm2" operation results on a (symbolic) scalar -una3_x <- unaryop.LazyTensor(x, "Norm2", - res_type = "LazyTensor", - dim_res = 1) -} +una3_x <- unaryop.LazyTensor( + x_i, "Norm2", res_type = "LazyTensor", dim_res = 1 +) } \author{ Chloe Serre-Combe, Amelie Vernay diff --git a/rkeops/man/vecmatmult.Rd b/rkeops/man/vecmatmult.Rd index 9effb143b..b6f784a26 100644 --- a/rkeops/man/vecmatmult.Rd +++ b/rkeops/man/vecmatmult.Rd @@ -25,7 +25,6 @@ of vector \code{v} and matrix \code{m}. of dimension 1. } \examples{ -\dontrun{ v <- c(1,2,3) # arbitrary R vector of length 3 m <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns Pm_v <- LazyTensor(v) # parameter vector LazyTensor from v @@ -33,7 +32,6 @@ m_i <- LazyTensor(m, index = 'i') # LazyTensor from matrix m, indexed by 'i' vm_mult <- vecmatmult(Pm_v, m_i) # symbolic matrix } -} \author{ Chloe Serre-Combe, Amelie Vernay } diff --git a/rkeops/man/weightedsqdist.Rd b/rkeops/man/weightedsqdist.Rd index 00b33a8e2..61f856805 100644 --- a/rkeops/man/weightedsqdist.Rd +++ b/rkeops/man/weightedsqdist.Rd @@ -34,7 +34,6 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Simple vector operations"}. } \examples{ -\dontrun{ x <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns y <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns s <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns @@ -48,7 +47,6 @@ s_i <- LazyTensor(s, index = 'i') # creating LazyTensor from matrix s, wsqd_xy <- weightedsqdist(x_i, y_j, s_i) # symbolic matrix } -} \seealso{ \code{\link[=weightedsqnorm]{weightedsqnorm()}}, \code{\link[=sqdist]{sqdist()}} } diff --git a/rkeops/man/weightedsqnorm.Rd b/rkeops/man/weightedsqnorm.Rd index c3be44836..e8df4af60 100644 --- a/rkeops/man/weightedsqnorm.Rd +++ b/rkeops/man/weightedsqnorm.Rd @@ -31,7 +31,6 @@ details about this function in the \emph{"RKeOps LazyTensor"} vignette, at section \emph{"Simple vector operations"}. } \examples{ -\dontrun{ x <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns s <- matrix(runif(100 * 3), 100, 3) # arbitrary R matrix, 100 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, @@ -40,7 +39,6 @@ s_j <- LazyTensor(s, index = 'j') # creating LazyTensor from matrix s, # indexed by 'j' wsqn_xy <- weightedsqnorm(x_i, s_j) # symbolic matrix, 100 rows,1 columns } -} \seealso{ \code{\link[=sqnorm2]{sqnorm2()}}, \code{\link[=weightedsqdist]{weightedsqdist()}} } diff --git a/rkeops/man/xlogx.LazyTensor.Rd b/rkeops/man/xlogx.LazyTensor.Rd index 21834c760..9bc7feafe 100644 --- a/rkeops/man/xlogx.LazyTensor.Rd +++ b/rkeops/man/xlogx.LazyTensor.Rd @@ -23,13 +23,11 @@ encodes, symbolically, the element-wise \code{x*log(x)} values for \code{x}. \strong{Note}: by convention \code{xlogx(0)} returns \code{0}. } \examples{ -\dontrun{ x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' xlog_x <- xlogx(x_i) # symbolic matrix, 150 rows and 3 columnsjs } -} \seealso{ \code{\link[=xlogx]{xlogx()}} } diff --git a/rkeops/man/xlogx.Rd b/rkeops/man/xlogx.Rd index 5e5c4244a..95ba9e7cd 100644 --- a/rkeops/man/xlogx.Rd +++ b/rkeops/man/xlogx.Rd @@ -25,17 +25,15 @@ else see \code{\link[=xlogx.default]{xlogx.default()}}. \strong{Note}: by convention \code{xlogx(0)} returns \code{0}. } \examples{ -\dontrun{ # Numerical input -xlog(4) -xlog(1:10) +xlogx(4) +xlogx(1:10) # LazyTensor symbolic element-wise `x*log(x)` x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns x_i <- LazyTensor(x, index = 'i') # creating LazyTensor from matrix x, # indexed by 'i' xlog_x <- xlogx(x_i) # symbolic matrix, 150 rows and 3 columns } -} \seealso{ \code{\link[=xlogx.default]{xlogx.default()}}, \code{\link[=xlogx.LazyTensor]{xlogx.LazyTensor()}} } diff --git a/rkeops/tests/testthat/setup.R b/rkeops/tests/testthat/setup.R index b84331c8d..124c851f2 100644 --- a/rkeops/tests/testthat/setup.R +++ b/rkeops/tests/testthat/setup.R @@ -6,6 +6,7 @@ skip_if_not_installed("fs") library(checkmate) library(withr) library(fs) +library(stringr) # helper function to skip tests if Python is not available on the system skip_if_no_python <- function() { diff --git a/rkeops/tests/testthat/test-01_install.R b/rkeops/tests/testthat/test-01_py_req.R similarity index 64% rename from rkeops/tests/testthat/test-01_install.R rename to rkeops/tests/testthat/test-01_py_req.R index eb0f32804..7e4bf77a3 100644 --- a/rkeops/tests/testthat/test-01_install.R +++ b/rkeops/tests/testthat/test-01_py_req.R @@ -3,6 +3,7 @@ test_that("install_rkeops", { withr::with_options(list(rkeops = NULL), { set_rkeops_options() - expect_error(install_rkeops(), NA) + setup_pyreq() + expect_true(reticulate::py_available("pykeops")) }) }) diff --git a/rkeops/tests/testthat/test-01_starting.R b/rkeops/tests/testthat/test-01_starting.R deleted file mode 100644 index 3506dc12a..000000000 --- a/rkeops/tests/testthat/test-01_starting.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("helloWorld", { - expect_output(helloWorld(), "Hello user of KeOps") -}) diff --git a/rkeops/tests/testthat/test-02_utils.R b/rkeops/tests/testthat/test-02_utils.R index 11af437be..5a1a081b7 100644 --- a/rkeops/tests/testthat/test-02_utils.R +++ b/rkeops/tests/testthat/test-02_utils.R @@ -30,10 +30,16 @@ test_that("random_varname", { test_that("stat_dir", { # empty dir withr::with_tempdir({ - checkmate::expect_string( - stat_dir(getwd()), pattern = "[0-9]+(.[0-9])*[KMG]?") + res <- stat_dir(getwd()) + checkmate::expect_string(res, pattern = "[0-9]+(.[0-9])*[KMG]?") + expect_equal(res, "0") }) # current dir checkmate::expect_string( - stat_dir(getwd()), pattern = "[0-9]+(.[0-9])*[KMG]?") + stat_dir(getwd()), + pattern = "[0-9]+(.[0-9])*[KMG]?" + ) + # non existing directory + expect_warning({res <- stat_dir("/not/existing/dir", warn = TRUE)}) + expect_equal(res, "0") }) diff --git a/rkeops/tests/testthat/test-03_rkeops_options.R b/rkeops/tests/testthat/test-03_rkeops_options.R index ee531b280..2e248f7ef 100644 --- a/rkeops/tests/testthat/test-03_rkeops_options.R +++ b/rkeops/tests/testthat/test-03_rkeops_options.R @@ -1,12 +1,13 @@ test_that("def_rkeops_options", { + # default options res <- def_rkeops_options() expect_equal(class(res), "rkeops_options") - checkmate::expect_list(res, len = 6) + checkmate::expect_list(res, len = 7) checkmate::expect_set_equal( names(res), c("backend", "device_id", "precision", "verbosity", "debug", - "cache_dir")) + "cache_dir", "formula_only")) checkmate::expect_choice(res$backend, c("CPU", "GPU")) checkmate::expect_integerish(res$device_id) checkmate::expect_choice(res$precision, c("float32", "float64")) @@ -14,16 +15,17 @@ test_that("def_rkeops_options", { checkmate::expect_choice(res$debug, c(0, 1)) checkmate::expect_directory(res$cache_dir) + # modify cache directory res <- def_rkeops_options( backend = "CPU", device_id = -1, precision = "float32", verbosity = FALSE, debug = FALSE, cache_dir = getwd()) expect_equal(class(res), "rkeops_options") - checkmate::expect_list(res, len = 6) + checkmate::expect_list(res, len = 7) checkmate::expect_set_equal( names(res), c("backend", "device_id", "precision", "verbosity", "debug", - "cache_dir")) + "cache_dir", "formula_only")) checkmate::expect_choice(res$backend, c("CPU", "GPU")) checkmate::expect_integerish(res$device_id) checkmate::expect_choice(res$precision, c("float32", "float64")) @@ -31,12 +33,14 @@ test_that("def_rkeops_options", { checkmate::expect_choice(res$debug, c(0, 1)) expect_equal(res$cache_dir, getwd()) + # bad input expect_error(def_rkeops_options(backend = "TPU")) expect_error(def_rkeops_options(device_id = 2.5)) expect_error(def_rkeops_options(precision = "integer")) expect_error(def_rkeops_options(verbosity = "FALSE")) expect_error(def_rkeops_options(debug = "FALSE")) - expect_error(def_rkeops_options(cache_dir = "/not/existing/dir")) + expect_warning(def_rkeops_options(cache_dir = "/not/existing/dir")) + expect_error(def_rkeops_options(formula_only = "TRUE")) }) test_that("get_rkeops_options", { @@ -204,6 +208,19 @@ test_that("set_rkeops_cache_dir", { checkmate::expect_directory(getOption("rkeops")$cache_dir) expect_equal(getOption("rkeops")$cache_dir, getwd()) }) + + withr::with_options(list(rkeops = NULL), { + # set options + set_rkeops_options() + # specific dir + expect_warning(set_rkeops_cache_dir( + "/not/existing/dir", verbose = FALSE + )) + + # check cache dir + expect_error(checkmate::expect_directory(getOption("rkeops")$cache_dir)) + expect_equal(getOption("rkeops")$cache_dir, "/not/existing/dir") + }) }) test_that("default_rkeops_cache_dir", { diff --git a/rkeops/tests/testthat/test-04_keops_setup.R b/rkeops/tests/testthat/test-04_keops_setup.R index cb8dd788d..7f4d62750 100644 --- a/rkeops/tests/testthat/test-04_keops_setup.R +++ b/rkeops/tests/testthat/test-04_keops_setup.R @@ -54,6 +54,7 @@ test_that("setup_pykeops", { setup_pykeops() expect_equal(def_pykeops_build_dir(), pykeops$get_build_folder()) expect_equal( - as.logical(get_rkeops_options("verbosity")), pykeops$verbose) + as.logical(get_rkeops_options("verbosity")), pykeops$verbose + ) }) }) diff --git a/rkeops/tests/testthat/test-04_keops_utils.R b/rkeops/tests/testthat/test-04_keops_utils.R index 29fa1d951..14dbfdc77 100644 --- a/rkeops/tests/testthat/test-04_keops_utils.R +++ b/rkeops/tests/testthat/test-04_keops_utils.R @@ -1,5 +1,8 @@ test_that("get_pykeops_formula", { + formula <- "Sum_Reduction((x|y, 1)" + expect_error(res <- get_pykeops_formula(formula)) + formula <- "Sum_Reduction(Exp(-s * SqNorm2(x - y)) * b, 1)" res <- get_pykeops_formula(formula) expect_equal( diff --git a/rkeops/tests/testthat/test-07_keops_kernel.R b/rkeops/tests/testthat/test-07_keops_kernel.R index 2cebced8f..d4a90e4ee 100644 --- a/rkeops/tests/testthat/test-07_keops_kernel.R +++ b/rkeops/tests/testthat/test-07_keops_kernel.R @@ -3,13 +3,19 @@ test_that("keops_kernel", { skip_if_no_keopscore() skip_if_no_pykeops() + # clean running env withr::with_options(list(rkeops = NULL), { + # dedicated cache directory for tests set_rkeops_options(list(cache_dir = testing_cache_dir)) - ## computation on GPU ? - if(Sys.getenv("TEST_GPU") == "1") rkeops_use_gpu() + # setup computing resources (or skip if limited resources) + if(Sys.getenv("RUN_LONG_TEST") == "1") { + if(Sys.getenv("TEST_GPU") == "1") rkeops_use_gpu() + } else { + skip("Long tests: not running (e.g. during a package check)") + } - ## use float64 precision in test (to match R precision) + # use float64 precision in test (to match R precision) rkeops_use_float64() ## bad formula diff --git a/rkeops/tests/testthat/test-08_keops_grad.R b/rkeops/tests/testthat/test-08_keops_grad.R index 57dfd2bbb..b7383a2c1 100644 --- a/rkeops/tests/testthat/test-08_keops_grad.R +++ b/rkeops/tests/testthat/test-08_keops_grad.R @@ -49,13 +49,19 @@ test_that("keops_grad", { skip_if_no_keopscore() skip_if_no_pykeops() + # clean running env withr::with_options(list(rkeops = NULL), { + # dedicated cache directory for tests set_rkeops_options(list(cache_dir = testing_cache_dir)) - - ## computation on GPU ? - if(Sys.getenv("TEST_GPU") == "1") use_gpu() - ## use float64 precision in test (to match R precision) + # setup computing resources (or skip if limited resources) + if(Sys.getenv("RUN_LONG_TEST") == "1") { + if(Sys.getenv("TEST_GPU") == "1") rkeops_use_gpu() + } else { + skip("Long tests: not running (e.g. during a package check)") + } + + # use float64 precision in test (to match R precision) rkeops_use_float64() ## define an operator (squared norm reduction) diff --git a/rkeops/tests/testthat/test-09_lazytensor_preprocess.R b/rkeops/tests/testthat/test-09_lazytensor_preprocess.R index 61542458c..7e5fbb4ff 100644 --- a/rkeops/tests/testthat/test-09_lazytensor_preprocess.R +++ b/rkeops/tests/testthat/test-09_lazytensor_preprocess.R @@ -2,8 +2,19 @@ skip_if_no_python() skip_if_no_keopscore() skip_if_no_pykeops() +# clean running env +withr::with_options(list(rkeops = NULL), { + +# dedicated cache directory for tests set_rkeops_options(list(cache_dir = testing_cache_dir)) +# setup computing resources (or skip if limited resources) +if(Sys.getenv("RUN_LONG_TEST") == "1") { + if(Sys.getenv("TEST_GPU") == "1") rkeops_use_gpu() +} else { + skip("Long tests: not running (e.g. during a package check)") +} + # TEST LAZYTENSOR CONFIGURATION ================================================ # Tests for LazyTensor related functions @@ -973,15 +984,15 @@ test_that("fix_variables", { expect_equal(fix_variables(l)$formula, "IntCst(314)") expect_equal(fix_variables(l + l*l)$formula, - "IntCst(314)+IntCst(314)*IntCst(314)") + "Add(IntCst(314),Mult(IntCst(314),IntCst(314)))") expect_equal(fix_variables(x_i)$formula, "V0") expect_equal(fix_expr1$formula, - "V0+V1+V0+V2") + "Add(Add(Add(V0,V1),V0),V2)") expect_equal(fix_expr2$formula, - "Exp(Powf(SqDist(V0,V1),IntCst(314)))-V0*V2") + "Subtract(Exp(Powf(SqDist(V0,V1),IntCst(314))),Mult(V0,V2))") expect_equal(fix_expr3$formula, - "Norm2(V0)+(V1|V2)*IntCst(314)") + "Add(Norm2(V0),Mult((V1|V2),IntCst(314)))") expect_equal(fix_expr4$formula, "Clamp(V0,V1,V2)") @@ -995,9 +1006,11 @@ test_that("fix_variables", { expect_equal(fix_expr3$args[3], "V2=Vi(3)") # errors - expect_error(fix_variables(x), - "`x` input must be a LazyTensor or a ComplexLazyTensor.", - fixed = TRUE) + expect_error( + fix_variables(x), + "`x` input must be a LazyTensor or a ComplexLazyTensor.", + fixed = TRUE + ) }) @@ -1095,3 +1108,5 @@ test_that("cplx_warning", { cplx_warning(FALSE) # should not produce warning }) + +}) # withr::with_options \ No newline at end of file diff --git a/rkeops/tests/testthat/test-10_lazytensor_operations.R b/rkeops/tests/testthat/test-10_lazytensor_operations.R index 62ca9736e..10e51ead4 100644 --- a/rkeops/tests/testthat/test-10_lazytensor_operations.R +++ b/rkeops/tests/testthat/test-10_lazytensor_operations.R @@ -2,8 +2,19 @@ skip_if_no_python() skip_if_no_keopscore() skip_if_no_pykeops() +# clean running env +withr::with_options(list(rkeops = NULL), { + +# dedicated cache directory for tests set_rkeops_options(list(cache_dir = testing_cache_dir)) +# setup computing resources (or skip if limited resources) +if(Sys.getenv("RUN_LONG_TEST") == "1") { + if(Sys.getenv("TEST_GPU") == "1") rkeops_use_gpu() +} else { + skip("Long tests: not running (e.g. during a package check)") +} + # TEST ARITHMETIC OPERATIONS =================================================== @@ -47,55 +58,59 @@ test_that("+", { obj <- x_i + y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*i\\+A0x.*j", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- x_i + xc_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "Add\\(Real2Complex\\(A0x.*i\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(Real2Complex\\(A0x.*i\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i + x_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "Add\\(A0x.*i,Real2Complex\\(A0x.*i\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(A0x.*i,Real2Complex\\(A0x.*i\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i + 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Add\\(A0x.*i,Real2Complex\\(IntCst\\(3\\)\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(A0x.*i,Real2Complex\\(IntCst\\(3\\)\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- 3 + xc_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "Add\\(Real2Complex\\(IntCst\\(3\\)\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(Real2Complex\\(IntCst\\(3\\)\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i + 3 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("A0x.*i\\+IntCst\\(3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Add\\(A0x.*i,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 3.14 + x_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*NA\\+A0x.*i", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Add\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( x_i + z_j, - paste( - "Operation `+` expects inputs of the same dimension or dimension 1.", - " Received 3 and 7.", - sep = "" + str_c( + "Operation `Add` expects inputs of the same dimension", + "or dimension 1.", + "Received 3 and 7.", + sep = " " ), fixed = TRUE ) @@ -142,65 +157,67 @@ test_that("-", { obj <- x_i - y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*i-A0x.*j", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Subtract\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) obj <- xc_i - yc_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Subtract\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Subtract\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i - y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "Subtract\\(A0x.*i,Real2Complex\\(A0x.*j\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(A0x.*i,Real2Complex\\(A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- x_i - yc_j) - bool_grep_formula <- grep( - "Subtract\\(Real2Complex\\(A0x.*i\\),A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(Real2Complex\\(A0x.*i\\),A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i - 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "Subtract\\(A0x.*i,Real2Complex\\(IntCst\\(3\\)\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(A0x.*i,Real2Complex\\(IntCst\\(3\\)\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- 3.3 - xc_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "Subtract\\(Real2Complex\\(A0x.*NA\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(Real2Complex\\(A0x.*NA\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i - 3 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("A0x.*i-IntCst\\(3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(A0x.*i,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- -x_i expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Minus\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Minus\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 3.14 - x_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*NA-A0x.*i", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Subtract\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( x_i - z_j, - paste( - "Operation `-` expects inputs of the same dimension or dimension 1.", - " Received 3 and 7.", sep = "" + str_c( + "Operation `Subtract` expects inputs of the same dimension", + "or dimension 1. Received 3 and 7.", sep = " " ), fixed = TRUE ) @@ -246,74 +263,77 @@ test_that("*", { obj <- x_i * y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*i\\*A0x.*j", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mult\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- x_i * xc_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "ComplexMult\\(Real2Complex\\(A0x.*i\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexMult\\(Real2Complex\\(A0x.*i\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i * x_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "ComplexMult\\(A0x.*i,Real2Complex\\(A0x.*i\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexMult\\(A0x.*i,Real2Complex\\(A0x.*i\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- xc_i * Pm(2i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("ComplexScal\\(A0x.*i,A0x.*NA\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexScal\\(A0x.*i,A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) obj <- Pm(2i) * xc_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("ComplexScal\\(A0x.*NA,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexScal\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- xc_i * Pm(2) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "ComplexRealScal\\(A0x.*i,IntCst\\(2\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexRealScal\\(A0x.*i,IntCst\\(2\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- xc_i * 2 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "ComplexRealScal\\(A0x.*i,IntCst\\(2\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexRealScal\\(A0x.*i,IntCst\\(2\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 2 * xc_i expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "ComplexRealScal\\(IntCst\\(2\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexRealScal\\(IntCst\\(2\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) - obj <- x_i * 3 + obj <- x_i * 3L expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("A0x.*i\\*+IntCst\\(3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Mult\\(A0x.*i,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 3.14 * x_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*NA\\*A0x.*i", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mult\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( x_i * z_j, paste( - "Operation `*` expects inputs of the same dimension or dimension 1.", - " Received 3 and 7.", sep = "" + "Operation `Mult` expects inputs of the same dimension", + "or dimension 1. Received 3 and 7.", sep = " " ), fixed = TRUE ) @@ -360,59 +380,58 @@ test_that("/", { obj <- x_i / y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*i/A0x.*j", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Divide\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- xc_i / y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "ComplexDivide\\(A0x.*i,Real2Complex\\(A0x.*j\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexDivide\\(A0x.*i,Real2Complex\\(A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- y_j / xc_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep( - "ComplexDivide\\(Real2Complex\\(A0x.*j\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexDivide\\(Real2Complex\\(A0x.*j\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- yc_j / 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "ComplexDivide\\(A0x.*j,Real2Complex\\(IntCst\\(3\\)\\)\\)", - obj$formula + bool_grep_formula <- str_detect( + obj$formula, + "ComplexDivide\\(A0x.*j,Real2Complex\\(IntCst\\(3\\)\\)\\)" ) - expect_equal(bool_grep_formula, 1) + expect_equal(bool_grep_formula, TRUE) expect_warning(obj <- 3 / xc_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "ComplexDivide\\(Real2Complex\\(IntCst\\(3\\)\\),A0x.*i\\)", - obj$formula - ) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "ComplexDivide\\(Real2Complex\\(IntCst\\(3\\)\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i / 3 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("A0x.*i/IntCst\\(3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Divide\\(A0x.*i,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 3.14 / x_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("A0x.*NA/A0x.*i", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Divide\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( x_i / z_j, paste( - "Operation `/` expects inputs of the same dimension or dimension 1.", - " Received 3 and 7.", sep = "" + "Operation `Divide` expects inputs of the same dimension", + "or dimension 1. Received 3 and 7.", sep = " " ), fixed = TRUE ) @@ -453,44 +472,44 @@ test_that("^", { obj <- x_i^y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Powf\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Powf\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i^3 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Pow\\(A0x.*i,3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Pow\\(A0x.*i,3\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i^(-0.5) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Rsqrt\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Rsqrt\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i^(0.5) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sqrt\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sqrt\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- y_j^2 expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Square\\(A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Square\\(A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) obj <- x_i^0.314 expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Powf\\(A0x.*i,A0x.*NA\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Powf\\(A0x.*i,A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) obj <- 3.14^x_i expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Powf\\(A0x.*NA,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Powf\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -517,8 +536,8 @@ test_that("square", { obj <- square(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Square\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Square\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -545,8 +564,8 @@ test_that("sqrt", { obj <- sqrt(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sqrt\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sqrt\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -573,8 +592,8 @@ test_that("rsqrt", { obj <- rsqrt(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Rsqrt\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Rsqrt\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -617,8 +636,8 @@ test_that("|", { obj <- x_i | y_j expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("\\(A0x.*i\\|A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "\\(A0x.*i\\|A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( @@ -663,20 +682,21 @@ test_that("exp", { obj <- exp(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Exp\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Exp\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- exp(x_i - y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Exp\\(A0x.*i-A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Exp\\(Subtract\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- exp(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ComplexExp\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexExp\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -709,20 +729,21 @@ test_that("log", { obj <- log(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Log\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Log\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- log(x_i - y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Log\\(A0x.*i-A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Log\\(Subtract\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- log(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Log\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Log\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -755,20 +776,21 @@ test_that("inv", { obj <- inv(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Inv\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Inv\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- inv(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Inv\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Inv\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- inv(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Inv\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Inv\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -801,20 +823,21 @@ test_that("cos", { obj <- cos(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Cos\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Cos\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- cos(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Cos\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Cos\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- cos(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Cos\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Cos\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -847,20 +870,21 @@ test_that("sin", { obj <- sin(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sin\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sin\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- sin(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Sin\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Sin\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- sin(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sin\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sin\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -893,14 +917,15 @@ test_that("acos", { obj <- acos(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Acos\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Acos\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- acos(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Acos\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Acos\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -931,14 +956,15 @@ test_that("asin", { obj <- asin(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Asin\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Asin\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- asin(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Asin\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Asin\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -968,14 +994,15 @@ test_that("atan", { obj <- atan(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Atan\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Atan\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- atan(x_i + y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Atan\\(A0x.*i\\+A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Atan\\(Add\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1010,8 +1037,8 @@ test_that("atan2", { obj <- atan2(x_i, y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Atan2\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Atan2\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(atan2(x_i, z_j), @@ -1103,20 +1130,20 @@ test_that("abs", { obj <- abs(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Abs\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Abs\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- abs(-y_j) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Abs\\(Minus\\(A0x.*j\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Abs\\(Minus\\(A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- abs(-xc_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ComplexAbs\\(Minus\\(A0x.*i\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexAbs\\(Minus\\(A0x.*i\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1146,14 +1173,14 @@ test_that("sign", { obj <- sign(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sign\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sign\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- sign(-y_j) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Sign\\(Minus\\(A0x.*j\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Sign\\(Minus\\(A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1185,20 +1212,20 @@ test_that("round", { obj <- round(x_i, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Round\\(A0x.*i,3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Round\\(A0x.*i,3\\)") + expect_equal(bool_grep_formula, TRUE) obj <- round(y_j, 3.14) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Round\\(A0x.*j,3.14\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Round\\(A0x.*j,3.14\\)") + expect_equal(bool_grep_formula, TRUE) obj <- round(Pm(3), 3) expect_null(obj$args) expect_null(obj$data) - bool_grep_formula <- grep("Round\\(IntCst\\(.*\\),3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Round\\(IntCst\\(.*\\),3\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(round(x_i, x), @@ -1237,14 +1264,14 @@ test_that("xlogx", { obj <- xlogx(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("XLogX\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "XLogX\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- xlogx(Pm(3)) expect_null(obj$args) expect_null(obj$data) - bool_grep_formula <- grep("XLogX\\(IntCst\\(.*\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "XLogX\\(IntCst\\(.*\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1274,14 +1301,14 @@ test_that("sinxdivx", { obj <- sinxdivx(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("SinXDivX\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "SinXDivX\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- sinxdivx(Pm(3)) expect_null(obj$args) expect_null(obj$data) - bool_grep_formula <- grep("SinXDivX\\(IntCst\\(.*\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "SinXDivX\\(IntCst\\(.*\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1310,14 +1337,14 @@ test_that("step", { obj <- step(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Step\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Step\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- step(Pm(2)) expect_null(obj$args) expect_null(obj$data) - bool_grep_formula <- grep("Step\\(IntCst\\(.*\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Step\\(IntCst\\(.*\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1346,14 +1373,14 @@ test_that("relu", { obj <- relu(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ReLU\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ReLU\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- relu(LazyTensor(4)) expect_null(obj$args) expect_null(obj$data) - bool_grep_formula <- grep("ReLU\\(IntCst\\(.*\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ReLU\\(IntCst\\(.*\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1382,29 +1409,29 @@ test_that("clamp", { expect_true(is.LazyTensor(obj)) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("Clamp\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Clamp\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- clamp(x_i, y_j, 3) expect_true(is.LazyTensor(obj)) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Clamp\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Clamp\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- clamp(2, y_j, 3) expect_true(is.LazyTensor(obj)) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Clamp\\(IntCst\\(2\\),A0x.*j,IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Clamp\\(IntCst\\(2\\),A0x.*j,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- clamp(x_i, 2, 3) expect_true(is.LazyTensor(obj)) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ClampInt\\(A0x.*i,2,3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ClampInt\\(A0x.*i,2,3\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( @@ -1461,15 +1488,15 @@ test_that("clampint", { expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_s3_class(obj, "LazyTensor") - bool_grep_formula <- grep("ClampInt\\(A0x.*i,6,8\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ClampInt\\(A0x.*i,6,8\\)") + expect_equal(bool_grep_formula, TRUE) obj <- clampint(1, 6, 8) expect_null(obj$args) expect_null(obj$data) expect_s3_class(obj, "LazyTensor") - bool_grep_formula <- grep("ClampInt\\(IntCst\\(1\\),6,8\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ClampInt\\(IntCst\\(1\\),6,8\\)") + expect_equal(bool_grep_formula, TRUE) # errors @@ -1538,22 +1565,22 @@ test_that("ifelse", { obj <- ifelse(x_i, y_j, z_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("IfElse\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "IfElse\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") obj <- ifelse(x_i, y_j, 3) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("IfElse\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "IfElse\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") obj <- ifelse(x_i, 2, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("IfElse\\(A0x.*i,IntCst\\(2\\),IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "IfElse\\(A0x.*i,IntCst\\(2\\),IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") # errors @@ -1610,51 +1637,50 @@ test_that("mod", { obj <- mod(x_i, y_j, z_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("Mod\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") obj <- mod(xc_i, yc_j, zc_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("Mod\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") obj <- mod(x_i, yc_j, zc_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("Mod\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") obj <- mod(xc_i, y_j, z_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("Mod\\(A0x.*i,A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") obj <- mod(x_i, y_j, 3) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("Mod\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,A0x.*j,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") obj <- mod(x_i, 2, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Mod\\(A0x.*i,IntCst\\(2\\),IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,IntCst\\(2\\),IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") obj <- mod(x_i, 2) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Mod\\(A0x.*i,IntCst\\(2\\),IntCst\\(0\\)\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Mod\\(A0x.*i,IntCst\\(2\\),IntCst\\(0\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") # errors @@ -1691,8 +1717,8 @@ test_that("sqnorm2", { obj <- sqnorm2(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("SqNorm2\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "SqNorm2\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1714,8 +1740,8 @@ test_that("norm2", { obj <- norm2(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Norm2\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Norm2\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1736,8 +1762,8 @@ test_that("normalize", { obj <- normalize(x_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Normalize\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Normalize\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1778,14 +1804,14 @@ test_that("sqdist", { obj <- sqdist(x_i, y_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("SqDist\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "SqDist\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) obj <- sqdist(x_i, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("SqDist\\(A0x.*i,IntCst\\(3\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "SqDist\\(A0x.*i,IntCst\\(3\\)\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error( @@ -1823,14 +1849,14 @@ test_that("weightedsqnorm", { obj <- weightedsqnorm(x_i, s_j) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("WeightedSqNorm\\(A0x.*j,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "WeightedSqNorm\\(A0x.*j,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- weightedsqnorm(x_i, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("WeightedSqNorm\\(IntCst\\(3\\),A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "WeightedSqNorm\\(IntCst\\(3\\),A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1869,32 +1895,33 @@ test_that("weightedsqdist", { obj <- weightedsqdist(x_i, y_j, s_i) expect_equal(length(obj$args), 3) expect_equal(length(obj$data), 3) - bool_grep_formula <- grep("WeightedSqNorm\\(A0x.*i,A0x.*i-A0x.*j\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "WeightedSqNorm\\(A0x.*i,Subtract\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- weightedsqdist(x_i, 2, s_i) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("WeightedSqNorm\\(A0x.*i,A0x.*i-IntCst\\(2\\)\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, + "WeightedSqNorm\\(A0x.*i,Subtract\\(A0x.*i,IntCst\\(2\\)\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- weightedsqdist(x_i, y_j, 3) expect_equal(length(obj$args), 2) expect_equal(length(obj$data), 2) - bool_grep_formula <- grep("WeightedSqNorm\\(IntCst\\(3\\),A0x.*i-A0x.*j\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, + "WeightedSqNorm\\(IntCst\\(3\\),Subtract\\(A0x.*i,A0x.*j\\)\\)") + expect_equal(bool_grep_formula, TRUE) obj <- weightedsqdist(x_i, 2, 3) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep( - "WeightedSqNorm\\(IntCst\\(3\\),A0x.*i-IntCst\\(2\\)\\)", - obj$formula - ) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, + "WeightedSqNorm\\(IntCst\\(3\\),Subtract\\(A0x.*i,IntCst\\(2\\)\\)\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -1933,13 +1960,17 @@ test_that("Re", { obj <- Re(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ComplexReal\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexReal\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") expect_error( Re(x_i), - "`Re` cannot be applied to a LazyTensor. See `?Re` for compatible types.", + str_c( + "`Re` cannot be applied to a LazyTensor.", + "See `?Re` for compatible types.", + sep = " " + ), fixed = TRUE ) @@ -1975,13 +2006,17 @@ test_that("Im", { obj <- Im(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ComplexImag\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexImag\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") expect_error( - Im(x_i), - "`Im` cannot be applied to a LazyTensor. See `?Im` for compatible types.", + Im(x_i), + str_c( + "`Im` cannot be applied to a LazyTensor.", + "See `?Im` for compatible types.", + sep = " " + ), fixed = TRUE ) @@ -2017,14 +2052,18 @@ test_that("Arg", { obj <- Arg(z_i) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("ComplexAngle\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexAngle\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "LazyTensor") # error expect_error( - Arg(x_i), - "`Arg` cannot be applied to a LazyTensor. See `?Arg` for compatible types.", + Arg(x_i), + str_c( + "`Arg` cannot be applied to a LazyTensor.", + "See `?Arg` for compatible types.", + sep = " " + ), fixed = TRUE ) @@ -2046,16 +2085,16 @@ test_that("real2complex", { expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_equal(obj$dimres, x_i$dimres) - bool_grep_formula <- grep("Real2Complex\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Real2Complex\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") expect_warning(obj <- real2complex(Pm(2))) expect_null(obj$args) expect_null(obj$data) expect_equal(obj$dimres, 1) - bool_grep_formula <- grep("Real2Complex\\(IntCst\\(2\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Real2Complex\\(IntCst\\(2\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") # errors @@ -2083,16 +2122,16 @@ test_that("imag2complex", { expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_equal(obj$dimres, x_i$dimres) - bool_grep_formula <- grep("Imag2Complex\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Imag2Complex\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") obj <- imag2complex(Pm(2)) expect_null(obj$args) expect_null(obj$data) expect_equal(obj$dimres, 1) - bool_grep_formula <- grep("Imag2Complex\\(IntCst\\(2\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Imag2Complex\\(IntCst\\(2\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") expect_error(imag2complex(xc_i), @@ -2116,8 +2155,8 @@ test_that("exp1j", { expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_equal(obj$dimres, x_i$dimres) - bool_grep_formula <- grep("ComplexExp1j\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexExp1j\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) expect_s3_class(obj, "ComplexLazyTensor") expect_error(exp1j(xc_i), @@ -2152,8 +2191,8 @@ test_that("Conj", { expect_s3_class(obj, "ComplexLazyTensor") expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) - bool_grep_formula <- grep("Conj\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Conj\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj <- Conj(1 + 2i) expect_equal(obj, 1 - 2i) @@ -2194,8 +2233,8 @@ test_that("Mod", { expect_equal(obj$dimres, 3) expect_true(is.LazyTensor(obj)) expect_false(is.ComplexLazyTensor(obj)) - bool_grep_formula <- grep("ComplexAbs\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ComplexAbs\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -2216,13 +2255,13 @@ test_that("elem", { # check formulas, args & classes obj <- elem(x_i, m) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Elem\\(A0x.*i,2\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Elem\\(A0x.*i,2\\)") + expect_equal(bool_grep_formula, TRUE) obj <- elem(Pm_int, 0) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Elem\\(IntCst\\(5\\),0\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Elem\\(IntCst\\(5\\),0\\)") + expect_equal(bool_grep_formula, TRUE) expect_null <- obj$args expect_null <- obj$data expect_equal(obj$dimres, 1) @@ -2264,19 +2303,19 @@ test_that("elemT", { # check formulas, args & classes obj <- elemT(Pm_x, m, n) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ElemT\\(A0x.*NA,3,2\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ElemT\\(A0x.*NA,3,2\\)") + expect_equal(bool_grep_formula, TRUE) obj <- elemT(Pm_z, m, n) expect_true(is.LazyTensor(obj)) expect_true(is.ComplexLazyTensor(obj)) - bool_grep_formula <- grep("ElemT\\(A0x.*NA,3,2\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ElemT\\(A0x.*NA,3,2\\)") + expect_equal(bool_grep_formula, TRUE) obj <- elemT(Pm_int, 5, 7) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ElemT\\(IntCst\\(4\\),7,5\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ElemT\\(IntCst\\(4\\),7,5\\)") + expect_equal(bool_grep_formula, TRUE) expect_null <- obj$args expect_null <- obj$data expect_equal(obj$dimres, 1) @@ -2319,18 +2358,18 @@ test_that("extract", { # check formulas, args & classes obj <- extract(x_i, m, d) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Extract\\(A0x.*i,1,3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Extract\\(A0x.*i,1,3\\)") + expect_equal(bool_grep_formula, TRUE) obj <- extract(Pm_v, 0, d) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Extract\\(A0x.*NA,0,3\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Extract\\(A0x.*NA,0,3\\)") + expect_equal(bool_grep_formula, TRUE) obj <- extract(Pm_int, 0, 1) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Extract\\(IntCst\\(2\\),0,1\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Extract\\(IntCst\\(2\\),0,1\\)") + expect_equal(bool_grep_formula, TRUE) expect_null <- obj$args expect_null <- obj$data expect_equal(obj$dimres, 1) @@ -2376,18 +2415,18 @@ test_that("extractT", { # check formulas, args & classes obj <- extractT(x_i, m, d) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ExtractT\\(A0x.*i,1,8\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ExtractT\\(A0x.*i,1,8\\)") + expect_equal(bool_grep_formula, TRUE) obj <- extractT(Pm_v, 0, d) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ExtractT\\(A0x.*NA,0,8\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ExtractT\\(A0x.*NA,0,8\\)") + expect_equal(bool_grep_formula, TRUE) obj <- extractT(Pm_int, 0, d) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ExtractT\\(IntCst\\(2\\),0,8\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ExtractT\\(IntCst\\(2\\),0,8\\)") + expect_equal(bool_grep_formula, TRUE) expect_null <- obj$args expect_null <- obj$data expect_equal(obj$dimres, 1) @@ -2428,8 +2467,8 @@ test_that("concat", { obj <- concat(x_i, y_j) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Concat\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Concat\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) res <- sum(concat(x_i,y_j), "i") expected_res <- rep(1:2, each = 3) @@ -2447,13 +2486,14 @@ test_that("concat", { # check formulas, args & classes obj <- concat(x_i, y_j) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Concat\\(A0x.*i,A0x.*j\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Concat\\(A0x.*i,A0x.*j\\)") + expect_equal(bool_grep_formula, TRUE) obj <- concat(x_i, Pm_int) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Concat\\(A0x.*i,IntCst\\(5\\)\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect( + obj$formula, "Concat\\(A0x.*i,IntCst\\(5\\)\\)") + expect_equal(bool_grep_formula, TRUE) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_equal(obj$dimres, 4) @@ -2478,16 +2518,16 @@ test_that("one_hot", { # check formulas, args & classes obj <- one_hot(LT_s, D) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("OneHot\\(IntCst\\(13\\),7\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "OneHot\\(IntCst\\(13\\),7\\)") + expect_equal(bool_grep_formula, TRUE) expect_null <- obj$args expect_null <- obj$data expect_equal(obj$dimres, 7) obj <- one_hot(LT_dec, D) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("OneHot\\(A0x.*NA,7\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "OneHot\\(A0x.*NA,7\\)") + expect_equal(bool_grep_formula, TRUE) expect_equal(length(obj$args), 1) expect_equal(length(obj$data), 1) expect_equal(obj$dimres, 7) @@ -2528,15 +2568,13 @@ test_that("matvecmult", { # check formulas, args & classes obj <- matvecmult(m_i, Pm_v) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("MatVecMult\\(A0x.*i,A0x.*NA\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "MatVecMult\\(A0x.*i,A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) obj_Pm_one <- matvecmult(m_i, Pm_one) expect_true(is.LazyTensor(obj_Pm_one)) - bool_grep_formula <- grep("MatVecMult\\(A0x.*i,A0x.*NA\\)", - obj_Pm_one$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj_Pm_one$formula, "MatVecMult\\(A0x.*i,A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) # check dimres expect_equal(obj$dimres, 1) @@ -2578,15 +2616,13 @@ test_that("vecmatmult", { # check formulas, args & classes obj <- vecmatmult(Pm_v, m_i) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("VecMatMult\\(A0x.*NA,A0x.*i\\)", - obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "VecMatMult\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) obj_Pm_one <- vecmatmult(Pm_one, m_i) expect_true(is.LazyTensor(obj_Pm_one)) - bool_grep_formula <- grep("VecMatMult\\(A0x.*NA,A0x.*i\\)", - obj_Pm_one$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj_Pm_one$formula, "VecMatMult\\(A0x.*NA,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # check dimres expect_equal(obj$dimres, 1) @@ -2630,8 +2666,8 @@ test_that("tensorprod", { expect_true(is.LazyTensor(obj)) expect_false(is.ComplexLazyTensor(obj)) expect_equal(obj$dimres, 9) - bool_grep_formula <- grep("TensorProd\\(A0x.*i,A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "TensorProd\\(A0x.*i,A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) }) @@ -2763,11 +2799,11 @@ test_that("sum", { expect_equal(as.vector(res), expected_res, tolerance = 1E-5) # check formulae - bool_grep_formula <- grep("Sum\\(A0x.*NA\\)", sum(Pm_v)$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(sum(Pm_v)$formula, "Sum\\(A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) - bool_grep_formula <- grep("ComplexSum\\(A0x.*NA\\)", sum(Pm_complex)$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(sum(Pm_complex)$formula, "ComplexSum\\(A0x.*NA\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(sum(x_i, "b"), @@ -2871,8 +2907,8 @@ test_that("min", { # checks when there is no reduction obj <- min(x_i) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Min\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Min\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(min(x_i, "b"), @@ -2940,8 +2976,8 @@ test_that("argmin", { obj <- argmin(x_i) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ArgMin\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ArgMin\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(argmin(3, "i"), @@ -3106,8 +3142,8 @@ test_that("max", { # when there is no reduction obj <- max(x_i) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("Max\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "Max\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(max(x_i, "b"), @@ -3163,8 +3199,8 @@ test_that("argmax", { obj <- argmax(x_i) expect_true(is.LazyTensor(obj)) - bool_grep_formula <- grep("ArgMax\\(A0x.*i\\)", obj$formula) - expect_equal(bool_grep_formula, 1) + bool_grep_formula <- str_detect(obj$formula, "ArgMax\\(A0x.*i\\)") + expect_equal(bool_grep_formula, TRUE) # errors expect_error(argmax(3, "i"), @@ -3690,7 +3726,7 @@ test_that("logsumexp", { V_ij <- x_i - y_j S_ij <- sum(V_ij^2) - expect_error(logsumexp(sum(V_ij), 'i', w_j)) + expect_error(logsumexp(S_ij, 'i', w_j)) res <- logsumexp(S_ij, 'i') expect_false(is.LazyTensor(res)) @@ -3827,10 +3863,10 @@ test_that("sumsoftmaxweight", { x_i <- LazyTensor(x, index = 'i') y <- matrix(runif(100 * 3), 100, 3) y_j <- LazyTensor(y, index = 'j') - + V_ij <- x_i - y_j # weight matrix S_ij = sum(V_ij^2) - + res <- sumsoftmaxweight(S_ij, 'i', V_ij) expect_false(is.LazyTensor(res)) expect_true(is.matrix(res)) @@ -3946,7 +3982,7 @@ test_that("grad", { expect_error( grad(sqnorm2(x_i - y_j), eta_i, "Sum", var = 0, 1), - paste0("`index` input argument should be a character, either 'i' or 'j'."), + "`index` input argument should be a character, either 'i' or 'j'.", fixed = TRUE ) @@ -3957,3 +3993,5 @@ test_that("grad", { ) }) + +}) # withr::with_options diff --git a/rkeops/vignettes/Kernel_Interpolation_rkeops.Rmd b/rkeops/vignettes/Kernel_Interpolation_rkeops.Rmd index 47c53fe23..219d0be71 100644 --- a/rkeops/vignettes/Kernel_Interpolation_rkeops.Rmd +++ b/rkeops/vignettes/Kernel_Interpolation_rkeops.Rmd @@ -27,7 +27,7 @@ knitr::opts_chunk$set( ``` ```{r requirement, include=FALSE} -required <- c("ggplot2", "dplyr", "pracma", "plotly", "reshape") +required <- c("ggplot2", "dplyr", "pracma", "plotly", "reshape", "withr") sapply( required, function(pkg) { @@ -49,14 +49,6 @@ library(reshape) # matrix to data.frame reformatting ```{r init, message=FALSE, warning=FALSE, results='hide', eval=FALSE} # load rkeops library(rkeops) -# create a dedicated Python environment with reticulate (!!to be done only once) -reticulate::virtualenv_create("rkeops") -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -# install rkeops requirements (!!to be done only once) -install_rkeops() -# use 64bit floating operation precision -rkeops_use_float64() ``` ```{r safe_init, message=FALSE, warning=FALSE, results='hide', include=FALSE} @@ -64,24 +56,15 @@ rkeops_use_float64() library(rkeops) tryCatch({ - # create a dedicated Python environment with reticulate (to be done only once) - reticulate::virtualenv_create("rkeops") - # activate the dedicated Python environment - reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) - # check Python availability - if(reticulate::py_available(initialize = TRUE)) { - # install rkeops requirements (to be done only once) - install_rkeops() - } else { + if(!reticulate::py_available(initialize = TRUE)) { knitr::opts_chunk$set(eval = FALSE) } }, error = function(e) {knitr::opts_chunk$set(eval = FALSE)}) - ``` ```{r} -# check rkeops install +# check rkeops setup check_rkeops() # use 64bit floating operation precision @@ -94,13 +77,13 @@ if(!check_rkeops(verbose = FALSE)) { } ``` -For build on CRAN, use CPU computing with 2 cores: -```{r limit_cpu_usage} +```{r limit_cpu_usage, include=FALSE} +# For build on CRAN, use CPU computing with 2 cores max rkeops_use_cpu(ncore = 2) ``` ```{r cleanup, include=FALSE} -# cleanup afterward +# cleanup afterward (especially for CRAN build) withr::defer(clean_rkeops(verbose = FALSE, remove_cache_dir = TRUE)) ``` @@ -306,7 +289,7 @@ mean_t <- mean_t[nrow(mean_t):1, ] data2plot_sample <- data.frame( X = x[,1], Y = x[,2], - value = b + value = b[,1] ) ggplot(data2plot_sample, aes(x = X, y = Y, col = value)) + diff --git a/rkeops/vignettes/LazyTensor_rkeops.Rmd b/rkeops/vignettes/LazyTensor_rkeops.Rmd index 42429249d..f5d3e065b 100644 --- a/rkeops/vignettes/LazyTensor_rkeops.Rmd +++ b/rkeops/vignettes/LazyTensor_rkeops.Rmd @@ -31,12 +31,8 @@ knitr::opts_chunk$set( ```{r} # load rkeops library(rkeops) -# create a dedicated Python environment with reticulate (!!to be done only once) -reticulate::virtualenv_create("rkeops") -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -# install rkeops requirements (!!to be done only once) -install_rkeops() +# check rkeops setup +check_rkeops() ``` @@ -142,7 +138,7 @@ Pm_v_z <- LazyTensor(v_z, is_complex = TRUE) Pm_v_z$data ## [[1]] ## [,1] [,2] [,3] [,4] [,5] [,6] -## [1,] 4 5 2 3 7 1 +## [1,] 4 5 2 3 7 1 ``` Of course if you create a vector or a matrix of real values, and @@ -350,9 +346,9 @@ The operations `sum()`, `min()`, `argmin()`, `max()` and `argmax()` can be calle Here, `x` is a `LazyTensor` of inner dimension $D$ and outer dimension $M$, indexed by $i \in \{1, \ldots ,M\}$, and `y` is a `LazyTensor` of inner dimension $D$ and outer dimension $N$, indexed by $j \in \{1, \ldots ,N\}$. -| operation | meaning | mathematical expression | -|:----------|:----------------------------------------------------------------------------------------------------|:------------------------------------------------| -|`x %*% y` | sum reduction of the product `x` * `y` indexed by `j`.
Same as `sum_reduction(x * y, "j")` | $\sum_j x_{ik} y_{jk}, ~ k \in \{1, \ldots, N\}$ | +| operation | meaning | mathematical expression | +|:----------|:----------------------------------------------------------------------------------------------------|:-------------------------------------------------| +|`x %*% y` | sum reduction of the product `x` * `y` indexed by `j`.
Same as `sum_reduction(x * y, "j")` | $\sum_j x_{ik} y_{jk}, ~ k \in \{1, \ldots, N\}$ | ## Advices and random notes diff --git a/rkeops/vignettes/introduction_to_rkeops.Rmd b/rkeops/vignettes/introduction_to_rkeops.Rmd index 97f6ed33e..6afc99cd1 100644 --- a/rkeops/vignettes/introduction_to_rkeops.Rmd +++ b/rkeops/vignettes/introduction_to_rkeops.Rmd @@ -35,9 +35,9 @@ a report on our [GitHub issue tracker](https://github.com/getkeops/keops/issues) **Core library - KeOps, PyKeOps, KeOpsLab:** -- [Benjamin Charlier](https://imag.umontpellier.fr/~charlier/), from the University of Montpellier. +- [Benjamin Charlier](https://miat.inrae.fr/bcharlier/), from the University of Montpellier. - [Jean Feydy](https://www.jeanfeydy.com), from Inria. -- [Joan Alexis Glaunès](http://helios.mi.parisdescartes.fr/~glaunes/), from the University of Paris. +- [Joan Alexis Glaunès](https://helios2.mi.parisdescartes.fr/~glaunes/), from the University of Paris. **R bindings - RKeOps:** @@ -47,11 +47,11 @@ a report on our [GitHub issue tracker](https://github.com/getkeops/keops/issues) **Contributors:** -- [François-David Collin](https://github.com/fradav), from the University of Montpellier: Tensordot operation, CI setup. +- [François-David Collin](https://fradav.perso.math.cnrs.fr/), from the University of Montpellier: Tensordot operation, CI setup. - [Tanguy Lefort](https://github.com/tanglef), from the University of Montpellier: conjugate gradient solver. - [Mauricio Diaz](https://github.com/mdiazmel), from Inria of Paris: CI setup. - [Benoît Martin](https://github.com/benoitmartin88), from the Aramis Inria team: multi-GPU support. -- [Francis Williams](https://www.fwilliams.info), from New York University: maths operations. +- [Francis Williams](https://fwilliams.info/), from New York University: maths operations. - [Kshiteej Kalambarkar](https://github.com/kshitij12345), from Quansight: maths operations. - [D. J. Sutherland](https://djsutherland.ml), from the TTI-Chicago: bug fix in the Python package. - [David Völgyes](https://scholar.google.no/citations?user=ngT2GvMAAAAJ&hl=en), from the Norwegian Institute of Science and Technology: bug fix in the formula parser. @@ -154,15 +154,11 @@ remotes::install_github("getkeops/keops", subdir = "rkeops") ```{r} # load rkeops library(rkeops) -# create a dedicated Python environment with reticulate (!!to be done only once) -reticulate::virtualenv_create("rkeops") -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -# install rkeops requirements (!!to be done only once) -install_rkeops() +# check rkeops setup +check_rkeops() ``` -For more details, see the specific **"Using RKeOps" [article](https://www.kernel-operations.io/rkeops/articles/using_rkeops.html)** or the corresponding vignette: +**Important:** for more details (especially in case of problems), see the specific **"Using RKeOps" [article](https://www.kernel-operations.io/rkeops/articles/using_rkeops.html)** or the corresponding vignette: ```{r} vignette("using_rkeops", package = "rkeops") ``` diff --git a/rkeops/vignettes/using_rkeops.Rmd b/rkeops/vignettes/using_rkeops.Rmd index c5470a7c6..a2e6b72c9 100644 --- a/rkeops/vignettes/using_rkeops.Rmd +++ b/rkeops/vignettes/using_rkeops.Rmd @@ -33,11 +33,35 @@ Thanks to RKeOps, you can use **GPU computing directly inside R** without the co * R (tested with R >= 4.2) * C++ compiler (g++ >=7 or clang) for CPU computing or CUDA compiler (nvcc >=10) and CUDA libs for GPU computing -* Python (>= 3.10) +* Python (>= 3.10), c.f. [next section](#note-on-python-requirement) + +**Disclaimer:** KeOps (including RKeOps) is not functional on Windows, it was only tested on Linux and MacOS. **Important:** Python is a requirement as an intern machinery for the package to work but you will not need to create nor manipulate Python codes to use the RKeOps package. -**Disclaimer:** KeOps (including RKeOps) is not functional on Windows, it was only tested on Linux and MacOS. +### Note on Python requirement + +RKeOps now uses PyKeOps Python package under the hood thanks to the [`reticulate`](https://rstudio.github.io/reticulate/) R package that provides an “R Interface to Python”. + +Everything related to Python, including the installation of the required Python version and required Python packages, should be automatically managed with `reticulate`. It should be transparent for the user. + +#### Troubleshooting + +In case of trouble with `reticulate` not being able to setup the Python configuration, you can try the following workaround: + +- install the development version of `reticulate`: +```{r} +remotes::install_github("rstudio/reticulate") +``` + +- check if `reticulate` is able to setup a Python environment: +```{r, eval=FALSE} +unlink(tools::R_user_dir("reticulate", "cache"), recursive = TRUE) +Sys.setenv("_RETICULATE_DEBUG_UV_" = "1") +library(reticulate) +py_require(python_version="3.12") +py_config() +``` ## Install from CRAN @@ -58,49 +82,23 @@ install.packages("remotes") remotes::install_github("getkeops/keops", subdir = "rkeops") ``` -## Setup and requirement install - -**To be done once after installation:** - -```{r install_requirements} -# load rkeops -library(rkeops) -# create a dedicated Python environment with reticulate (!!to be done only once) -reticulate::virtualenv_create("rkeops") -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -# install rkeops requirements (!!to be done only once) -install_rkeops() -``` - -### Note on Python requirement - -RKeOps now uses PyKeOps Python package under the hood thanks to the [`reticulate`](https://rstudio.github.io/reticulate/) R package that provides an “R Interface to Python”. - -We recommend to use a dedicated Python environment (through `reticulate`) to install and use RKeOps Python dependencies (c.f. [previously](#setup-and-requirement-install)). - -> **Note:** To get more information about **managing** which **version of Python** you are using, you can refer to `reticulate` [documentation](https://rstudio.github.io/reticulate/articles/versions.html) about “Python Version Configuration”. In particular, if you are a Miniconda/Anaconda Python distribution user, you can either user a Python virtual environment (c.f. above) or a **Conda environment** with the same results. Please refer to the `reticulate` [documentation](https://rstudio.github.io/reticulate/articles/versions.html#providing-hints) in this case. - --- # How to use RKeOps -Load RKeOps in R: +RKeOps allows to define and compile new operators that run computations on GPU or on CPU with the exact same code. + +## Loading + +Load RKeOps in R and verify that it is working: ```{r setup} # load rkeops library(rkeops) -# activate the dedicated Python environment -reticulate::use_virtualenv(virtualenv = "rkeops", required = TRUE) -``` - -**Note**: If you are using a Python environment (c.f. [previously](#note-on-python-requirement)), you should always activate it after loading RKeOps. - -You can verify that every thing is ok: -```{r check} +# check rkeops setup check_rkeops() ``` -RKeOps allows to define and compile new operators that run computations on GPU. +**Note:** in case, the previous call does not return `TRUE`, you may need to force `reticulate` initialization by calling `reticulate::py_config()`. ## LazyTensors