Need tests for new MEX interface functions run in recent version of Matlab

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Need tests for new MEX interface functions run in recent version of Matlab

John W. Eaton
Administrator
I'm looking at adding the following new MEX interface functions to Octave

    mxGetDoubles  mxGetSingles
    mxSetDoubles  mxSetSingles

    mxGetInt8s  mxGetInt16s  mxGetInt32s  mxGetInt64s
    mxSetInt8s  mxSetInt16s  mxSetInt32s  mxSetInt64s

    mxGetUint8s  mxGetUint16s  mxGetUint32s  mxGetUint64s
    mxSetUint8s  mxSetUint16s  mxSetUint32s  mxSetUint

To do that, I could use help understanding how they behave and how the
older functions like mxGetPr behave with Matlab 2018a and newer versions
that use interleaved complex data.

1. Do the new functions like mxGetDoubles throw errors if the input
mxArray object does not match the expected type or do they return some
undefined result?

2. If using the -r2018a option when compiling mex files so that they use
the interleaved complex data interface, does the mxGetPr function return
alternating real/imag values for a complex input array or does it throw
an error?

Could someone try the following with the attached mextst.c file?  You'll
need Matlab 2018a or a newer version.

If compiled with mex -r2018a and called with

   mextst ([1, 2])

I expect the output to be something like

   mxGetPr:       1.00000, 2.00000
   mxGetDoubles:  1.00000, 2.00000

If called with

   mextst ([1+i, 2+2i])

Does mxGetPr throw an error because the type is wrong?  If not, what
does it display?

Does mxGetDoubles fail with an error because the type of the argument is
wrong?  If not, what does it display?

jwe

mextst.c (321 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Need tests for new MEX interface functions run in recent version of Matlab

John W. Eaton
Administrator
On 1/14/20 4:50 PM, John W. Eaton wrote:

> If called with
>
>    mextst ([1+i, 2+2i])
>
> Does mxGetPr throw an error because the type is wrong?  If not, what
> does it display?
>
> Does mxGetDoubles fail with an error because the type of the argument is
> wrong?  If not, what does it display?

I would still like confirmation, but I now expect both of these calls to
throw errors as the current documentation for mxGetPr says that is what
it will do when called with something other than a real-valued double array.

jwe




Reply | Threaded
Open this post in threaded view
|

Re: Need tests for new MEX interface functions run in recent version of Matlab

siko1056
In reply to this post by John W. Eaton
On 1/15/20 7:50 AM, John W. Eaton wrote:

> I'm looking at adding the following new MEX interface functions to Octave
>
>    mxGetDoubles  mxGetSingles
>    mxSetDoubles  mxSetSingles
>
>    mxGetInt8s  mxGetInt16s  mxGetInt32s  mxGetInt64s
>    mxSetInt8s  mxSetInt16s  mxSetInt32s  mxSetInt64s
>
>    mxGetUint8s  mxGetUint16s  mxGetUint32s  mxGetUint64s
>    mxSetUint8s  mxSetUint16s  mxSetUint32s  mxSetUint
>
> To do that, I could use help understanding how they behave and how the
> older functions like mxGetPr behave with Matlab 2018a and newer versions
> that use interleaved complex data.
>
> 1. Do the new functions like mxGetDoubles throw errors if the input
> mxArray object does not match the expected type or do they return some
> undefined result?
>
> 2. If using the -r2018a option when compiling mex files so that they use
> the interleaved complex data interface, does the mxGetPr function return
> alternating real/imag values for a complex input array or does it throw
> an error?
>
> Could someone try the following with the attached mextst.c file?  You'll
> need Matlab 2018a or a newer version.
>
> If compiled with mex -r2018a and called with
>
>   mextst ([1, 2])
>
> I expect the output to be something like
>
>   mxGetPr:       1.00000, 2.00000
>   mxGetDoubles:  1.00000, 2.00000
>
> If called with
>
>   mextst ([1+i, 2+2i])
>
> Does mxGetPr throw an error because the type is wrong?  If not, what
> does it display?
>
> Does mxGetDoubles fail with an error because the type of the argument is
> wrong?  If not, what does it display?
>
> jwe

>> ver
-------------------------------------------------------------------------------------------------------
MATLAB Version: 9.6.0.1072779 (R2019a)
MATLAB License Number: sqrt(-42)
Operating System: Linux 4.12.14-lp151.28.36-default #1 SMP Fri Dec 6
13:50:27 UTC 2019 (8f4a495) x86_64
Java Version: Java 1.8.0_181-b13 with Oracle Corporation Java
HotSpot(TM) 64-Bit Server VM mixed mode
-------------------------------------------------------------------------------------------------------

>> mex -r2018a mextst.c
Building with 'gcc'.
Warning: You are using gcc version '7.5.0'. The version of gcc is not
supported. The version currently supported with MEX is '6.3.x'. For a
list of currently supported compilers see:
https://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.

>> mextst ([1, 2])
mxGetPr:       1.000000, 2.000000
mxGetDoubles:  1.000000, 2.000000

>> mextst ([1+i, 2+2i])
Error using mextst
Array must not be complex.

%% Commenting out "//pr = mxGetPr" + following line and recompile

>> mextst ([1+i, 2+2i])

%% MATLAB CRASH!!!!

%% Commenting out "//d = mxGetDoubles" + following line and recompile

>> mextst ([1+i, 2+2i])
Error using mextst
Array must not be complex.


But it must be said for fairness, that in their reference example
"explore.c", TMW suggests to use the test "mxIsComplex ()" before
calling "mxGetDoubles ()".

Kai

Reply | Threaded
Open this post in threaded view
|

Re: Need tests for new MEX interface functions run in recent version of Matlab

John W. Eaton
Administrator
In reply to this post by John W. Eaton
On 1/14/20 7:31 PM, Gene Harvey wrote:

> R2019b
>
> 1. Yes. The error displayed is "Array must not be complex."
> 2. The function actually returns NULL, and the file does not terminate.
>
> I also tried both with Int16. Here, mxGetPr returns a pointer to the
> data, as expected, but mxGetDoubles returns NULL rather than
> terminating. This doesn't seem to match with the documentation, and I
> did build it as a MEX file, so maybe someone else can confirm what I'm
> seeing.

Yes, the documentation clearly states that it should throw an error and
terminate the mex function.  The behavior you are seeing looks more like
what is described if you had built a standalone application instead of a
mex function.

jwe


Reply | Threaded
Open this post in threaded view
|

Re: Need tests for new MEX interface functions run in recent version of Matlab

John W. Eaton
Administrator
In reply to this post by siko1056
On 1/14/20 7:27 PM, Kai Torben Ohlhus wrote:

>>> mex -r2018a mextst.c
> Building with 'gcc'.
> Warning: You are using gcc version '7.5.0'. The version of gcc is not
> supported. The version currently supported with MEX is '6.3.x'. For a
> list of currently supported compilers see:
> https://www.mathworks.com/support/compilers/current_release.
> MEX completed successfully.
>
>>> mextst ([1, 2])
> mxGetPr:       1.000000, 2.000000
> mxGetDoubles:  1.000000, 2.000000
>
>>> mextst ([1+i, 2+2i])
> Error using mextst
> Array must not be complex.
>
> %% Commenting out "//pr = mxGetPr" + following line and recompile
>
>>> mextst ([1+i, 2+2i])
>
> %% MATLAB CRASH!!!!
>
> %% Commenting out "//d = mxGetDoubles" + following line and recompile

Does mxGetDoubles return NULL in this case?  Still, the documentation
only says it will do that if you built a standalone application, not a
mex function.

jwe



Reply | Threaded
Open this post in threaded view
|

Re: Need tests for new MEX interface functions run in recent version of Matlab

siko1056
On 1/15/20 1:09 PM, John W. Eaton wrote:

> On 1/14/20 7:27 PM, Kai Torben Ohlhus wrote:
>
>>>> mex -r2018a mextst.c
>> Building with 'gcc'.
>> Warning: You are using gcc version '7.5.0'. The version of gcc is not
>> supported. The version currently supported with MEX is '6.3.x'. For a
>> list of currently supported compilers see:
>> https://www.mathworks.com/support/compilers/current_release.
>> MEX completed successfully.
>>
>>>> mextst ([1, 2])
>> mxGetPr:       1.000000, 2.000000
>> mxGetDoubles:  1.000000, 2.000000
>>
>>>> mextst ([1+i, 2+2i])
>> Error using mextst
>> Array must not be complex.
>>
>> %% Commenting out "//pr = mxGetPr" + following line and recompile
>>
>>>> mextst ([1+i, 2+2i])
>>
>> %% MATLAB CRASH!!!!
>>
>> %% Commenting out "//d = mxGetDoubles" + following line and recompile
>
> Does mxGetDoubles return NULL in this case?  Still, the documentation
> only says it will do that if you built a standalone application, not a
> mex function.
>
> jwe
>
Yes, mxGetDoubles returns NULL in this case.  I modified the program, as
attached.

>> mex -r2018a mextst.c
[...]
MEX completed successfully.
>> mextst ([1+i, 2+2i])
Error using mextst
d is 'NULL'

Kai

mextst.c (407 bytes) Download Attachment