[R] crossprod(x) vs crossprod(x,x)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 21 13:59:02 CET 2006
On Tue, 21 Nov 2006, Duncan Murdoch wrote:
> On 11/21/2006 6:39 AM, Robin Hankin wrote:
>> Professor Ripley
>>
>> thanks for this.
>>
>> I see what you say about gc(). I'll try your looped test on my system:
>>
>>
>>
>> > x <- matrix(rnorm(3000000),ncol=3)
>> >
>> > system.time(for(i in 1:100){crossprod(x)})
>> [1] 7.931 20.420 28.619 0.000 0.000
>> > system.time(for(i in 1:100){crossprod(x)})
>> [1] 7.975 20.590 29.512 0.000 0.000
>> > system.time(for(i in 1:100){crossprod(x)})
>> [1] 8.003 20.641 30.160 0.000 0.000
>> > system.time(for(i in 1:100){crossprod(x,x)})
>> [1] 2.350 0.032 2.552 0.000 0.000
>> > system.time(for(i in 1:100){crossprod(x,x)})
>> [1] 2.330 0.015 2.333 0.000 0.000
>> > system.time(for(i in 1:100){crossprod(x,x)})
>> [1] 2.333 0.034 2.447 0.000 0.000
>> >
>>
>>
>>
>> How come my findings are qualitatively different from yours?
>
> Have you said what version of R you're using? I tried your code in an Intel
> Mac with R 2.4.0, and a Windows machine with R-devel, and saw what Brian saw.
> Maybe the Power Mac changes this, but that doesn't make a lot of sense. On
> the other hand, it could be that an older R release is making unnecessary
> copies in one case but not the other.
I think this indicates a problem with the BLAS on the PPC MacOS, which is
very different from the Intel one, AFAIK. Nothing in R itself could be
directly responsible for that system-time usage, since R is a user
process.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list