Help with "mxGetPi is deprecated"

16 views (last 30 days)
Ed Mendes
Ed Mendes on 27 May 2018
Edited: James Tursa on 12 Nov 2018
Hello
I am trying to compile an old mex function. The first lines are:
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
mxArray *blk_cell_pr, *A_cell_pr;
double *A, *B, *AI, *BI, *blksize, *Atmp, *AItmp
....
The problem is that variables AI and BI use the deprecated function MxGetPi (AI = mxGetPi(prhs[1]), for instance) and I have no idea how to modify the code to accommodate the changes. I can use a flag (-R2017b) to compile it but sooner or later I will have to change the code (I've been doing that since 93).
I try the help files but I could not find an example and to be honest I did not understand a thing on the explanation on the consequences of mxGetPi being deprecated.
Any help will be appreciated.
Cheers
Ed

Accepted Answer

James Tursa
James Tursa on 28 May 2018
Edited: James Tursa on 28 May 2018
With the R2018a release of MATLAB, complex real/imag data is stored in an interleaved fashion instead of the separate fashion of R2017b and earlier. If you compile with the -R2017b flag (the default for R2018a) then the complex data is passed into and out of your mex routine via a deep copy, which will slow you down but should still work (unless you are doing something like modifying an input variable inplace). The deep copy stuff is the penalty you pay for using the old memory model API (i.e., the -R2017b flag) in R2018a and later.
How to go about changing your code for -R2018a depends on what your code does. We can't advise you unless we see your code.
  8 Comments
ryyan
ryyan on 11 Nov 2018
Dear all, thank you for your posts. I also met this problem too. But I am wondering, if I have an array of complex variable (image) instead of one complex variable, would the pi = pr + 1 still hold true? Or I would need to change to the size of the real-part of the variable? ie.
pi = pr + sizeof(real-part of the variable)
which is from the
/* example2018a.c
* R2018a Example code doing the equivalent of the following:
* z = any full double complex variable
* r = real(z); i = imag(z);
* result = sum(r(:).*r(:) + i(:).*i(:));
*
...
...
// pr = mxGetPr(prhs[0]);
// pi = mxGetPi(prhs[0]);
pr = (double *) mxGetData(prhs[0]);
pi = pr + 1;
...
I appreciate any hints and help! Thank you very much.
James Tursa
James Tursa on 12 Nov 2018
Edited: James Tursa on 12 Nov 2018
I assume by "... complex variable (image) ..." you mean the underlying data type isn't double, but is something else like uint8. In that case, the only thing you would need to change in my example code is the types involved. E.g. if the image was uint8, then change this
double *pr, *pi;
to this
unsigned char *pr, *pi;
And change this:
pr = (double *) mxGetData(prhs[0]);
to this:
pr = (unsigned char *) mxGetData(prhs[0]);
The pointer arithmetic you DO NOT change! You DO NOT adjust based on the bytes used by the underlying data ... this is done automatically for you by the C/C++ compiler. So
pi = pr + sizeof(real-part of the variable); <-- NO
but
pi = pr + 1; <-- YES, this works regardless of underlying data type

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!