Re: [R] fast matrix update

From: Duncan Murdoch <>
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 mailing list PLEASE do read the posting guide! 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