Description
Hi,
I am trying to automatize code conversion from matlab/octave to cpp. Let me put my case in context:
- imagine that there is a master code in matlab/octave, that calls another matlab/octave function (worker), which takes most of the execution time.
- the worker code may actually vary in successive invocations of the master (although the basic structure of the worker remains the same). Therefore the master does not only execute the worker, but it also checks first if the worker needs to be regenerated, which is automatized.
Now I want the master to use matlab2cpp to automatize the creation of a worker in cpp from the worker that is written in matlab/octave.
One of the main issues for this is to get the proper types of some variables. I know that they can be set manually, but sometimes they can also be inferred by using the -s argument.
So, this feature request is about enhancing the guess of variables that are explicitly declared in matlab/octave, as this would very much ease the automatic conversion.
To see this better please consider the following example:
% i = int64(1);
% x = randn;
% str = 'hello';
% v = randn(10,1);
% M = randn(10,2);
% s.i = i;
% s.x = x;
% s.str = str;
% s.v = v;
% s.M = M;
% c{1} = i;
% c{2} = x;
% c{3} = str;
% c{4} = v;
% c{5} = M;
% save('test_types');
load('test_types');
i = int64(i);
x = double(x);
str = char(str);
v = double(v);
M = double(M);
s = struct(s);
c = cell(c);
Now Imagine that I first created a test_types.mat using the piece of code that is commented above and then I run this uncommented code. In matlab/octave the variables i to c are explicitly declared. My request is about using that information during the conversion to cpp, which doesn't happen so far, please see below:
// Automatically translated using Matlab2cpp 0.5 on 2016-04-28 16:15:13
#include <armadillo>
using namespace arma ;
int main(int argc, char** argv)
{
TYPE M, c, i, s, str, v, x ;
load("test_types") ;
i = int64(i) ;
x = double(x) ;
str = char(str) ;
v = double(v) ;
M = double(M) ;
s = struct(s) ;
c = cell(c) ;
return 0 ;
}
If you would think positively about implementing this, please let me know if I could be of any help on this.
A side note:
I realize that the proper types for v and M are more difficult to convert as they would be guessed as double instead of vec and mat. For this I would be more explicit during the creation of the matlab/octave worker, to initialize those to the proper dimensions, before they take the particular valeus from the load function.
Still in this case, having this enhanced guessing would be highly beneficial as it would be able to distinguish between vec (v = double(v);) and ivec (v = int64(v);), and similary between mat and imat.