无法将带有前置和后置增量运算符的c ++转换为python

Pet*_*ves 0 c++ python

我试图找出a[++j]=*pr++;以下代码中的等价物(来自MatLab mex文件)是在Python中.我发现'pr'是指向输入数组的第一个元素的指针,但我无法理解j发生的事情.有人可以用没有指针等简单的术语来解释那里发生的事情吗?

rf3(mxArray *array_ext, mxArray *hs[]) {
double *pr, *po, a[16384], ampl, mean;
int tot_num, index, j, cNr;
mxArray *array_out;

tot_num = mxGetM(array_ext) * mxGetN(array_ext);
pr = (double *)mxGetPr(array_ext);

array_out = mxCreateDoubleMatrix(3, tot_num-1, mxREAL);
po = (double *)mxGetPr(array_out);

j = -1;
cNr = 1;
for (index=0; index<tot_num; index++) {
    a[++j]=*pr++;
    while ( (j >= 2) && (fabs(a[j-1]-a[j-2]) <= fabs(a[j]-a[j-1])) ) {
        ampl=fabs( (a[j-1]-a[j-2])/2 );
        switch(j)
{
            case 0: { break; }
            case 1: { break; }
            case 2: {
                mean=(a[0]+a[1])/2;
                a[0]=a[1];
                a[1]=a[2];
                j=1;
                if (ampl > 0) {
                    *po++=ampl;
                    *po++=mean;
                    *po++=0.50;
                }
                break;
            }
            default: {
                mean=(a[j-1]+a[j-2])/2;
                a[j-2]=a[j];
                j=j-2;
                if (ampl > 0) {
                    *po++=ampl;
                    *po++=mean;
                    *po++=1.00;
                    cNr++;
                }
                break;
            }
        }
    }
}
for (index=0; index<j; index++) {
    ampl=fabs(a[index]-a[index+1])/2;
    mean=(a[index]+a[index+1])/2;
    if (ampl > 0){
        *po++=ampl;
        *po++=mean;
        *po++=0.50;
    }
}
/* you can free the allocated memeory */
/* for array_out data                 */
  mxSetN(array_out, tot_num - cNr);
  hs[0]=array_out;
}
Run Code Online (Sandbox Code Playgroud)

Sig*_*erm 5

这是发生的事情:

  1. 增加j1
  2. 分配给指向的a[j]pr
  3. 增量pr.

按此顺序.