Inconsistent array notation in Java interface generated by MATLAB Compiler SDK?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
FM
el 28 de Oct. de 2020
To call Matlab functions from Java, MATLAB's Compiler SDK generates functions with the following signatures.
/* mlx interface - List version*/
public void mysum(List lhs, List rhs)
throws MWException
/* mlx interface - Array version*/
public void mysum(Object[] lhs, Object[] rhs)
throws MWException
/* standard interface - no inputs */
public Object[] mysum(int nargout)
throws MWException
/* standard interface - variable inputs */
public Object[] mysum(int nargout, Object varargin)
throws MWException
Here, `mlx` seems to refer to an signature convention, and speculatively, the reasons for the name seem to be no longer relevant in the current context.
Here is an example invocation from within function getsum:
public double getsum(double[] vals) throws MWException
{
myclass cls = null; // Class containing the generated functions
Object[] x = {vals};
Object[] y = null;
try
{
cls = new myclass();
y = cls.mysum(1, x);
...snip...
"[O]bject array [x] of length 1 is created and initialized with a reference to the supplied double array. This argument is passed to the mysum method. The result is known to be a scalar double..." The invocation matches 4th and last signature above.
Why is argument x of type Object array (Object[] x) when the 4th signature shows a scalar Object (Object varargin)?
I realize that an array itself (i.e., Object[] x) is also an Object, but if that is how the prototypes are to be interpretted, then why is the array nature of the arguments explicit in the 2nd prototype above (Object[] rhs) but not the 4th prototype (Object varargin)?
0 comentarios
Respuesta aceptada
Todd Flanagan
el 29 de Oct. de 2020
You are correct that mlx is a convention. It refers to a c style interface that is familiar to people using other c-style MATLAB interfaces.
I don't know the specifics of why the particular signature was chosen and what the design trade offs were, but the signature does expect and Object [] array to be passed in as Object per the documentation.
In all cases, the varargin argument is passed as type Object. This lets you provide any number of inputs in the form of an array of Object, that is Object[], and the contents of this array are passed to the compiled MATLAB function in the order in which they appear in the array.
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Call Java from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!