Moreno I. Coco <M.I.Coco <at> sms.ed.ac.uk> writes:
[snip snip snip] > > So, I have written my own spdiags function (below); following > also a suggestion in an old, and perhaps unique post, about > this issue. > > It works only for square matrices (that's my need), however I > have a couple of issues, mainly related to computational > efficiency: > > 1) if I use it with a sparseMatrix, it throws a tedious warning > "<sparse>[ <logic> ] : .M.sub.i.logical() maybe inefficient"; > can I suppress this warning somehow, this is slowing the computation > very radically; quick answer: use suppressMessages() > > 2) I can go around this problem by translating a sparseMatrix back > into a logical matrix before I run spdiags on it. However, the loop > gets very slow for large matrices (e.g., 2000x2000), which is the > kind of matrices I have to handle. If you look in the code, > I have placed a system.time() where the code is slowing down, and > it takes about: > I'm not quite sure how to do it, but I think you should look at the ?band function in Matrix. In combination with diag() of a suitably truncated matrix, you should be able to extract bands of sparse matrices efficiently ... ______________________________________________ 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.