Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: inline mata vs mo/mlib?


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: inline mata vs mo/mlib?
Date   Wed, 10 Aug 2005 16:42:25 +0100

Thanks to Bill for his very helpful advice.

While still on the subject of good Mata practice, -[M-1] naming- recommends that we name our functions with long names and do not choose words in the English language dictionary, to reduce the probability of name clashes with StataCorp and/or other users. I have just written a pair of Mata functions named _balancedtree() and balancedtree(), which I intend to distribute in due course. Should I rename them?

Roger


At 14:21 10/08/2005, Bill wrote:

Kit Baum <[email protected]> asked,

> [...] Say that you
> have an ado-file that calls one (or several) of your own mata
> functions. You could place those functions in-line in the ado-file,
> or you could compile them into .mo and put them into an .mlib.
>
> is there any real downside to distributing a single ado-file
> containing the mata functions inline versus distributing the .ado
> and .mlib (and presumably the .mata if you want to expose the code)?
> The inline code will be compiled when loaded, but once per session.

I recently wrote an ado file for which the ado part was 17 lines and
the Mata part 491.  I recommend the all-ado construction if

    1.  there is not too much Mata code (say more than 2,000 lines),

    2.  you are willing to make public the Mata part, and

    3.  The Mata routines are not general-purpose functions that
        you will want to call from other ado-files.

Concerning (1), remember compiles occur only when the ado-file is loaded.
Concerning the 2,000-line guideline, I should mention that lots of short
functions compile very quickly, whereas one 2,000-line function takes
longer.  The compile time for a single function increases quadratically with
the number of lines in the function.

-- Bill
[email protected]

--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
Division of Asthma, Allergy and Lung Biology
King's College London

5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
  or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://phs.kcl.ac.uk/rogernewson/

Opinions expressed are those of the author, not the institution.

*
*   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