CXXR (C++ R) API
Applic.h
1 /*CXXR $Id: Applic.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 1998-2007 Robert Gentleman, Ross Ihaka
20  * and the R Core Team
21  *
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU Lesser General Public License as published by
24  * the Free Software Foundation; either version 2.1 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  *
32  * You should have received a copy of the GNU Lesser General Public License
33  * along with this program; if not, a copy is available at
34  * http://www.r-project.org/Licenses/
35  *
36  *
37  * Application Routines, typically implemented in ../appl/
38  * ---------------------------------------------- ========
39  */
40 
41 /* This header file contains routines which are in the R API and ones which
42  are not.
43 
44  Those which are not can be used only at the user's risk and may change
45  or disappear in a future release of R.
46 */
47 
48 
49 #ifndef R_APPLIC_H_
50 #define R_APPLIC_H_
51 
52 #include <R_ext/Boolean.h>
53 #include <R_ext/RS.h> /* F77_... */
54 #include <R_ext/BLAS.h>
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 /* Entry points in the R API */
61 
62 /* appl/integrate.c */
63 typedef void integr_fn(double *x, int n, void *ex);
64 /* vectorizing function f(x[1:n], ...) -> x[] {overwriting x[]}. */
65 
66 void Rdqags(integr_fn f, void *ex, double *a, double *b,
67  double *epsabs, double *epsrel,
68  double *result, double *abserr, int *neval, int *ier,
69  int *limit, int *lenw, int *last, int *iwork, double *work);
70 
71 void Rdqagi(integr_fn f, void *ex, double *bound, int *inf,
72  double *epsabs, double *epsrel,
73  double *result, double *abserr, int *neval, int *ier,
74  int *limit, int *lenw, int *last,
75  int *iwork, double *work);
76 
77 /* appl/rcont.c */
78 void rcont2(int *nrow, int *ncol, int *nrowt, int *ncolt, int *ntotal,
79  double *fact, int *jwork, int *matrix);
80 
81 /* main/optim.c */
82 typedef double optimfn(int, double *, void *);
83 typedef void optimgr(int, double *, double *, void *);
84 
85 void vmmin(int n, double *b, double *Fmin,
86  optimfn fn, optimgr gr, int maxit, int trace,
87  int *mask, double abstol, double reltol, int nREPORT,
88  void *ex, int *fncount, int *grcount, int *fail);
89 void nmmin(int n, double *Bvec, double *X, double *Fmin, optimfn fn,
90  int *fail, double abstol, double intol, void *ex,
91  double alpha, double bet, double gamm, int trace,
92  int *fncount, int maxit);
93 void cgmin(int n, double *Bvec, double *X, double *Fmin,
94  optimfn fn, optimgr gr,
95  int *fail, double abstol, double intol, void *ex,
96  int type, int trace, int *fncount, int *grcount, int maxit);
97 void lbfgsb(int n, int m, double *x, double *l, double *u, int *nbd,
98  double *Fmin, optimfn fn, optimgr gr, int *fail, void *ex,
99  double factr, double pgtol, int *fncount, int *grcount,
100  int maxit, char *msg, int trace, int nREPORT);
101 void samin(int n, double *pb, double *yb, optimfn fn, int maxit,
102  int tmax, double ti, int trace, void *ex);
103 
104 
105 
106 /* Entry points NOT in the R API */
107 
108 /* appl/bakslv.c : hidden */
109 void bakslv(double *, int *, int *,
110  double *, int *, int *,
111  double *, int *, int *);
112 
113 /* appl/binning.c : hidden */
114 void bincode (double *x, int *n, double *breaks, int *nb,
115  int *code, int *right, int *include_border, int *naok);
116 void bincount(double *x, int *n, double *breaks, int *nb, int *count,
117  int *right, int *include_border, int *naok);
118 
119 /* appl/ch2inv.f */
120 void F77_NAME(ch2inv)(double *x, int *ldx, int *n, double *v, int *info);
121 
122 /* appl/chol.f Used in nlme */
123 void F77_NAME(chol)(double *a, int *lda, int *n, double *v, int *info);
124 
125 /* appl/cpoly.c : hidden */
126 void R_cpolyroot(double *opr, double *opi, int *degree,
127  double *zeror, double *zeroi, Rboolean *fail);
128 /* More `Complex Polynomial Utilities' could be exported:
129 
130  polyev(...)
131  errev(...)
132  cpoly_cauchy(...)
133  cpoly_scale(...)
134  cdivid(...)
135 */
136 
137 
138 /* appl/cumsum.c : non-API, used in package DCluster */
139 void R_cumsum(double *, int *, double *, double *);
140 
141 /* appl/eigen.f */
142 int F77_NAME(cg)(int *nm, int *n, double *ar, double *ai,
143  double *wr, double *wi, int *matz, double *zr, double *zi,
144  double *fv1, double *fv2, double *fv3, int *ierr);
145 int F77_NAME(ch)(int *nm, int *n, double *ar, double *ai,
146  double *w, int *matz, double *zr, double *zi,
147  double *fv1, double *fv2, double *fm1, int *ierr);
148 int F77_NAME(rg)(int *nm, int *n, double *a, double *wr, double *wi,
149  int *matz, double *z, int *iv1, double *fv1, int *ierr);
150 /* used in nlme */
151 int F77_NAME(rs)(int *nm, int *n, double *a, double *w,
152  int *matz, double *z, double *fv1, double *fv2, int *ierr);
153 
154 /* appl/fft.c */
155 /* NOTE: The following functions use GLOBAL (static) variables !!
156  * ---- some of R-core think that this should be changed,
157  * which will INEVITABLY extend the argument lists ...!
158  */
159 /* non-API, but used by package RandomFields */
160 void fft_factor(int n, int *pmaxf, int *pmaxp);
161 Rboolean fft_work(double *a, double *b, int nseg, int n, int nspn,
162 /* TRUE: success */ int isn, double *work, int *iwork);
163 
164 /* appl/fmin.c : non-API, but used in package ape */
165 double Brent_fmin(double ax, double bx, double (*f)(double, void *),
166  void *info, double tol);
167 
168 /* appl/interv.c: also in Utils.h */
169 /* used in packages gam and mda */
170 int F77_SUB(interv)(double *xt, int *n, double *x,
171  Rboolean *rightmost_closed, Rboolean *all_inside,
172  int *ilo, int *mflag);
173 void find_interv_vec(double *xt, int *n, double *x, int *nx,
174  int *rightmost_closed, int *all_inside, int *indx);
175 /* used in package eco */
176 int findInterval(double *xt, int n, double x,
177  Rboolean rightmost_closed, Rboolean all_inside, int ilo,
178  int *mflag);
179 
180 /* appl/lbfgsb.c */
181 void setulb(int n, int m, double *x, double *l, double *u, int *nbd,
182  double *f, double *g, double factr, double *pgtol,
183  double *wa, int * iwa, char *task, int iprint,
184  int *lsave, int *isave, double *dsave);
185 
186 /* appl/machar.c */
187 void machar(int *ibeta, int *it, int *irnd, int *ngrd, int *machep,
188  int *negep, int *iexp, int *minexp, int *maxexp,
189  double *eps, double *epsneg, double *xmin, double *xmax);
190 
191 /* appl/maxcol.c: also in Utils.h Used in package MNP */
192 void R_max_col(double *matrix, int *nr, int *nc, int *maxes, int *ties_meth);
193 
194 
195 /* appl/pretty.c */
196 double R_pretty0(double *lo, double *up, int *ndiv, int min_n,
197  double shrink_sml, double high_u_fact[],
198  int eps_correction, int return_bounds);
199 void R_pretty(double *lo, double *up, int *ndiv, int *min_n,
200  double *shrink_sml, double *high_u_fact,
201  int *eps_correction);
202 
203 /* appl/rowsum.c */
204 void R_rowsum(int *dim, double *na_x, double *x, double *group);
205 
206 /* appl/stem.c */
207 Rboolean stemleaf(double *x, int *n, double *scale, int *width, double *atom);
208 
209 /* appl/strsignif.c */
210 void str_signif(char *x, int *n, const char **type, int *width, int *digits,
211  const char **format, const char **flag, char **result);
212 
213 /* appl/tabulate.c : non-API, used in package ape */
214 void R_tabulate(int *x, int *n, int *nbin, int *ans);
215 
216 /* appl/uncmin.c : */
217 
218 /* type of pointer to the target and gradient functions */
219 typedef void (*fcn_p)(int, double *, double *, void *);
220 
221 /* type of pointer to the hessian functions */
222 typedef void (*d2fcn_p)(int, int, double *, double *, void *);
223 
224 void fdhess(int n, double *x, double fval, fcn_p fun, void *state,
225  double *h, int nfd, double *step, double *f, int ndigit,
226  double *typx);
227 
228 /* used in nlme */
229 void optif9(int nr, int n, double *x,
230  fcn_p fcn, fcn_p d1fcn, d2fcn_p d2fcn,
231  void *state, double *typsiz, double fscale, int method,
232  int iexp, int *msg, int ndigit, int itnlim, int iagflg,
233  int iahflg, double dlt, double gradtl, double stepmx,
234  double steptl, double *xpls, double *fpls, double *gpls,
235  int *itrmcd, double *a, double *wrk, int *itncnt);
236 
237 void optif0(int nr, int n, double *x, fcn_p fcn, void *state,
238  double *xpls, double *fpls, double *gpls, int *itrmcd,
239  double *a, double *wrk);
240 
241 /* appl/zeroin.c : non API, but used in packages ape and qtl */
242 double R_zeroin(double ax, double bx, double (*f)(double, void *), void *info,
243  double *Tol, int *Maxit);
244 /* R_zeroin2() is faster for "expensive" f(), in those typical cases where
245  * f(ax) and f(bx) are available anyway : */
246 double R_zeroin2(double ax, double bx, double fa, double fb,
247  double (*f)(double, void *), void *info, double *Tol, int *Maxit);
248 
249 
250 /* ALL appl/<foobar>.f [semi-automatically by
251  * f2c -A -P *.f; cat *.P > all.h and editing]
252  */
253 
254 /* This is not in the applications but in the BLAS, and defined in Lapack.h
255 extern int F77_NAME(lsame)(const char *, const char *);
256 */
257 
258 /* LINPACK routines also declared in Linpack.h
259 void F77_NAME(dpoco)(double *a, int *lda, int *n, double *rcond,
260  double *z__, int *info);
261 void F77_NAME(dpodi)(double *a, int *lda, int *n, double *det, int *job);
262 void F77_NAME(dpofa)(double *a, int *lda, int *n, int *info);
263 void F77_NAME(dposl)(double *a, int *lda, int *n, double *b);
264 void F77_NAME(dqrdc)(double *x, int *ldx, int *n, int *p,
265  double *qraux, int *jpvt, double *work, int *job);
266 void F77_NAME(dqrsl)(double *x, int *ldx, int *n, int *k,
267  double *qraux, double *y,
268  double *qy, double *qty, double *b,
269  double *rsd, double *xb, int *job, int *info);
270 void F77_NAME(dsvdc)(double *x, int *ldx, int *n, int *p,
271  double *s, double *e,
272  double *u, int *ldu, double *v, int *ldv,
273  double *work, int *job, int *info);
274 void F77_NAME(dtrco)(double *t, int *ldt, int *n, double *rcond,
275  double *z__, int *job);
276 void F77_NAME(dtrsl)(double *t, int *ldt, int *n, double *b, int *job,
277  int *info);
278 */
279 
280 /* find qr decomposition, dqrdc2() is basis of R's qr(), also used by nlme */
281 void F77_NAME(dqrdc2)(double *x, int *ldx, int *n, int *p,
282  double *tol, int *rank,
283  double *qraux, int *pivot, double *work);
284 void F77_NAME(dqrls)(double *x, int *n, int *p, double *y, int *ny,
285  double *tol, double *b, double *rsd,
286  double *qty, int *k,
287  int *jpvt, double *qraux, double *work);
288 
289 /* appl/dqrutl.f: interfaces to dqrsl */
290 void F77_NAME(dqrqty)(double *x, int *n, int *k, double *qraux,
291  double *y, int *ny, double *qty);
292 void F77_NAME(dqrqy)(double *x, int *n, int *k, double *qraux,
293  double *y, int *ny, double *qy);
294 void F77_NAME(dqrcf)(double *x, int *n, int *k, double *qraux,
295  double *y, int *ny, double *b, int *info);
296 void F77_NAME(dqrrsd)(double *x, int *n, int *k, double *qraux,
297  double *y, int *ny, double *rsd);
298 void F77_NAME(dqrxb)(double *x, int *n, int *k, double *qraux,
299  double *y, int *ny, double *xb);
300 
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif /* R_APPLIC_H_ */