Skip to content

Commit 784ec43

Browse files
author
maechler
committed
cosmetic changes, C: local declarations; Ftn: do .. end do
git-svn-id: https://svn.r-project.org/R/trunk@87292 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f4f2a2f commit 784ec43

File tree

5 files changed

+191
-194
lines changed

5 files changed

+191
-194
lines changed

src/appl/optim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ void cgmin(int n, double *Bvec, double *X, double *Fmin,
494494
case 2: Rprintf("Method: Polak Ribiere\n"); break;
495495
case 3: Rprintf("Method: Beale Sorenson\n"); break;
496496
default:
497-
error(_("unknown 'type' in \"CG\" method of 'optim'"));
497+
error(_("unknown type in \"CG\" method of 'optim'"));
498498
}
499499
}
500500
c = vect(n); g = vect(n); t = vect(n);
@@ -507,7 +507,7 @@ void cgmin(int n, double *Bvec, double *X, double *Fmin,
507507
if (trace) Rprintf("tolerance used in gradient test=%g\n", tol);
508508
f = fminfn(n, Bvec, ex);
509509
if (!R_FINITE(f)) {
510-
error(_("Function cannot be evaluated at initial parameters"));
510+
error(_("function cannot be evaluated at initial parameters"));
511511
} else {
512512
*Fmin = f;
513513
funcount = 1;

src/include/R_ext/Lapack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,7 @@ F77_NAME(zgebak)(const char* job, const char* side, La_INT *n, La_INT *ilo,
29242924
La_INT *ihi, double *scale, La_INT *m, La_complex *v,
29252925
La_INT *ldv, La_INT *info FCLEN FCLEN);
29262926

2927+
/* ZGEBAL balances a general complex matrix A */
29272928
La_extern void
29282929
F77_NAME(zgebal)(const char *job, const La_INT *n, La_complex *a,
29292930
const La_INT *lda, La_INT *ilo, La_INT *ihi, double *scale,

src/library/stats/src/ks.c

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ K2l(double x, int lower, double tol)
8787
* the value for x < 0.2, and use the standard expansion otherwise.)
8888
*
8989
*/
90-
double new, old, s, w, z, p;
91-
int k, k_max;
92-
93-
k_max = (int) sqrt(2 - log(tol));
90+
double s, z, p;
91+
int k;
9492

9593
/* Note that for x = 0.1 we get 6.609305e-53 ... */
9694
if(x <= 0.) {
@@ -100,8 +98,9 @@ K2l(double x, int lower, double tol)
10098
p = 1.;
10199
}
102100
else if(x < 1.) {
101+
int k_max = (int) sqrt(2 - log(tol));
102+
double w = log(x);
103103
z = - (M_PI_2 * M_PI_4) / (x * x);
104-
w = log(x);
105104
s = 0;
106105
for(k = 1; k < k_max; k += 2) {
107106
s += exp(k * k * z - w);
@@ -111,6 +110,7 @@ K2l(double x, int lower, double tol)
111110
p = 1 - p;
112111
}
113112
else {
113+
double new, old;
114114
z = -2 * x * x;
115115
s = -1;
116116
if(lower) {
@@ -136,7 +136,7 @@ K2l(double x, int lower, double tol)
136136

137137
/* Two-sample exact distributions.
138138
139-
See
139+
See
140140
141141
Gunar Schröer and Dietrich Trenkler (1995),
142142
Exact and Randomization Distributions of Kolmogorov-Smirnov Tests
@@ -159,7 +159,7 @@ K2l(double x, int lower, double tol)
159159
160160
A_{i,j} = D_{i,j} (A_{i-1,j} + A_{i,j-1})
161161
162-
with
162+
with
163163
164164
D_{i,j} = 0 if FUN(i/m - j/n) >= q
165165
1 otherwise
@@ -249,33 +249,30 @@ psmirnov_exact_test_two(double q, double r, double s) {
249249

250250
static double
251251
psmirnov_exact_uniq_lower(double q, int m, int n, int two) {
252-
double md, nd, *u, w;
253-
int i, j;
252+
double
253+
md = (double) m,
254+
nd = (double) n;
254255
int (*test)(double, double, double);
255-
256-
md = (double) m;
257-
nd = (double) n;
258256
if(two)
259257
test = psmirnov_exact_test_two;
260258
else
261259
test = psmirnov_exact_test_one;
262260

263-
u = (double *) R_alloc(n + 1, sizeof(double));
264-
261+
double *u = (double *) R_alloc(n + 1, sizeof(double));
265262
u[0] = 1.;
266-
for(j = 1; j <= n; j++) {
263+
for(int j = 1; j <= n; j++) {
267264
if(test(q, 0., j / nd))
268265
u[j] = 0.;
269266
else
270267
u[j] = u[j - 1];
271268
}
272-
for(i = 1; i <= m; i++) {
273-
w = (double)(i) / ((double)(i + n));
269+
for(int i = 1; i <= m; i++) {
270+
double w = (double)(i) / ((double)(i + n));
274271
if(test(q, i / md, 0.))
275272
u[0] = 0.;
276273
else
277274
u[0] = w * u[0];
278-
for(j = 1; j <= n; j++) {
275+
for(int j = 1; j <= n; j++) {
279276
if(test(q, i / md, j / nd))
280277
u[j] = 0.;
281278
else
@@ -287,35 +284,33 @@ psmirnov_exact_uniq_lower(double q, int m, int n, int two) {
287284

288285
static double
289286
psmirnov_exact_uniq_upper(double q, int m, int n, int two) {
290-
double md, nd, *u, v, w;
291-
int i, j;
287+
double
288+
md = (double) m,
289+
nd = (double) n;
292290
int (*test)(double, double, double);
293-
294-
md = (double) m;
295-
nd = (double) n;
296291
if(two)
297292
test = psmirnov_exact_test_two;
298293
else
299294
test = psmirnov_exact_test_one;
300295

301-
u = (double *) R_alloc(n + 1, sizeof(double));
302-
296+
double *u = (double *) R_alloc(n + 1, sizeof(double));
303297
u[0] = 0.;
304-
for(j = 1; j <= n; j++) {
298+
for(int j = 1; j <= n; j++) {
305299
if(test(q, 0., j / nd))
306300
u[j] = 1.;
307301
else
308302
u[j] = u[j - 1];
309303
}
310-
for(i = 1; i <= m; i++) {
304+
for(int i = 1; i <= m; i++) {
311305
if(test(q, i / md, 0.))
312306
u[0] = 1.;
313-
for(j = 1; j <= n; j++) {
307+
for(int j = 1; j <= n; j++) {
314308
if(test(q, i / md, j / nd))
315309
u[j] = 1.;
316310
else {
317-
v = (double)(i) / (double)(i + j);
318-
w = (double)(j) / (double)(i + j); /* 1 - v */
311+
double
312+
v = (double)(i) / (double)(i + j),
313+
w = (double)(j) / (double)(i + j); /* 1 - v */
319314
u[j] = v * u[j] + w * u[j - 1];
320315
}
321316
}
@@ -425,20 +420,19 @@ K2x(int n, double d)
425420
URL: http://www.jstatsoft.org/v08/i18/.
426421
*/
427422

428-
int k, m, i, j, g, eH, eQ;
429-
double h, s, *H, *Q;
430-
431423
/*
432424
The faster right-tail approximation is omitted here.
433425
s = d*d*n;
434426
if(s > 7.24 || (s > 3.76 && n > 99))
435427
return 1-2*exp(-(2.000071+.331/sqrt(n)+1.409/n)*s);
436428
*/
437-
k = (int) (n * d) + 1;
438-
m = 2 * k - 1;
439-
h = k - n * d;
440-
H = (double*) R_Calloc(m * m, double);
441-
Q = (double*) R_Calloc(m * m, double);
429+
int k = (int) (n * d) + 1,
430+
m = 2 * k - 1;
431+
double h = k - n * d,
432+
*H = (double*) R_Calloc(m * m, double),
433+
*Q = (double*) R_Calloc(m * m, double);
434+
435+
int i, j;
442436
for(i = 0; i < m; i++)
443437
for(j = 0; j < m; j++)
444438
if(i - j + 1 < 0)
@@ -453,11 +447,11 @@ K2x(int n, double d)
453447
for(i = 0; i < m; i++)
454448
for(j = 0; j < m; j++)
455449
if(i - j + 1 > 0)
456-
for(g = 1; g <= i - j + 1; g++)
450+
for(int g = 1; g <= i - j + 1; g++)
457451
H[i * m + j] /= g;
458-
eH = 0;
452+
int eH = 0, eQ;
459453
m_power(H, eH, Q, &eQ, m, n);
460-
s = Q[(k - 1) * m + k - 1];
454+
double s = Q[(k - 1) * m + k - 1];
461455
for(i = 1; i <= n; i++) {
462456
s = s * i / n;
463457
if(s < 1e-140) {
@@ -478,10 +472,9 @@ m_multiply(double *A, double *B, double *C, int m)
478472
Matrix multiplication.
479473
*/
480474
int i, j, k;
481-
double s;
482475
for(i = 0; i < m; i++)
483476
for(j = 0; j < m; j++) {
484-
s = 0.;
477+
double s = 0.;
485478
for(k = 0; k < m; k++)
486479
s+= A[i * m + k] * B[k * m + j];
487480
C[i * m + j] = s;
@@ -494,19 +487,17 @@ m_power(double *A, int eA, double *V, int *eV, int m, int n)
494487
/* Auxiliary routine used by K2x().
495488
Matrix power.
496489
*/
497-
double *B;
498-
int eB, i;
499-
490+
int i;
500491
if(n == 1) {
501492
for(i = 0; i < m * m; i++)
502493
V[i] = A[i];
503494
*eV = eA;
504495
return;
505496
}
506497
m_power(A, eA, V, eV, m, n / 2);
507-
B = (double*) R_Calloc(m * m, double);
498+
double *B = (double*) R_Calloc(m * m, double);
508499
m_multiply(V, V, B, m);
509-
eB = 2 * (*eV);
500+
int eB = 2 * (*eV);
510501
if((n % 2) == 0) {
511502
for(i = 0; i < m * m; i++)
512503
V[i] = B[i];

0 commit comments

Comments
 (0)