Last updated on 2024-11-13 01:49:17 CET.
Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
---|---|---|---|---|---|---|
r-devel-linux-x86_64-debian-clang | 0.5.7 | 15.86 | 93.49 | 109.35 | NOTE | |
r-devel-linux-x86_64-debian-gcc | 0.5.7 | 13.03 | 61.39 | 74.42 | NOTE | |
r-devel-linux-x86_64-fedora-clang | 0.5.7 | 160.65 | ERROR | |||
r-devel-linux-x86_64-fedora-gcc | 0.5.7 | 155.66 | ERROR | |||
r-devel-windows-x86_64 | 0.5.7 | 23.00 | 125.00 | 148.00 | NOTE | |
r-patched-linux-x86_64 | 0.5.7 | 18.97 | 85.66 | 104.63 | OK | |
r-release-linux-x86_64 | 0.5.7 | 15.96 | 86.81 | 102.77 | OK | |
r-release-macos-arm64 | 0.5.7 | 44.00 | OK | |||
r-release-macos-x86_64 | 0.5.7 | 67.00 | OK | |||
r-release-windows-x86_64 | 0.5.7 | 23.00 | 123.00 | 146.00 | OK | |
r-oldrel-macos-arm64 | 0.5.7 | 53.00 | OK | |||
r-oldrel-macos-x86_64 | 0.5.7 | 133.00 | OK | |||
r-oldrel-windows-x86_64 | 0.5.7 | 31.00 | 149.00 | 180.00 | OK |
Version: 0.5.7
Check: Rd cross-references
Result: NOTE
Found the following Rd file(s) with Rd \link{} targets missing package
anchors:
simulate.covAll.Rd: mvrnorm
Please provide package anchors for all Rd \link{} targets not in the
package itself and the base packages.
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-windows-x86_64
Version: 0.5.7
Check: examples
Result: ERROR
Running examples in ‘kergp-Ex.R’ failed
The error most likely occurred in:
> ### Name: gp
> ### Title: Gaussian Process Model
> ### Aliases: gp
>
> ### ** Examples
>
> ## ==================================================================
> ## Example 1. Data sampled from a GP model with a known covTS object
> ## ==================================================================
> set.seed(1234)
> myCov <- covTS(inputs = c("Temp", "Humid"),
+ kernel = "k1Matern5_2",
+ dep = c(range = "input"),
+ value = c(range = 0.4))
> ## change coefficients (variances)
> coef(myCov) <- c(0.5, 0.8, 2, 16)
> d <- myCov@d; n <- 20
> ## design matrix
> X <- matrix(runif(n*d), nrow = n, ncol = d)
> colnames(X) <- inputNames(myCov)
> ## generate the GP realization
> myGp <- gp(formula = y ~ 1, data = data.frame(y = rep(0, n), X),
+ cov = myCov, estim = FALSE,
+ beta = 10, varNoise = 0.05)
> y <- simulate(myGp, cond = FALSE)$sim
Loading required package: MASS
>
> ## parIni: add noise to true parameters
> parCovIni <- coef(myCov)
> parCovIni[] <- 0.9 * parCovIni[] + 0.1 * runif(length(parCovIni))
> coefLower(myCov) <- rep(1e-2, 4)
> coefUpper(myCov) <- c(5, 5, 20, 20)
> est <- gp(y ~ 1, data = data.frame(y = y, X),
+ cov = myCov,
+ noise = TRUE,
+ varNoiseLower = 1e-2,
+ varNoiseIni = 1.0,
+ parCovIni = parCovIni)
Warning in nloptr.add.default.options(opts.user = opts, x0 = x0, num_constraints_ineq = num_constraints_ineq, :
No termination criterion specified, using default(relative x-tolerance = 1e-04)
> summary(est)
Call:
gp(formula = y ~ 1, data = data.frame(y = y, X), cov = myCov,
noise = TRUE, varNoiseLower = 0.01, varNoiseIni = 1, parCovIni = parCovIni)
Number of observations: 20
Trend coef.:
Value
(Intercept) 6.616421
Covariance whith class "covTS"
Tensor sum covariance kernel
o Dimension 'd' (nb of inputs): 2
o Kernel (1D): "Matern nu = 5/2" with parameters: "range"
o One parameter by input:
range: YES
o Number of parameters: 4
o Param. values:
Temp Humid
range 0.8206737 1.320164
var 2.2419969 15.197190
Noise variance: 0.039
> coef(est)
(Intercept) range.Temp range.Humid var.Temp var.Humid varNoise
6.6164214 0.8206737 1.3201637 2.2419969 15.1971902 0.0388751
>
> ## =======================================================================
> ## Example 2. Predicting an additive function with an additive GP model
> ## =======================================================================
>
> ## Not run:
> ##D
> ##D addfun6d <- function(x){
> ##D res <- x[1]^3 + cos(pi * x[2]) + abs(x[3]) * sin(x[3]^2) +
> ##D 3 * x[4]^3 + 3 * cos(pi * x[5]) + 3 * abs(x[6]) * sin(x[6]^2)
> ##D }
> ##D
> ##D ## 'Fit' is for the learning set, 'Val' for the validation set
> ##D set.seed(123)
> ##D nFit <- 50
> ##D nVal <- 200
> ##D d <- 6
> ##D inputs <- paste("x", 1L:d, sep = "")
> ##D
> ##D ## create design matrices with DiceDesign package
> ##D require(DiceDesign)
> ##D require(DiceKriging)
> ##D set.seed(0)
> ##D dataFitIni <- DiceDesign::lhsDesign(nFit, d)$design
> ##D dataValIni <- DiceDesign::lhsDesign(nVal, d)$design
> ##D dataFit <- DiceDesign::maximinSA_LHS(dataFitIni)$design
> ##D dataVal <- DiceDesign::maximinSA_LHS(dataValIni)$design
> ##D
> ##D colnames(dataFit) <- colnames(dataVal) <- inputs
> ##D testfun <- addfun6d
> ##D dataFit <- data.frame(dataFit, y = apply(dataFit, 1, testfun))
> ##D dataVal <- data.frame(dataVal, y = apply(dataVal, 1, testfun))
> ##D
> ##D ## Creation of "CovTS" object with one range by input
> ##D myCov <- covTS(inputs = inputs, d = d, kernel = "k1Matern3_2",
> ##D dep = c(range = "input"))
> ##D
> ##D ## Creation of a gp object
> ##D fitgp <- gp(formula = y ~ 1, data = dataFit,
> ##D cov = myCov, noise = TRUE,
> ##D parCovIni = rep(1, 2*d),
> ##D parCovLower = c(rep(1e-4, 2*d)),
> ##D parCovUpper = c(rep(5, d), rep(10,d)))
> ##D
> ##D predTS <- predict(fitgp, newdata = as.matrix(dataVal[ , inputs]), type = "UK")$mean
> ##D
> ##D ## Classical tensor product kernel as a reference for comparison
> ##D fitRef <- DiceKriging::km(formula = ~1,
> ##D design = dataFit[ , inputs],
> ##D response = dataFit$y, covtype="matern3_2")
> ##D predRef <- predict(fitRef,
> ##D newdata = as.matrix(dataVal[ , inputs]),
> ##D type = "UK")$mean
> ##D ## Compare TS and Ref
> ##D RMSE <- data.frame(TS = sqrt(mean((dataVal$y - predTS)^2)),
> ##D Ref = sqrt(mean((dataVal$y - predRef)^2)),
> ##D row.names = "RMSE")
> ##D print(RMSE)
> ##D
> ##D Comp <- data.frame(y = dataVal$y, predTS, predRef)
> ##D plot(predRef ~ y, data = Comp, col = "black", pch = 4,
> ##D xlab = "True", ylab = "Predicted",
> ##D main = paste("Prediction on a validation set (nFit = ",
> ##D nFit, ", nVal = ", nVal, ").", sep = ""))
> ##D points(predTS ~ y, data = Comp, col = "red", pch = 20)
> ##D abline(a = 0, b = 1, col = "blue", lty = "dotted")
> ##D legend("bottomright", pch = c(4, 20), col = c("black", "red"),
> ##D legend = c("Ref", "Tensor Sum"))
> ## End(Not run)
>
> ##=======================================================================
> ## Example 3: a 'covMan' kernel with 3 implementations
> ##=======================================================================
>
> d <- 4
>
> ## -- Define a 4-dimensional covariance structure with a kernel in R
>
> myGaussFunR <- function(x1, x2, par) {
+ h <- (x1 - x2) / par[1]
+ SS2 <- sum(h^2)
+ d2 <- exp(-SS2)
+ kern <- par[2] * d2
+ d1 <- 2 * kern * SS2 / par[1]
+ attr(kern, "gradient") <- c(theta = d1, sigma2 = d2)
+ return(kern)
+ }
>
> myGaussR <- covMan(kernel = myGaussFunR,
+ hasGrad = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: R implementation")
>
> ## -- The same, still in R, but with a kernel admitting matrices as arguments
>
> myGaussFunRVec <- function(x1, x2, par) {
+ # x1, x2 : matrices with same number of columns 'd' (dimension)
+ n <- nrow(x1)
+ d <- ncol(x1)
+ SS2 <- 0
+ for (j in 1:d){
+ Aj <- outer(x1[ , j], x2[ , j], "-")
+ Hj2 <- (Aj / par[1])^2
+ SS2 <- SS2 + Hj2
+ }
+ D2 <- exp(-SS2)
+ kern <- par[2] * D2
+ D1 <- 2 * kern * SS2 / par[1]
+ attr(kern, "gradient") <- list(theta = D1, sigma2 = D2)
+
+ return(kern)
+ }
>
> myGaussRVec <- covMan(
+ kernel = myGaussFunRVec,
+ hasGrad = TRUE,
+ acceptMatrix = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: vectorised R implementation"
+ )
>
> ## -- The same, with inlined C code
> ## (see also another example with Rcpp by typing: ?kergp).
>
> if (require(inline)) {
+
+ kernCode <- "
+ SEXP kern, dkern;
+ int nprotect = 0, d;
+ double SS2 = 0.0, d2, z, *rkern, *rdkern;
+
+ d = LENGTH(x1);
+ PROTECT(kern = allocVector(REALSXP, 1)); nprotect++;
+ PROTECT(dkern = allocVector(REALSXP, 2)); nprotect++;
+ rkern = REAL(kern);
+ rdkern = REAL(dkern);
+
+ for (int i = 0; i < d; i++) {
+ z = ( REAL(x1)[i] - REAL(x2)[i] ) / REAL(par)[0];
+ SS2 += z * z;
+ }
+
+ d2 = exp(-SS2);
+ rkern[0] = REAL(par)[1] * d2;
+ rdkern[1] = d2;
+ rdkern[0] = 2 * rkern[0] * SS2 / REAL(par)[0];
+
+ SET_ATTR(kern, install(\"gradient\"), dkern);
+ UNPROTECT(nprotect);
+ return kern;
+ "
+ myGaussFunC <- cfunction(sig = signature(x1 = "numeric", x2 = "numeric",
+ par = "numeric"),
+ body = kernCode)
+
+ myGaussC <- covMan(kernel = myGaussFunC,
+ hasGrad = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: C/inline implementation")
+
+ }
Loading required package: inline
Attaching package: ‘inline’
The following object is masked from ‘package:Rcpp’:
registerPlugin
ERROR(s) during compilation: source code errors or compiler configuration errors!
make cmd is
make -f '/data/gannet/ripley/R/R-clang/etc/Makeconf' -f '/data/gannet/ripley/R/R-clang/share/make/shlib.mk' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='file3e0c8055a21d92.so' CXX_DEFS=-DR_NO_REMAP OBJECTS='file3e0c8055a21d92.o'
make would use
make[1]: Entering directory '/tmp/Rtmp6QgD7C/working_dir/Rtmpy9Lauj'
/usr/local/clang19/bin/clang++ -stdlib=libc++ -std=gnu++17 -I"/data/gannet/ripley/R/R-clang/include" -DNDEBUG -isystem /usr/local/clang19/include -I/usr/local/clang/include -fpic -O3 -Wall -pedantic -frtti -Wp,-D_FORTIFY_SOURCE=3 -DR_NO_REMAP -c file3e0c8055a21d92.cpp -o file3e0c8055a21d92.o
if test "zfile3e0c8055a21d92.o" != "z"; then \
echo /usr/local/clang19/bin/clang++ -stdlib=libc++ -std=gnu++17 -shared -L/usr/local/clang/lib64 -L/usr/local/clang19/lib -L/usr/local/clang19/lib/x86_64-unknown-linux-gnu -L/usr/local/gcc14/lib64 -L/usr/local/lib64 -o file3e0c8055a21d92.so file3e0c8055a21d92.o ; \
/usr/local/clang19/bin/clang++ -stdlib=libc++ -std=gnu++17 -shared -L/usr/local/clang/lib64 -L/usr/local/clang19/lib -L/usr/local/clang19/lib/x86_64-unknown-linux-gnu -L/usr/local/gcc14/lib64 -L/usr/local/lib64 -o file3e0c8055a21d92.so file3e0c8055a21d92.o ; \
fi
make[1]: Leaving directory '/tmp/Rtmp6QgD7C/working_dir/Rtmpy9Lauj'
Program source:
1: #include <R.h>
2: #include <Rdefines.h>
3: #include <R_ext/Error.h>
4:
5:
6: extern "C" {
7: SEXP file3e0c8055a21d92 ( SEXP x1, SEXP x2, SEXP par );
8: }
9:
10: SEXP file3e0c8055a21d92 ( SEXP x1, SEXP x2, SEXP par ) {
11:
12: SEXP kern, dkern;
13: int nprotect = 0, d;
14: double SS2 = 0.0, d2, z, *rkern, *rdkern;
15:
16: d = LENGTH(x1);
17: PROTECT(kern = allocVector(REALSXP, 1)); nprotect++;
18: PROTECT(dkern = allocVector(REALSXP, 2)); nprotect++;
19: rkern = REAL(kern);
20: rdkern = REAL(dkern);
21:
22: for (int i = 0; i < d; i++) {
23: z = ( REAL(x1)[i] - REAL(x2)[i] ) / REAL(par)[0];
24: SS2 += z * z;
25: }
26:
27: d2 = exp(-SS2);
28: rkern[0] = REAL(par)[1] * d2;
29: rdkern[1] = d2;
30: rdkern[0] = 2 * rkern[0] * SS2 / REAL(par)[0];
31:
32: SET_ATTR(kern, install("gradient"), dkern);
33: UNPROTECT(nprotect);
34: return kern;
35:
36: Rf_warning("your C program does not return anything!");
37: return R_NilValue;
38: }
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language, verbose) :
ctor(SEXPTYPE, R_xlen_t);
| ^
file3e0c8055a21d92.cpp:18:24: error: use of undeclared identifier 'allocVector'; did you mean 'Rf_allocVector'?
18 | PROTECT(dkern = allocVector(REALSXP, 2)); nprotect++;
| ^~~~~~~~~~~
| Rf_allocVector
/data/gannet/ripley/R/R-clang/include/Rinternals.h:388:31: note: expanded from macro 'PROTECT'
388 | #define PROTECT(s) Rf_protect(s)
| ^
/data/gannet/ripley/R/R-clang/include/Rinternals.h:1078:10: note: 'Rf_allocVector' declared here
1078 | SEXP Rf_allocVector(SEXPTYPE, R_xlen_t);
| ^
file3e0c8055a21d92.cpp:32:23: error: use of undeclared identifier 'install'
32 | SET_ATTR(kern, install("gradient"), dkern);
| ^
3 errors generated.
make[1]: *** [/data/gannet/ripley/R/R-clang/etc/Makeconf:202: file3e0c8055a21d92.o] Error 1
make[1]: Target 'all' not remade because o
Calls: cfunction -> compileCode
Execution halted
Flavor: r-devel-linux-x86_64-fedora-clang
Version: 0.5.7
Check: examples
Result: ERROR
Running examples in ‘kergp-Ex.R’ failed
The error most likely occurred in:
> ### Name: gp
> ### Title: Gaussian Process Model
> ### Aliases: gp
>
> ### ** Examples
>
> ## ==================================================================
> ## Example 1. Data sampled from a GP model with a known covTS object
> ## ==================================================================
> set.seed(1234)
> myCov <- covTS(inputs = c("Temp", "Humid"),
+ kernel = "k1Matern5_2",
+ dep = c(range = "input"),
+ value = c(range = 0.4))
> ## change coefficients (variances)
> coef(myCov) <- c(0.5, 0.8, 2, 16)
> d <- myCov@d; n <- 20
> ## design matrix
> X <- matrix(runif(n*d), nrow = n, ncol = d)
> colnames(X) <- inputNames(myCov)
> ## generate the GP realization
> myGp <- gp(formula = y ~ 1, data = data.frame(y = rep(0, n), X),
+ cov = myCov, estim = FALSE,
+ beta = 10, varNoise = 0.05)
> y <- simulate(myGp, cond = FALSE)$sim
Loading required package: MASS
>
> ## parIni: add noise to true parameters
> parCovIni <- coef(myCov)
> parCovIni[] <- 0.9 * parCovIni[] + 0.1 * runif(length(parCovIni))
> coefLower(myCov) <- rep(1e-2, 4)
> coefUpper(myCov) <- c(5, 5, 20, 20)
> est <- gp(y ~ 1, data = data.frame(y = y, X),
+ cov = myCov,
+ noise = TRUE,
+ varNoiseLower = 1e-2,
+ varNoiseIni = 1.0,
+ parCovIni = parCovIni)
Warning in nloptr.add.default.options(opts.user = opts, x0 = x0, num_constraints_ineq = num_constraints_ineq, :
No termination criterion specified, using default(relative x-tolerance = 1e-04)
> summary(est)
Call:
gp(formula = y ~ 1, data = data.frame(y = y, X), cov = myCov,
noise = TRUE, varNoiseLower = 0.01, varNoiseIni = 1, parCovIni = parCovIni)
Number of observations: 20
Trend coef.:
Value
(Intercept) 6.616421
Covariance whith class "covTS"
Tensor sum covariance kernel
o Dimension 'd' (nb of inputs): 2
o Kernel (1D): "Matern nu = 5/2" with parameters: "range"
o One parameter by input:
range: YES
o Number of parameters: 4
o Param. values:
Temp Humid
range 0.8206737 1.320164
var 2.2419969 15.197190
Noise variance: 0.039
> coef(est)
(Intercept) range.Temp range.Humid var.Temp var.Humid varNoise
6.6164214 0.8206737 1.3201637 2.2419969 15.1971902 0.0388751
>
> ## =======================================================================
> ## Example 2. Predicting an additive function with an additive GP model
> ## =======================================================================
>
> ## Not run:
> ##D
> ##D addfun6d <- function(x){
> ##D res <- x[1]^3 + cos(pi * x[2]) + abs(x[3]) * sin(x[3]^2) +
> ##D 3 * x[4]^3 + 3 * cos(pi * x[5]) + 3 * abs(x[6]) * sin(x[6]^2)
> ##D }
> ##D
> ##D ## 'Fit' is for the learning set, 'Val' for the validation set
> ##D set.seed(123)
> ##D nFit <- 50
> ##D nVal <- 200
> ##D d <- 6
> ##D inputs <- paste("x", 1L:d, sep = "")
> ##D
> ##D ## create design matrices with DiceDesign package
> ##D require(DiceDesign)
> ##D require(DiceKriging)
> ##D set.seed(0)
> ##D dataFitIni <- DiceDesign::lhsDesign(nFit, d)$design
> ##D dataValIni <- DiceDesign::lhsDesign(nVal, d)$design
> ##D dataFit <- DiceDesign::maximinSA_LHS(dataFitIni)$design
> ##D dataVal <- DiceDesign::maximinSA_LHS(dataValIni)$design
> ##D
> ##D colnames(dataFit) <- colnames(dataVal) <- inputs
> ##D testfun <- addfun6d
> ##D dataFit <- data.frame(dataFit, y = apply(dataFit, 1, testfun))
> ##D dataVal <- data.frame(dataVal, y = apply(dataVal, 1, testfun))
> ##D
> ##D ## Creation of "CovTS" object with one range by input
> ##D myCov <- covTS(inputs = inputs, d = d, kernel = "k1Matern3_2",
> ##D dep = c(range = "input"))
> ##D
> ##D ## Creation of a gp object
> ##D fitgp <- gp(formula = y ~ 1, data = dataFit,
> ##D cov = myCov, noise = TRUE,
> ##D parCovIni = rep(1, 2*d),
> ##D parCovLower = c(rep(1e-4, 2*d)),
> ##D parCovUpper = c(rep(5, d), rep(10,d)))
> ##D
> ##D predTS <- predict(fitgp, newdata = as.matrix(dataVal[ , inputs]), type = "UK")$mean
> ##D
> ##D ## Classical tensor product kernel as a reference for comparison
> ##D fitRef <- DiceKriging::km(formula = ~1,
> ##D design = dataFit[ , inputs],
> ##D response = dataFit$y, covtype="matern3_2")
> ##D predRef <- predict(fitRef,
> ##D newdata = as.matrix(dataVal[ , inputs]),
> ##D type = "UK")$mean
> ##D ## Compare TS and Ref
> ##D RMSE <- data.frame(TS = sqrt(mean((dataVal$y - predTS)^2)),
> ##D Ref = sqrt(mean((dataVal$y - predRef)^2)),
> ##D row.names = "RMSE")
> ##D print(RMSE)
> ##D
> ##D Comp <- data.frame(y = dataVal$y, predTS, predRef)
> ##D plot(predRef ~ y, data = Comp, col = "black", pch = 4,
> ##D xlab = "True", ylab = "Predicted",
> ##D main = paste("Prediction on a validation set (nFit = ",
> ##D nFit, ", nVal = ", nVal, ").", sep = ""))
> ##D points(predTS ~ y, data = Comp, col = "red", pch = 20)
> ##D abline(a = 0, b = 1, col = "blue", lty = "dotted")
> ##D legend("bottomright", pch = c(4, 20), col = c("black", "red"),
> ##D legend = c("Ref", "Tensor Sum"))
> ## End(Not run)
>
> ##=======================================================================
> ## Example 3: a 'covMan' kernel with 3 implementations
> ##=======================================================================
>
> d <- 4
>
> ## -- Define a 4-dimensional covariance structure with a kernel in R
>
> myGaussFunR <- function(x1, x2, par) {
+ h <- (x1 - x2) / par[1]
+ SS2 <- sum(h^2)
+ d2 <- exp(-SS2)
+ kern <- par[2] * d2
+ d1 <- 2 * kern * SS2 / par[1]
+ attr(kern, "gradient") <- c(theta = d1, sigma2 = d2)
+ return(kern)
+ }
>
> myGaussR <- covMan(kernel = myGaussFunR,
+ hasGrad = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: R implementation")
>
> ## -- The same, still in R, but with a kernel admitting matrices as arguments
>
> myGaussFunRVec <- function(x1, x2, par) {
+ # x1, x2 : matrices with same number of columns 'd' (dimension)
+ n <- nrow(x1)
+ d <- ncol(x1)
+ SS2 <- 0
+ for (j in 1:d){
+ Aj <- outer(x1[ , j], x2[ , j], "-")
+ Hj2 <- (Aj / par[1])^2
+ SS2 <- SS2 + Hj2
+ }
+ D2 <- exp(-SS2)
+ kern <- par[2] * D2
+ D1 <- 2 * kern * SS2 / par[1]
+ attr(kern, "gradient") <- list(theta = D1, sigma2 = D2)
+
+ return(kern)
+ }
>
> myGaussRVec <- covMan(
+ kernel = myGaussFunRVec,
+ hasGrad = TRUE,
+ acceptMatrix = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: vectorised R implementation"
+ )
>
> ## -- The same, with inlined C code
> ## (see also another example with Rcpp by typing: ?kergp).
>
> if (require(inline)) {
+
+ kernCode <- "
+ SEXP kern, dkern;
+ int nprotect = 0, d;
+ double SS2 = 0.0, d2, z, *rkern, *rdkern;
+
+ d = LENGTH(x1);
+ PROTECT(kern = allocVector(REALSXP, 1)); nprotect++;
+ PROTECT(dkern = allocVector(REALSXP, 2)); nprotect++;
+ rkern = REAL(kern);
+ rdkern = REAL(dkern);
+
+ for (int i = 0; i < d; i++) {
+ z = ( REAL(x1)[i] - REAL(x2)[i] ) / REAL(par)[0];
+ SS2 += z * z;
+ }
+
+ d2 = exp(-SS2);
+ rkern[0] = REAL(par)[1] * d2;
+ rdkern[1] = d2;
+ rdkern[0] = 2 * rkern[0] * SS2 / REAL(par)[0];
+
+ SET_ATTR(kern, install(\"gradient\"), dkern);
+ UNPROTECT(nprotect);
+ return kern;
+ "
+ myGaussFunC <- cfunction(sig = signature(x1 = "numeric", x2 = "numeric",
+ par = "numeric"),
+ body = kernCode)
+
+ myGaussC <- covMan(kernel = myGaussFunC,
+ hasGrad = TRUE,
+ d = d,
+ parLower = c(theta = 0.0, sigma2 = 0.0),
+ parUpper = c(theta = Inf, sigma2 = Inf),
+ parNames = c("theta", "sigma2"),
+ label = "Gaussian kernel: C/inline implementation")
+
+ }
Loading required package: inline
Attaching package: ‘inline’
The following object is masked from ‘package:Rcpp’:
registerPlugin
ERROR(s) during compilation: source code errors or compiler configuration errors!
make cmd is
make -f '/data/gannet/ripley/R/R-devel/etc/Makeconf' -f '/data/gannet/ripley/R/R-devel/share/make/shlib.mk' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='file1ecab628ac54ee.so' CXX_DEFS=-DR_NO_REMAP OBJECTS='file1ecab628ac54ee.o'
make would use
make[1]: Entering directory '/tmp/Rtmpvqr5RP/working_dir/RtmpsgAXR2'
g++-14 -std=gnu++17 -I"/data/gannet/ripley/R/R-devel/include" -DNDEBUG -I/usr/local/include -fpic -g -O2 -Wall -pedantic -mtune=native -Wno-ignored-attributes -Wno-parentheses -Wp,-D_FORTIFY_SOURCE=3 -fexceptions -fstack-protector-strong -fstack-clash-protection -fcf-protection -DR_NO_REMAP -c file1ecab628ac54ee.cpp -o file1ecab628ac54ee.o
if test "zfile1ecab628ac54ee.o" != "z"; then \
echo g++-14 -std=gnu++17 -shared -L/usr/local/gcc14/lib64 -L/usr/local/lib64 -o file1ecab628ac54ee.so file1ecab628ac54ee.o ; \
g++-14 -std=gnu++17 -shared -L/usr/local/gcc14/lib64 -L/usr/local/lib64 -o file1ecab628ac54ee.so file1ecab628ac54ee.o ; \
fi
make[1]: Leaving directory '/tmp/Rtmpvqr5RP/working_dir/RtmpsgAXR2'
Program source:
1: #include <R.h>
2: #include <Rdefines.h>
3: #include <R_ext/Error.h>
4:
5:
6: extern "C" {
7: SEXP file1ecab628ac54ee ( SEXP x1, SEXP x2, SEXP par );
8: }
9:
10: SEXP file1ecab628ac54ee ( SEXP x1, SEXP x2, SEXP par ) {
11:
12: SEXP kern, dkern;
13: int nprotect = 0, d;
14: double SS2 = 0.0, d2, z, *rkern, *rdkern;
15:
16: d = LENGTH(x1);
17: PROTECT(kern = allocVector(REALSXP, 1)); nprotect++;
18: PROTECT(dkern = allocVector(REALSXP, 2)); nprotect++;
19: rkern = REAL(kern);
20: rdkern = REAL(dkern);
21:
22: for (int i = 0; i < d; i++) {
23: z = ( REAL(x1)[i] - REAL(x2)[i] ) / REAL(par)[0];
24: SS2 += z * z;
25: }
26:
27: d2 = exp(-SS2);
28: rkern[0] = REAL(par)[1] * d2;
29: rdkern[1] = d2;
30: rdkern[0] = 2 * rkern[0] * SS2 / REAL(par)[0];
31:
32: SET_ATTR(kern, install("gradient"), dkern);
33: UNPROTECT(nprotect);
34: return kern;
35:
36: Rf_warning("your C program does not return anything!");
37: return R_NilValue;
38: }
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language, verbose) :
XPREC* file1ecab628ac54ee(SEXP, SEXP, SEXP)':
file1ecab628ac54ee.cpp:17:23: error: 'allocVector' was not declared in this scope; did you mean 'Rf_allocVector'?
17 | PROTECT(kern = allocVector(REALSXP, 1)); nprotect++;
| ^~~~~~~~~~~
/data/gannet/ripley/R/R-devel/include/Rinternals.h:388:36: note: in definition of macro 'PROTECT'
388 | #define PROTECT(s) Rf_protect(s)
| ^
file1ecab628ac54ee.cpp:32:23: error: 'install' was not declared in this scope
32 | SET_ATTR(kern, install("gradient"), dkern);
| ^~~~~~~
/data/gannet/ripley/R/R-devel/include/Rdefines.h:141:49: note: in definition of macro 'SET_ATTR'
141 | #define SET_ATTR(x, what, n) Rf_setAttrib(x, what, n)
| ^~~~
make[1]: *** [/data/gannet/ripley/R/R-devel/etc/Makeconf:202: file1ecab628ac54ee.o] Error 1
make[1]: Target 'all' not remade because o
Calls: cfunction -> compileCode
Execution halted
Flavor: r-devel-linux-x86_64-fedora-gcc