Running examples in ‘kergp-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### 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.468396

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.8562201  1.356954
var   2.2592352 15.459578

Noise variance: 0.041
> coef(est)
(Intercept)  range.Temp range.Humid    var.Temp   var.Humid    varNoise 
 6.46839553  0.85622010  1.35695422  2.25923522 15.45957780  0.04114952 
> 
> ## =======================================================================
> ## 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 '/home/hornik/tmp/R.check/r-devel-gcc/Work/build/etc/Makeconf' -f '/home/hornik/tmp/R.check/r-devel-gcc/Work/build/share/make/shlib.mk' -f '/home/hornik/.R/Makevars-gcc' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='file311b037979577e.so' CXX_DEFS=-DR_NO_REMAP XDEFS=-DSTRICT_R_HEADERS=1 OBJECTS='file311b037979577e.o'

make would use
make[1]: Entering directory '/tmp/RtmpiuWC1h'
g++-14 -std=gnu++17 -I"/home/hornik/tmp/R.check/r-devel-gcc/Work/build/include" -DNDEBUG   -I/usr/local/include -D_FORTIFY_SOURCE=3 -DSTRICT_R_HEADERS=1  -fpic  -g -O2 -Wall -pedantic -mtune=native  -DR_NO_REMAP -c file311b037979577e.cpp -o file311b037979577e.o
if test  "zfile311b037979577e.o" != "z"; then \
  echo g++-14 -std=gnu++17 -shared -L"/home/hornik/tmp/R.check/r-devel-gcc/Work/build/lib" -Wl,-O1 -o file311b037979577e.so file311b037979577e.o    -L"/home/hornik/tmp/R.check/r-devel-gcc/Work/build/lib" -lR; \
  g++-14 -std=gnu++17 -shared -L"/home/hornik/tmp/R.check/r-devel-gcc/Work/build/lib" -Wl,-O1 -o file311b037979577e.so file311b037979577e.o    -L"/home/hornik/tmp/R.check/r-devel-gcc/Work/build/lib" -lR; \
fi
make[1]: Leaving directory '/tmp/RtmpiuWC1h'

Program source:
  1: #include <R.h>
  2: #include <Rdefines.h>
  3: #include <R_ext/Error.h>
  4: 
  5: 
  6: extern "C" {
  7:   SEXP file311b037979577e ( SEXP x1, SEXP x2, SEXP par );
  8: }
  9: 
 10: SEXP file311b037979577e ( 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:   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) : 
        |                                                 ^~~~file311b037979577e.cpp:36:3: error: ‘warning’ was not declared in this scope; did you mean ‘Rf_warning’?   36 |   warning("your C program does not return anything!");      |   ^~~~~~~      |   Rf_warningmake[1]: *** [/home/hornik/tmp/R.check/r-devel-gcc/Work/build/etc/Makeconf:204: file311b037979577e.o] Error 1
Calls: cfunction -> compileCode
Execution halted