Message-ID: <1328805536105-4373437.post@n4.nabble.com>
Date: 2012-02-09T16:38:56Z
From: Ally
Subject: Row-wise kronecker product with Matrix package
I'm trying to calculate the row-wise kronecker product A \Box B of two
sparse matrices A and B, and am struggling to find a quick way to do this
that takes advantage of sparseness. I thought a good idea would be to use
"rep" to construct 2 matrices of the same dimension of the end product, and
multiply these two together:
library(Matrix)
A<-Matrix(c(1,0,0,0,0,1,2,0), 2, 4)
B<-Matrix(c(2,5,0,0,0,1,0,0,0,0), 2, 5)
A[, rep(seq(ncol(A)), each = ncol(B))] * B[, rep(seq(ncol(B)),ncol(A))]
This works, but for much larger problems is slow (compared to keeping A and
B dense). I was wondering why this happens, and whether there might be a
way around it?
Thanks in advance for any advice,
Alastair
--
View this message in context: http://r.789695.n4.nabble.com/Row-wise-kronecker-product-with-Matrix-package-tp4373437p4373437.html
Sent from the R help mailing list archive at Nabble.com.