Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more cleaning up

git-svn-id: https://svn.r-project.org/R/trunk@60890 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
commit b2d9b83a11e50d16b285901849d0b5262067c8c3 1 parent 32bd6c5
ripley authored
1  src/library/stats/R/cmdscale.R
@@ -43,6 +43,7 @@ cmdscale <- function (d, k = 2, eig = FALSE, add = FALSE, x.ret = FALSE)
43 43 if(is.na(n) || n > 46340) stop("invalid value of 'n'")
44 44 if((k <- as.integer(k)) > n - 1 || k < 1)
45 45 stop("'k' must be in {1, 2, .. n - 1}")
  46 + ## NB: this alters argument x, which is OK as it is re-assigned.
46 47 x <- .Call(C_DoubleCentre, x)
47 48
48 49 if(add) { ## solve the additive constant problem
22 src/library/stats/src/dblcen.c
@@ -24,21 +24,21 @@
24 24 /* NB: this does not duplicate A */
25 25 SEXP DoubleCentre(SEXP A)
26 26 {
27   - int i, j, n = nrows(A);
28   - double *a = REAL(A), sum;
29   - size_t N = n;
  27 + int n = nrows(A);
  28 + double *a = REAL(A);
  29 + size_t N = n; /* avoid integer overflow with long vectors */
30 30
31   - for(i = 0 ; i < n ; i++) {
32   - sum = 0;
33   - for(j = 0 ; j < n ; j++) sum += a[i+j*N];
  31 + for(int i = 0; i < n; i++) {
  32 + double sum = 0;
  33 + for(int j = 0; j < n; j++) sum += a[i+j*N];
34 34 sum /= n;
35   - for(j = 0 ; j < n ; j++) a[i+j*N] -= sum;
  35 + for(int j = 0; j < n; j++) a[i+j*N] -= sum;
36 36 }
37   - for(j = 0 ; j < n ; j++) {
38   - sum = 0;
39   - for(i = 0 ; i < n ; i++) sum += a[i+j*N];
  37 + for(int j = 0; j < n; j++) {
  38 + double sum = 0;
  39 + for(int i = 0; i < n; i++) sum += a[i+j*N];
40 40 sum /= n;
41   - for(i = 0 ; i < n ; i++) a[i+j*N] -= sum;
  41 + for(int i = 0; i < n; i++) a[i+j*N] -= sum;
42 42 }
43 43 return A;
44 44 }

0 comments on commit b2d9b83

Please sign in to comment.
Something went wrong with that request. Please try again.