Hi there,
struct2local.m is a function that make local variables out of the fields of a structure. This function creates a problem in some circumstances (details below) at least with Matlab R2010a.
I had replaced it in a previous commit, but I should have sent a message to this list rather than relay only on the commit message in GIT.
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
In any case, we can't use struct2local and it is safer to unroll the fieldnames by hand. In addition, we may create only the local variables actually needed by the function rather than all the fields of the structure.
All the best,
Michel
-------- Original Message -------- Subject: Re: commits Date: Fri, 09 Apr 2010 11:38:51 +0200 From: Sébastien Villemot sebastien.villemot@ens.fr To: Marco Ratto marco.ratto@jrc.ec.europa.eu CC: Stéphane Adjemian stephane.adjemian@gmail.com, Michel Juillard michel.juillard@ens.fr References: 4BBDF623.3060701@jrc.ec.europa.eu
Hi Marco,
Le jeudi 08 avril 2010 à 17:28 +0200, Marco Ratto a écrit :
I did a number of commits related to parallel dynare.
Thanks for that.
I have a problem with your commit 320266412... dated 08 april 2010 17:15:15: it reverts to the use of struct2local(), which was removed by Michel in his commit 2679e190e8... dated 02 april 2010 21:37:43.
It seems that Michel had problems with struct2local() on MATLAB R2010a, so he purposedly removed the use of that function.
I guess Michel and you have to find an agreement on what is the best solution there.
Le samedi 10 avril 2010 à 11:39 +0200, Michel Juillard a écrit :
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
I can reproduce the problem on MATLAB 7.0, 7.4 and 7.9. So this is not specific to one version.
This behavior seems indeed in contradiction with the precedence rules: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-60956....
Note that if we define "run_smoother=1" directly in the file test_s2l.m, then the "if" statement uses the local variable and not the function: in that case the precedence rules are correctly applied.
So it looks like the precedence rules are not respected only when the variable is assigned via "assignin('caller'...)" (as it is in struct2local.m).
This is very strange, it looks like a bug, but since it is present in many versions of MATLAB, we must take it as normal behavior of MATLAB.
Thanks a lot for checking. I noted for some other routine that when the variable is not explicitly defined in the function, the precedence rule is not followed. It may be also worth trying to find a way to have this precedence rule with assign in
best Marco
Sébastien Villemot wrote:
Le samedi 10 avril 2010 à 11:39 +0200, Michel Juillard a écrit :
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
I can reproduce the problem on MATLAB 7.0, 7.4 and 7.9. So this is not specific to one version.
This behavior seems indeed in contradiction with the precedence rules: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-60956....
Note that if we define "run_smoother=1" directly in the file test_s2l.m, then the "if" statement uses the local variable and not the function: in that case the precedence rules are correctly applied.
So it looks like the precedence rules are not respected only when the variable is assigned via "assignin('caller'...)" (as it is in struct2local.m).
This is very strange, it looks like a bug, but since it is present in many versions of MATLAB, we must take it as normal behavior of MATLAB.
OK, but I suggest that for the time being we refrain from using struct2local
Cheers
Michel
Marco Ratto wrote:
Thanks a lot for checking. I noted for some other routine that when the variable is not explicitly defined in the function, the precedence rule is not followed. It may be also worth trying to find a way to have this precedence rule with assign in
best Marco
Sébastien Villemot wrote:
Le samedi 10 avril 2010 à 11:39 +0200, Michel Juillard a écrit :
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
I can reproduce the problem on MATLAB 7.0, 7.4 and 7.9. So this is not specific to one version.
This behavior seems indeed in contradiction with the precedence rules: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-60956....
Note that if we define "run_smoother=1" directly in the file test_s2l.m, then the "if" statement uses the local variable and not the function: in that case the precedence rules are correctly applied.
So it looks like the precedence rules are not respected only when the variable is assigned via "assignin('caller'...)" (as it is in struct2local.m).
This is very strange, it looks like a bug, but since it is present in many versions of MATLAB, we must take it as normal behavior of MATLAB.
OK, we will do this on all our parallel functions .... best Marco
Michel Juillard wrote:
OK, but I suggest that for the time being we refrain from using struct2local
Cheers
Michel
Marco Ratto wrote:
Thanks a lot for checking. I noted for some other routine that when the variable is not explicitly defined in the function, the precedence rule is not followed. It may be also worth trying to find a way to have this precedence rule with assign in
best Marco
Sébastien Villemot wrote:
Le samedi 10 avril 2010 à 11:39 +0200, Michel Juillard a écrit :
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
I can reproduce the problem on MATLAB 7.0, 7.4 and 7.9. So this is not specific to one version.
This behavior seems indeed in contradiction with the precedence rules: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-60956....
Note that if we define "run_smoother=1" directly in the file test_s2l.m, then the "if" statement uses the local variable and not the function: in that case the precedence rules are correctly applied.
So it looks like the precedence rules are not respected only when the variable is assigned via "assignin('caller'...)" (as it is in struct2local.m).
This is very strange, it looks like a bug, but since it is present in many versions of MATLAB, we must take it as normal behavior of MATLAB.
Dev mailing list Dev@dynare.org https://www.dynare.org/cgi-bin/mailman/listinfo/dev
Thanks, Marco
Michel
Marco Ratto wrote:
OK, we will do this on all our parallel functions .... best Marco
Michel Juillard wrote:
OK, but I suggest that for the time being we refrain from using struct2local
Cheers
Michel
Marco Ratto wrote:
Thanks a lot for checking. I noted for some other routine that when the variable is not explicitly defined in the function, the precedence rule is not followed. It may be also worth trying to find a way to have this precedence rule with assign in
best Marco
Sébastien Villemot wrote:
Le samedi 10 avril 2010 à 11:39 +0200, Michel Juillard a écrit :
As illustrated with the 2 functions attached, if one of the fieldname is also the name of a function present in the path, an 'if' statement calls the function instead of the local variable.
This is in contradiction with the priorities for searching symbol names stated by Matlab documentation and it looks like a Matlab bug, maybe it affects only R2010a, but I didn't get a chance to try with other Matlab versions.
I can reproduce the problem on MATLAB 7.0, 7.4 and 7.9. So this is not specific to one version.
This behavior seems indeed in contradiction with the precedence rules: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f10-60956....
Note that if we define "run_smoother=1" directly in the file test_s2l.m, then the "if" statement uses the local variable and not the function: in that case the precedence rules are correctly applied.
So it looks like the precedence rules are not respected only when the variable is assigned via "assignin('caller'...)" (as it is in struct2local.m).
This is very strange, it looks like a bug, but since it is present in many versions of MATLAB, we must take it as normal behavior of MATLAB.
Dev mailing list Dev@dynare.org https://www.dynare.org/cgi-bin/mailman/listinfo/dev
Le lundi 12 avril 2010 à 15:34 +0200, Marco Ratto a écrit :
OK, we will do this on all our parallel functions ....
Please, don't forget to also do it on the stable 4.1 branch, for the future 4.1.2 release (since I think that struct2local is also used in the 4.1).
Best
Hi All,
it seems that the problem is not a bug but an explicit matlab policy:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f0-38052.h...
so struct2local seems a non-robust utility best Marco
Sébastien Villemot wrote:
Le lundi 12 avril 2010 à 15:34 +0200, Marco Ratto a écrit :
OK, we will do this on all our parallel functions ....
Please, don't forget to also do it on the stable 4.1 branch, for the future 4.1.2 release (since I think that struct2local is also used in the 4.1).
Best