Re: [R] speeding up a special product of three arrays

2008-05-09 Thread Vincent Goulet
Le ven. 09 mai à 03:44, Dimitris Rizopoulos a écrit : try this: A <- matrix(rnorm(10*4), 10, 4) B <- matrix(rnorm(3*4), 3, 4) C <- matrix(rnorm(5*4), 5, 4) nrA <- nrow(A); nrB <- nrow(B); nrC <- nrow(C) ind <- as.matrix(expand.grid(1:nrA, 1:nrB, 1:nrC)) D <- rowSums(A[ind[, 1], ] * B[ind[, 2],

Re: [R] speeding up a special product of three arrays

2008-05-09 Thread Dimitris Rizopoulos
try this: A <- matrix(rnorm(10*4), 10, 4) B <- matrix(rnorm(3*4), 3, 4) C <- matrix(rnorm(5*4), 5, 4) nrA <- nrow(A); nrB <- nrow(B); nrC <- nrow(C) ind <- as.matrix(expand.grid(1:nrA, 1:nrB, 1:nrC)) D <- rowSums(A[ind[, 1], ] * B[ind[, 2], ] * C[ind[, 3], ]) dim(D) <- c(nrA, nrB, nrC) D I hop

Re: [R] speeding up a special product of three arrays

2008-05-08 Thread Vincent Goulet
Le jeu. 8 mai à 17:20, Giuseppe Paleologo a écrit : I am struggling with R code optimization, a recurrent topic on this list. I have three arrays, say A, B and C, all having the same number of columns. I need to compute an array D whose generic element is D[i, j, k] <- sum_n A[i, n]*B[j,