Function masking / precedence of functions

I have a question related functions and their precedence for the following example:
Assume I have a function (calling it function_main) which calls several other functions (function_1...function_n). The called functions are mainly very generic, e.g. Matlab intrinsic functions. I have started to translate the functions for my use cases into mex-functions calling them function_1_mex etc.. The translation does not cover the generic implementation, but only the use case in function_main. For those I can Unit Test them against their original Matlab implementation for exactly that usage. But the function_main is still under development and I want to test if new use cases appear compared to the current status of the translation. Thus I want to add an additional Unit Test which does the following:
Mask function_1 with function_1_mex and call the original function_main (that would otherwise not call any of my mex functions and see if it fails compared to the Matlab-only code, thus showing me that I now miss other use cases. In pseudo C-code I'd like something like this:
#define function_1(params[]) function_1_mex(params[]) // masking original function_1 for one call of function_main
function_main();
#undefined function_1
Is something comparable to that possible in Matlab? Maybe by changing the names of function_#_mex to function_# and changing the precedence for one call?

 Respuesta aceptada

James Tursa
James Tursa el 26 de Mayo de 2016

0 votos

You could try the following: Run your code from a special directory that does not contain any of the functions you want to mask. Then for each function you want to mask, create an m-file of that name that actually calls the mex version of that function. This m-file in the current folder will mask any m-files that are in other directories on the path. This scheme will not work if the functions you want to mask are nested functions or local functions inside one of your m-files.

2 comentarios

Michael Eschey
Michael Eschey el 31 de Mayo de 2016
Thanks this will work. With a nice script to set the paths between development and Unit Testing it is also not an annoying work around, thanks a lot.
Michael Eschey
Michael Eschey el 31 de Mayo de 2016
tested this now, to mask Matlab built-in functions one needs to use the private folder, otherwise Matlab will prefer the built-in function still.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 24 de Mayo de 2016

Comentada:

el 31 de Mayo de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by