Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: st_views passed on from Mata funtion to Mata function? pointers?


From   László Sándor <[email protected]>
To   [email protected]
Subject   Re: st: Re: st_views passed on from Mata funtion to Mata function? pointers?
Date   Wed, 11 Sep 2013 18:35:45 -0400

Still on this: Perhaps what matters is that -mata describe- thinks a
view is a real matrix. It is not a pointer or a special thing of its
own.

So probably the question is whether I can use it as an argument of a
function without immediately invoking copying.

And if I ever could, can I do that to achieve what is currently done
in these lines for XX (which "real matrix" should hold my view,
preferably without copying):

St = XX:*(v*J(1,cols(XX),1))
…
Ups = sqrt(quadcolsum(XX:^2)/nObs)*sqrt(quadcolsum(v:^2)/nObs)

Thanks!

On Wed, Sep 11, 2013 at 4:09 PM, László Sándor <[email protected]> wrote:
> FWIW, I now checked lars.ado, and there are operations on its st_view,
> even the one definitely avoidable with cross(). So presumably it is
> not much more efficient, at least memorywise.
>
> On Wed, Sep 11, 2013 at 2:43 PM, László Sándor <[email protected]> wrote:
>> Hi,
>> I am still struggling to make Christian Hansen's lassoShooting as fast
>> as possible. (See yesterday's email, code at
>> http://faculty.chicagobooth.edu/christian.hansen/research/)
>>
>> Even if I don't run out of memory (it is already scary if my data
>> takes more than 50% of physical memory so a copy runs out of it), I am
>> worried about lines of code when a view is passed onto a function that
>> expects a real matrix. A copy is made there, inefficiently?
>>
>> See e.g. the function
>>
>> real rowvector MakeLassoWeights(real colvector v , real matrix XX ,
>> real scalar hetero )
>> {
>> real rowvector Ups
>> nObs = rows(v)
>> if (hetero == 1) {
>> St = XX:*(v*J(1,cols(XX),1))
>> Ups = sqrt(quadcolsum((St):^2)/nObs)
>> }
>> else {
>> Ups = sqrt(quadcolsum(XX:^2)/nObs)*sqrt(quadcolsum(v:^2)/nObs)
>> }
>> return(Ups)
>> }
>>
>> And its use
>> Ups = MakeLassoWeights(v , data.Xs , hetero)
>>
>> Where data.Xs is a HUGE view (think of 3 million rows, 500 columns),
>> and even v is long. Btw, I still think v should made more efficiently:
>> v = data.y - data.Xs*betas.betaAll
>>
>> I find it stunning if Stata proudly sports a cross() function proudly
>> careful and efficient with views but does not do something similar for
>> other matrix multiplications.
>>
>> Is there really nothing to do about this?
>>
>> Or has anyone vetted LARS.ado much to see if their use of Mata is more
>> careful? (I cannot try the new code easily with the data.)
>>
>> Thanks,
>>
>> Laszlo
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index