-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: enhance variable type guess when matlab variable are explicitly declared #85
Comments
I intend to work on Matlab2cpp's ability to get a more automatic way of getting the variable types. I was thinking that the translator could create some new Matlab files (from the original Matlab files), which are the similar to the original Matlab files, but also include a function which dumps the types of the workspace variables (modified whos function) original matlab file:
modified matlab file
By running this modified Matlab code in Matlab/Octave I hope to get the data types. The whos_f function write a file like this:
I ran the code above in the command window. When a script is used "command window" should be the name of the script file and also the name of the function should be included. From this I hope to extract the file, function and the variable types. For a we have: a, 1x2, double, 0, 0 which makes it a rowvec, and the second zero indicate that it should be a double type. b and c can be integer or floating point (hard to tell because they are declared as integer but could be used as double later). Declaring b = 3.0 doesn't change this because the way the value is found to be an integer is by converting it to and integer and comparing it to the value before conversion. So the idea is not perfect. Also variables declared inside for and if statements go out of scope and disappear before the whos_f function dumps the variable information. As for your idea, I realize I have to write some code for handling save and load. In Matlab you can save and load workspace variables with save("file.mat") and load("file.mat"). In Armadillo it seems you can only load one variable at a time, see Armadillo documentation. So there are things from Matlab that don't carry over to C++ with Armadillo. So a possible translation of load from Matlab to C++ with Armadillo
Also how to translate cells in Matlab to C++ is not implemented and I have no clue how to do that. |
Very interesting approach. Please see some comments below:
|
If you run this example, you can see that the else part of the if statement is not entered. Therefore the whos function have no information about the c variable. 3-4) I will look into this next week, as I will more time then. |
Hi,
I am trying to automatize code conversion from matlab/octave to cpp. Let me put my case in context:
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:
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:
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.
The text was updated successfully, but these errors were encountered: