==1088073== Memcheck, a memory error detector ==1088073== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al. ==1088073== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info ==1088073== Command: /data/blackswan/ripley/R/R-devel-vg/bin/exec/R --vanilla ==1088073== R Under development (unstable) (2026-04-01 r89777) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "n1qn1" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('n1qn1') > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("dot-n1qn1ptr") > ### * dot-n1qn1ptr > > flush(stderr()); flush(stdout()) > > ### Name: .n1qn1ptr > ### Title: This gives the function pointers in the n1qn1 library > ### Aliases: .n1qn1ptr > > ### ** Examples > > > .n1qn1ptr() $n1qn1F $n1qn1F2 $n1qn1_ > > > > > cleanEx() > nameEx("n1qn1") > ### * n1qn1 > > flush(stderr()); flush(stdout()) > > ### Name: n1qn1 > ### Title: n1qn1 optimization > ### Aliases: n1qn1 > > ### ** Examples > > > ## Rosenbrock's banana function > n=3; p=100 > > fr = function(x) + { + f=1.0 + for(i in 2:n) { + f=f+p*(x[i]-x[i-1]**2)**2+(1.0-x[i])**2 + } + f + } > > grr = function(x) + { + g = double(n) + g[1]=-4.0*p*(x[2]-x[1]**2)*x[1] + if(n>2) { + for(i in 2:(n-1)) { + g[i]=2.0*p*(x[i]-x[i-1]**2)-4.0*p*(x[i+1]-x[i]**2)*x[i]-2.0*(1.0-x[i]) + } + } + g[n]=2.0*p*(x[n]-x[n-1]**2)-2.0*(1.0-x[n]) + g + } > > x = c(1.02,1.02,1.02) > eps=1e-3 > n=length(x); niter=100L; nsim=100L; imp=3L; > nzm=as.integer(n*(n+13)/2) > zm=double(nzm) > > (op1 <- n1qn1(fr, grr, x, imp=3)) $value [1] 1 $par [1] 1 1 1 $H [,1] [,2] [,3] [1,] 799.9959094 -399.6141 -0.1962135 [2,] -399.6140752 1002.5950 -400.3193166 [3,] -0.1962135 -400.3193 202.1709062 $c.hess [1] 799.9959094 -399.6140752 -0.1962135 1002.5949739 -400.3193166 [6] 202.1709062 0.0000000 0.0000000 0.0000000 0.0000000 [11] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [16] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [21] 0.0000000 0.0000000 0.0000000 0.0000000 $n.fn [1] 40 $n.gr [1] 40 > > ## Note there are 40 function calls and 40 gradient calls in the above optimization > > ## Now assume we know something about the Hessian: > c.hess <- c(797.861115, + -393.801473, + -2.795134, + 991.271179, + -395.382900, + 200.024349) > c.hess <- c(c.hess, rep(0, 24 - length(c.hess))) > > (op2 <- n1qn1(fr, grr, x,imp=3, zm=c.hess)) ==1088073== Mismatched new/delete size value: 16 ==1088073== at 0x4847B51: operator delete(void*, unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:1181) ==1088073== by 0x1841A5CC: n1qn1_wrap (packages/tests-vg/n1qn1/src/RcppExpMod.cpp:58) ==1088073== by 0x4A8E79: R_doDotCall (svn/R-devel/src/main/dotcode.c:813) ==1088073== by 0x4E3E43: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7515) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7500) ==1088073== by 0x4F42CA: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==1088073== by 0x4F604D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==1088073== by 0x4F6D06: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==1088073== by 0x4F43D5: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==1088073== by 0x4F43D5: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==1088073== by 0x4F909C: do_set (svn/R-devel/src/main/eval.c:3581) ==1088073== by 0x4F4632: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==1088073== by 0x4F9230: Rf_evalList (svn/R-devel/src/main/eval.c:3679) ==1088073== Address 0xfa05950 is 0 bytes inside a block of size 32 alloc'd ==1088073== at 0x4843FEC: operator new(unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:487) ==1088073== by 0x1841A5EB: n1qn1_wrap (packages/tests-vg/n1qn1/src/RcppExpMod.cpp:62) ==1088073== by 0x4A8E79: R_doDotCall (svn/R-devel/src/main/dotcode.c:813) ==1088073== by 0x4E3E43: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7515) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7500) ==1088073== by 0x4F42CA: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==1088073== by 0x4F604D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==1088073== by 0x4F6D06: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==1088073== by 0x4F43D5: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==1088073== by 0x4F43D5: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==1088073== by 0x4F909C: do_set (svn/R-devel/src/main/eval.c:3581) ==1088073== by 0x4F4632: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==1088073== by 0x4F9230: Rf_evalList (svn/R-devel/src/main/eval.c:3679) ==1088073== ==1088073== Mismatched new/delete size value: 16 ==1088073== at 0x4847B51: operator delete(void*, unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:1181) ==1088073== by 0x1841A64F: n1qn1_wrap (packages/tests-vg/n1qn1/src/RcppExpMod.cpp:64) ==1088073== by 0x4A8E79: R_doDotCall (svn/R-devel/src/main/dotcode.c:813) ==1088073== by 0x4E3E43: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7515) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7500) ==1088073== by 0x4F42CA: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==1088073== by 0x4F604D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==1088073== by 0x4F6D06: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==1088073== by 0x4F43D5: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==1088073== by 0x4F43D5: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==1088073== by 0x4F909C: do_set (svn/R-devel/src/main/eval.c:3581) ==1088073== by 0x4F4632: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==1088073== by 0x4F9230: Rf_evalList (svn/R-devel/src/main/eval.c:3679) ==1088073== Address 0xfcff3e0 is 0 bytes inside a block of size 32 alloc'd ==1088073== at 0x4843FEC: operator new(unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:487) ==1088073== by 0x1841A66A: n1qn1_wrap (packages/tests-vg/n1qn1/src/RcppExpMod.cpp:68) ==1088073== by 0x4A8E79: R_doDotCall (svn/R-devel/src/main/dotcode.c:813) ==1088073== by 0x4E3E43: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7515) ==1088073== by 0x4F3F97: bcEval (svn/R-devel/src/main/eval.c:7500) ==1088073== by 0x4F42CA: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==1088073== by 0x4F604D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==1088073== by 0x4F6D06: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==1088073== by 0x4F43D5: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==1088073== by 0x4F43D5: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==1088073== by 0x4F909C: do_set (svn/R-devel/src/main/eval.c:3581) ==1088073== by 0x4F4632: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==1088073== by 0x4F9230: Rf_evalList (svn/R-devel/src/main/eval.c:3679) ==1088073== $value [1] 1 $par [1] 1 1 1 $H [,1] [,2] [,3] [1,] 800.03080771 -399.8782 -0.05266924 [2,] -399.87816045 1001.8405 -399.89053754 [3,] -0.05266924 -399.8905 201.93261767 $c.hess [1] 800.03080771 -399.87816045 -0.05266924 1001.84045503 -399.89053754 [6] 201.93261767 0.00000000 0.00000000 0.00000000 0.00000000 [11] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 [16] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 [21] 0.00000000 0.00000000 0.00000000 0.00000000 $n.fn [1] 29 $n.gr [1] 29 > > ## Note with this knowledge, there were only 29 function/gradient calls > > (op3 <- n1qn1(fr, grr, x, imp=3, zm=op1$c.hess)) $value [1] 1 $par [1] 1 1 1 $H [,1] [,2] [,3] [1,] 795.2593270 -397.1187 -0.1459179 [2,] -397.1186752 1000.8727 -400.2294075 [3,] -0.1459179 -400.2294 202.1576894 $c.hess [1] 795.2593270 -397.1186752 -0.1459179 1000.8726637 -400.2294075 [6] 202.1576894 0.0000000 0.0000000 0.0000000 0.0000000 [11] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [16] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 [21] 0.0000000 0.0000000 0.0000000 0.0000000 $n.fn [1] 33 $n.gr [1] 33 > > ## The number of function evaluations is still reduced because the Hessian > ## is closer to what it should be than the initial guess. > > ## With certain optimization procedures this can be helpful in reducing the > ## Optimization time. > > > > > ### *