From: Ian B. <ian...@gm...> - 2014-08-19 18:43:12
|
I experienced this exact issue, and while it wasn't the end of the world that it didn't directly output anything to screen (helpful for debugging), it would have been nice to have had the info that all was well. I think your proposed solution makes sense to me. I think it is a more common use case to have a function that returns something as compared to a void, unless you are passing by reference I guess. So making that the default seems logical to me. Ian On Tue, Aug 19, 2014 at 12:28 PM, Joel Andersson <j.a...@gm...> wrote: > Hi! > > I've finally managed to generate a (still incomplete) MATLAB interface to > our optimization framework CasADi! There is still a long way to go, but I > would already say thanks especially to Kris for great contributions to the > module! > > There is one thing I find particularly annoying when playing around with > CasADi from MATLAB; the fact that the "ans" argument in MATLAB is not > generated when you want it. > > A function such as arcsinh in CasADi is now wrapped as follows: > function varargout = function_name(varargin) > [varargout{1:nargout}] = > casadi_coreMATLAB_wrap(1532,'SX_arcsinh',self,varargin{:}); > end > > The problem is that if you type "asinh(x)" in MATLAB, nargout will be > zero, so nothing will be returned from the wrapper. To get an "ans" > argument, you need to replace "nargout" with 1, or more generally with > max(nargout,1): > function varargout = function_name(varargin) > [varargout{1:max(1,nargout)}] = > casadi_coreMATLAB_wrap(1532,'SX_arcsinh',self,varargin{:}); > end > > My proposed resolution is to always return at least one output whenever > any overload of the function has any outputs arguments. This means that if > you have two overloaded functions, one without outputs and another with > outputs, a dummy output (0-by-0 matrix) would be returned from the overload > with no outputs: > > void foo(double a); // no outputs, but dummy output [] returned > int foo(double a, double b); // outputs > > Does this sound reasonable? In a MATLAB script, you'd put a semicolon > after foo(a) anyway, preventing the creation of []. > > Best regards, > Joel > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Swig-devel mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-devel > > |