简体   繁体   中英

How to find dependend functions in octave

I would like to identify all functions needed to run a specific function in octave. I need this to deploy an application written in Octave. While Matlab offers some tools to analyse a function on its dependencies, I could not find something similar for Octave.

Trying inmem as recommended in matlab does not produce the expected result:

> inmem

warning: the 'inmem' function is not yet implemented in Octave

Is there any other solution to this problem available?

First, let me point out that from your description, the matlab tool you're after is not inmem , but deprpt .

Secondly, while octave does not have a built-in tool for this, there is a number of ways to do so yourself. I have not tried these personally, so, ymmv.

1) Run your function while using the profiler, then inspect the functions used during the running process. As suggested in the octave archives: https://lists.gnu.org/archive/html/help-octave/2015-10/msg00135.html

2) There are some external tools on github that attempt just this, eg :

3) If I had to attack this myself, I would approach the problem as follows:

  • Parse and tokenise the m-file in question. (possibly also use binary checks like isvarname to further filter useless tokens before moving to the next step.)
  • For each token x, wrap a "help(x)" call to a try / catch block
  • Inspect the error, this will be one of:
    • "Invalid input" (ie token was not a function)
    • "Not found" (ie not a valid identifier etc)
    • "Not documented" (function exists but has no help string)
    • No error, in which case you stumbled upon a valid function call within the file
  • To further check if these are builtin functions or part of a loaded package, you could further parse the first line of the "help" output, which typically tells you where this function came from.

If the context for this is that you're trying to check if a matlab script will work on octave, one complication will be that typically packages that will be required on octave are not present in matlab code. Then again, if this is your goal, you should probably be using deprpt from matlab directly instead.

Good luck.


PS. I might add that the above is for creating a general tool etc. In terms of identifying dependencies in your own code, good software engineering practices go a long way towards providing maintenable code and easily resolving dependency problems for your users. Eg: -- clearly identifying required packages (which, unlike matlab, octave does anyway by requiring such packages to be visibly loaded in code) -- similarly, for custom dependencies, consider wrapping and providing these as packages / namespaces, rather than scattered files -- if packaging dependencies isn't possible, you can create tests / checks in your file that throw errors if necessary files are missing, or at least mention such dependencies in comments in the file itself, etc.

According to Octave Compatibility FAQ here ,

Q. inmem 
A. who -functions

You can use who -function . (Note: I have not tried yet.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM