Joel Andersson
2016-06-14 18:15:41 UTC
Hi all,
If you are familiar with Octave, you know that it's designed to be syntax
compatible with MATLAB. This doesn't apply to the internal API, which is
why it has never been an option to use SWIG's Octave module for MATLAB.
SWIG's Octave module relies on Octave's internal C++ API which has no
MATLAB counterpart. The MATLAB module that we've been working on uses a
different design, relying on MATLAB's support for object oriented
programming and builds up a class hierarchy in MATLAB that serves to
redirect all function calls to a single entry-point MEX function.
Now, I was curious if it would be possible to use the MATLAB module working
from Octave, given that Octave now supports both MEX and MATLAB-style
object oriented programming. And after a bit of work it turned out that the
answer is yes! I had to modify the MATLAB module a bit - (cf.
https://github.com/jaeandersson/swig/tree/octave_new and
https://github.com/jaeandersson/swig/issues/67) - to work around some
MATLAB features that are not (yet) supported by Octave, but after that I
managed to compile and run SWIG's "class" example as well as the generated
MATLAB interface to CasADi, which uses a large subset of SWIG.
I find this exciting for a number of reasons:
1. By using the same module for both Octave and MATLAB, there is no need to
duplicate the work to e.g. write typemaps and to implement
language-specific features for both Octave and MATLAB. We have successfully
generated a proof-of-concept Octave interface to CasADi using SWIG's Octave
module, but to implement all these language-specific things has been a
daunting task for a (compared to MATLAB) relatively small number of users.
By making the modules MATLAB/Octave bilingual, one can be pretty sure that
if it works for one, it will work for the other.
2. I would argue that the MATLAB module offers a much more natural user
syntax than the Octave module. SWIG's Octave module was written at a time
when Octave didn't support object oriented programming, but manages to work
around this fact. But it feels weird e.g. to have classes be variables in
Octave and not being able to call "help" for a class. The MATLAB module, on
the other hand, uses Octave's newly added support for OOP.
3. If the MATLAB module is Octave compatible, we can use Octave for testing
it e.g. on Travis. And you won't need to obtain a MATLAB license to run the
test suite.
Thoughts, comments?
Best regards,
Joel
If you are familiar with Octave, you know that it's designed to be syntax
compatible with MATLAB. This doesn't apply to the internal API, which is
why it has never been an option to use SWIG's Octave module for MATLAB.
SWIG's Octave module relies on Octave's internal C++ API which has no
MATLAB counterpart. The MATLAB module that we've been working on uses a
different design, relying on MATLAB's support for object oriented
programming and builds up a class hierarchy in MATLAB that serves to
redirect all function calls to a single entry-point MEX function.
Now, I was curious if it would be possible to use the MATLAB module working
from Octave, given that Octave now supports both MEX and MATLAB-style
object oriented programming. And after a bit of work it turned out that the
answer is yes! I had to modify the MATLAB module a bit - (cf.
https://github.com/jaeandersson/swig/tree/octave_new and
https://github.com/jaeandersson/swig/issues/67) - to work around some
MATLAB features that are not (yet) supported by Octave, but after that I
managed to compile and run SWIG's "class" example as well as the generated
MATLAB interface to CasADi, which uses a large subset of SWIG.
I find this exciting for a number of reasons:
1. By using the same module for both Octave and MATLAB, there is no need to
duplicate the work to e.g. write typemaps and to implement
language-specific features for both Octave and MATLAB. We have successfully
generated a proof-of-concept Octave interface to CasADi using SWIG's Octave
module, but to implement all these language-specific things has been a
daunting task for a (compared to MATLAB) relatively small number of users.
By making the modules MATLAB/Octave bilingual, one can be pretty sure that
if it works for one, it will work for the other.
2. I would argue that the MATLAB module offers a much more natural user
syntax than the Octave module. SWIG's Octave module was written at a time
when Octave didn't support object oriented programming, but manages to work
around this fact. But it feels weird e.g. to have classes be variables in
Octave and not being able to call "help" for a class. The MATLAB module, on
the other hand, uses Octave's newly added support for OOP.
3. If the MATLAB module is Octave compatible, we can use Octave for testing
it e.g. on Travis. And you won't need to obtain a MATLAB license to run the
test suite.
Thoughts, comments?
Best regards,
Joel