I have the following matrix operation

A %*% B %*% A

Where these matrices have the following dimensions and class attributes.

> dim(A)
[1] 5764 5764

> class(A)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

> dim(B)
[1] 5764 5764

> class(B)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

Now, when I do just the first part of the operation, A %*% B, this happens 
rather quickly as you can see below.

> system.time(s1 <- A %*% B)
   user  system elapsed
   3.49    0.36    3.87

> dim(s1)
[1] 5764 5764

> class(s1)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

But now, when I do the second part

s1 %*% A

R essentially hangs up and the computation doesn't complete. I am not quite 
sure why this happens since both s1 and A are of the same class and dimensions 
as those used in the operation A %*% B. I would intuitively expect computing 
time to be equivalent. But, it clearly is not.

Am I missing something obvious here or is there possibly a better way to do 
this computation?

Harold


> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lme4_0.999375-38   Matrix_0.999375-46 lattice_0.19-13

loaded via a namespace (and not attached):
[1] grid_2.12.2   nlme_3.1-98   stats4_2.12.2

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to