On Wed, 1 Oct 2014, Riccardo (Jack) Lucchetti wrote:
 On Wed, 1 Oct 2014, Sven Schreiber wrote:
> Hi,
> 
> when I'm feeling really nerdy I try to use qform() instead of directly
> writing the matrix product Z'Z. But since qform() is of course actually
> for x*A*x', I have to insert an identity matrix as the second argument,
> like this:
> qform(x', I(cols(x)))
> 
> So two questions:
> 1) Is it actually really faster to use qform() for this kind of inner
> product where A is the identity matrix? (I know the speed difference
> won't be noticeable anyway, but in theory.)
 Absolutely not :) Try this: 
[script showing that plain x'x is _much_ faster than qform(x',I(dim))]
 I had a look at the source and it occurred to me that we may try to 
 intercept expressions like x'x and apply a specialised algorithm (which 
 should be somewhat faster) for those: Allin, correct me if I'm wrong, 
 but we could check for "l" and "r" for being the same guy in the
B_TRMUL 
 branch of the big "switch" inside eval (line 10501 of geneval.c) and 
 then, if so, simply call matrix_multiply_self_transpose(). No? 
gretl_matrix_multiply_mod() already checks for a identical to b and
calls matrix_multiply_self_transpose() if it's appropriate.
In general, doing tricksy things to try to speed up matrix operations in 
gretl is likely to slow them down. We've spent a lot of time trying to get 
things working optimally when coded "naturally".
Allin