Statalist The Stata Listserver


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

Re: st: Mata functions not found in compiled Mata library


From   Ulrich Kohler <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Mata functions not found in compiled Mata library
Date   Tue, 27 Jun 2006 09:57:53 +0200

Thank you Bill. Your answer points us to the solution. It was really simple: 
We have not saved two compiled structure definitions of our library. Now that 
we have proceeded as shown in -help m2_struct##tagsavdef- everything works 
out fine. 

Sorry for eating your time...

Uli

William Gould, Stata wrote:
> Uli Kohler <kohler@wz-berlin.de> and Magda Luniak <luniak@wz-berlin.de>
> are having problems getting their code to work after putting it in a
> .mlib library.
>
> They have a do-file which compiles all the code,
>
>         . do lsq.mata
>
> and I assume file lsq.mata also creates the library.  The library, they
> report, is named lsq.mata.
>
> They have an ado file, sqom.ado, which works just fine right after
> -do lsq.mata-,
>
>
>         . do lsq.mata
>
>         . sqom
>         <expected output appears>
>
> but later, or after a -clear-, if they run -sqom-, they get an error
> message,
>
>         . sqom
>           <istmt>:  3499  sqomref() not found
>         r(3499);
>
> So what could be going on?  There are two possibilities,
>
>     1.  The have not included everything in the library that they
>         thought they did (in particularly, they left out -sqomref()-, or
>
>     2.  The computer is not even looking in the library lsq.mata.
>
> I rather like #2.
>
> Where is the file lsq.mata?  That is, in which directdory?  When was it
> put there?  Even if lsq.mata is located in some official directory
> (such as PERSONAL), it it was put there after Stata was already
> running, Mata would not know to look there, and in that case, you must type
>
>         . mata mlib index
>
> Don't do that yet, though.  First type,
>
>         . mata mlib query
>
> to find out what libraries Mata is searching.
>
>
> Mata's library search
> ---------------------
>
> Libraries in Mata start with the letter "l" (el) and end in ".mlib".
> Unlike with ado-files, however, Mata does not search for them any time
> it cannot find something it needs.
>
> Instead, Mata forms a list of the libraries.  It does that the first
> time -mata- is invoked in a Stata session.  Mata also does it whenever
> you type
>
>        : mata mlib index
>
> to the Mata prompt.
> I do not recommend you put -mata: mata mlib index- in your ado-file,
> because the command can take a long time to run, especially on laptops.
>
> Anyway, when I type -mata mlib query- on my computer, here is the result:
>         : mata mlib query
>
>         .mlib libraries to be searched are
>             lmatabase;lmataado
>
> I get the same result if I type -mata mlib index- because I only have
> two libraries that came with Mata on my computer.
>
> When Uli or Magda type -mata mlib query-, they hope to see something like
>
>         : mata mlib query
>
>         .mlib libraries to be searched are
>             lmatabase;lmataado;lsqom
>
> If they do not, then Mata is not looking there.  Assuming the library is
> around where Mata can find it, typing
>
>         : mata mlib index
>
>         .mlib libraries to be searched are now
>             lmatabase;lmataado;lsqom
>
> should fix the problem.  Assuming the library is in some official place
> (such as PERSONAL), the next time they want to use -sqom-, they will not
> have to type -mata mlib index- because the library will be found
> automatically the first time Mata is invoked.
>
> Anyway, the unfound library is my favorite explanation right now.
> I especially like it because it might explain the apparent random
> behavior they described.  Imagine they have old versions of some routines
> laying around in .o files.  Not finding the library, Mata might latch onto
> those.
>
> My second favorite explanation is that the library does not contain
> everything Uli and Magda think it contains, and I'll mix that with
> old .o files laying around.  The next time Uli or Magda get one of the
> longer error messages, such as
>
>         . sqom
>           hashing():  3499  elemlist() not found
>           sqomref():     -  function returned error
>           <istmt>:        -  function returned error
>         r(3499);
>
> I suggest they explore such how -sqomref()- and -hashing()- were found,
> which they can do by typing
>
> 	. mata: mata which sqomref()r
>
> 	. mata: mata which hashing()
>
> They might be in for a surprise.
>
> When I create a Mata library, here is how I organize my file:
>
>
>       ----------------------------- example.mata --- BEGIN ---
>       version 9.2
>
>       clear
>
>       capture erase "`c(sysdir_personal)'/lexample.mlib"
>
>       // ---------------------------- code begins
>       mata:
>
>       function ...
>       {
>           ...
>       }
>
>       ...
>       end
>       // ---------------------------- code ends
>
>       mata:
>       mata mlib create lexample,        dir(PERSONAL)
>       mata mlib add    lexample  *(),   dir(PERSONAL)
>       mata describe using lexample
>       end
>       ----------------------------- example.mata --- END ---
>
> This way, I know I leave nothing out.
>
> In the example above, I create the library in my PERSONAL directory.
>
>
> -- Bill
> wgould@stata.com
> *
> *   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/

-- 
kohler@wz-berlin.de
+49 (030) 25491-361
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index