Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
Showing with 12 additions and 11 deletions.
  1. +1 −0  src/library/stats/R/cmdscale.R
  2. +11 −11 src/library/stats/src/dblcen.c
1  src/library/stats/R/cmdscale.R
View
@@ -43,6 +43,7 @@ cmdscale <- function (d, k = 2, eig = FALSE, add = FALSE, x.ret = FALSE)
if(is.na(n) || n > 46340) stop("invalid value of 'n'")
if((k <- as.integer(k)) > n - 1 || k < 1)
stop("'k' must be in {1, 2, .. n - 1}")
+ ## NB: this alters argument x, which is OK as it is re-assigned.
x <- .Call(C_DoubleCentre, x)
if(add) { ## solve the additive constant problem
22 src/library/stats/src/dblcen.c
View
@@ -24,21 +24,21 @@
/* NB: this does not duplicate A */
SEXP DoubleCentre(SEXP A)
{
- int i, j, n = nrows(A);
- double *a = REAL(A), sum;
- size_t N = n;
+ int n = nrows(A);
+ double *a = REAL(A);
+ size_t N = n; /* avoid integer overflow with long vectors */
- for(i = 0 ; i < n ; i++) {
- sum = 0;
- for(j = 0 ; j < n ; j++) sum += a[i+j*N];
+ for(int i = 0; i < n; i++) {
+ double sum = 0;
+ for(int j = 0; j < n; j++) sum += a[i+j*N];
sum /= n;
- for(j = 0 ; j < n ; j++) a[i+j*N] -= sum;
+ for(int j = 0; j < n; j++) a[i+j*N] -= sum;
}
- for(j = 0 ; j < n ; j++) {
- sum = 0;
- for(i = 0 ; i < n ; i++) sum += a[i+j*N];
+ for(int j = 0; j < n; j++) {
+ double sum = 0;
+ for(int i = 0; i < n; i++) sum += a[i+j*N];
sum /= n;
- for(i = 0 ; i < n ; i++) a[i+j*N] -= sum;
+ for(int i = 0; i < n; i++) a[i+j*N] -= sum;
}
return A;
}
Please sign in to comment.
Something went wrong with that request. Please try again.