MATLAB: MEX api and interleaved complex arrays

apicomplex interleavedMATLABmex

Does MATLAB store complex data in interleaved format since R2018a?
If you compile a MEX function with the -R2018a flag, you can process complex arrays in interleaved format. But what happens, if a MEX function is compiled with the -R2017b flag and called from a modern Matlab version? Does accessing mxGetPr / mxGetPi cause a deep data copy to create the two arrays in separate memory blocks, and another copy to re-create an interleaved array for the output?
This would mean, that MEX fumnctions processing complex data are very inefficient, when they use the -R2017b flag. Is this correct?

Best Answer

Where have you been Jan? In a cave? ;-)
Sorry it couldn't resist.
As I understand, when you call mxGetPr and mxGetPi, the data is copied to ensure the compatibility. Yes it will not optimal, but it's not very inefficient either.
Yes, to avoid the data copy you have to compile MCC using -R2018a flag then use function such as mxGetDoubles, etc rather than mxGetPr
You can always use the predefined symbol MX_HAS_INTERLEAVED_COMPLEX to know which option you compile
#if MX_HAS_INTERLEAVED_COMPLEX
a = mxGetDoubles(A); % interleaved complex
/* ... */
#else
ar = mxGetPr(A); % real part
ai = mxGetPi(A); % iaginary part
/* ... */
#endif