Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: how to access a matrix in a plugin


From   "Tom Boonen" <[email protected]>
To   [email protected]
Subject   Re: st: Re: how to access a matrix in a plugin
Date   Tue, 19 Sep 2006 15:02:35 -0400

Hi Kit,

thanks for your response.

I would love to avoid a plugin and just use Mata. But my estimator is
based on a nested optimization problem that requires quadratic
programming. Mata does not seem to offer a rountine for quadratic
programming (like quadprog() in mathlab (see
http://www-ccs.ucsd.edu/matlab/toolbox/optim/quadprog.html), or ipop()
in R). So I have to jump out to C to do the optimization, unless
somebody adds a quadratic programming routine to Mata.

Or does such routine exit in Mata?

Best,
Tom

On 9/19/06, Kit Baum <[email protected]> wrote:
sacrificial lamb

Don't. If you're using version 9.2, why not do this in Mata? C
plugins are cumbersome and platform-specific. The speed penalty of
Mata over C code is not likely to be very large on any decently fast
machine.

Kit


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


On Sep 17, 2006, at 2:33 AM, Tom wrote:

> I have problems to understand the ST_mat_el() and ST_mat_store()
> commands that pass matrices between Stata and my plugin. Here is my
> example program:
>
> program matrixAtoB
>         version 9.2
>  tempname inmat outmat
>  mat `inmat' = (1,2 \ 3,4)
>  mat `outmat ' = ([.,.] \ [.,.])
>  plugin call intooutmat, `inmat' `outmat'
>  matrix list `B'
> end
>
> The task is to pass both matrices (inmat and outmat) to the plugin.
> Then access inmat and get all of its contents into a C variable, then
> possibly do some computations with this variable in C and finally
> store the results (which happen to have the same dimensions as the
> inpmat) into outmat so Stata can access the output of my computation.
>
> For now, I can do this with a single elment of inmat:
>
> intooutmat.c :
>
> #include "stplugin.h"
>
> STDLL stata_call(int argc, char *argv[])
>         {
>          ST_double z ;
>
>                 SF_mat_el( argv[0] , 1 , 2 , &z ) ;
>                   SF_mat_store( argv[1] , 1 , 2 , z ) ;
>
>            return(0) ;
>        }
>
> This takes the element from the first row second column of inmat, puts
> it into z, and then puts z into the first row second column of outmat.
> But how can I access the WHOLE matrix inmat in the plugin (not just
> element by element) and pout it into outmat?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index