Re: [R] fast matrix update

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 18 May 2005 - 20:07:12 EST

vincent wrote:
> Hello,
> I use extensively m[i0:i1,j0:j1] = ... to update matrices parts.
> This writing is very convenient, but, since I'm doing this
> calculus many many times, I would like to know if there is a way
> (a hope ?) to do the same operation faster ?

It tends to be faster to use vector indexing rather than matrix indexing, so if you can calculate which entries correspond to the block you want to replace you might find this is faster:

block <- [ some calculation here, e.g. i0:i1 if j0 = j1 = 1 ] m[block] <- ...

Of course, the calculation involved in the general case is ugly and could be slow. If this is really a crucial bottleneck to your calculation, I'd suggest skipping over that optimization and redoing the function in C or Fortran.

Duncan Murdoch



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 18 20:35:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:50 EST