Skip to content
Snippets Groups Projects
Verified Commit 984c60ac authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Various improvements related to the MEX R2018a API

— Use MX_HAS_INTERLEAVED_COMPLEX for testing for the new API

— Use the typed access functions under the new API, with one exception: we do
  not use mxGetDoubles() instead of mxGetPr(), because it would just complexif
  the code without any value added

For more details, see:
https://fr.mathworks.com/help/matlab/matlab_external/upgrade-mex-files-to-use-interleaved-complex.html
parent 5a4f7062
Branches
Tags
No related merge requests found
......@@ -133,7 +133,11 @@ mxArray *
SylvParams::IntParamItem::createMatlabArray() const
{
mxArray *res = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
#if MX_HAS_INTERLEAVED_COMPLEX
*mxGetInt32s(res) = value;
#else
*static_cast<int *>(mxGetData(res)) = value;
#endif
return res;
}
......
......@@ -169,10 +169,10 @@ BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const
pP = mxDuplicateArray(prhs[7]);
pY = mxDuplicateArray(prhs[8]);
start = mxGetScalar(prhs[9]);
mfd = static_cast<double *>(mxGetData(prhs[10]));
mfd = mxGetPr(prhs[10]);
kalman_tol = mxGetScalar(prhs[11]);
riccati_tol = mxGetScalar(prhs[12]);
nz_state_var = static_cast<double *>(mxGetData(prhs[13]));
nz_state_var = mxGetPr(prhs[13]);
n_diag = mxGetScalar(prhs[14]);
pure_obs = mxGetScalar(prhs[15]);
}
......@@ -190,10 +190,10 @@ BlockKalmanFilter::BlockKalmanFilter(int nlhs, mxArray *plhs[], int nrhs, const
n = mxGetN(pT); // Number of state variables.
pp = mxGetM(pY); // Maximum number of observed variables.
smpl = mxGetN(pY); // Sample size. ;
mfd = static_cast<double *>(mxGetData(prhs[7]));
mfd = mxGetPr(prhs[7]);
kalman_tol = mxGetScalar(prhs[8]);
riccati_tol = mxGetScalar(prhs[9]);
nz_state_var = static_cast<double *>(mxGetData(prhs[10]));
nz_state_var = mxGetPr(prhs[10]);
n_diag = mxGetScalar(prhs[11]);
pure_obs = mxGetScalar(prhs[12]);
}
......@@ -363,7 +363,7 @@ BlockKalmanFilter::block_kalman_filter(int nlhs, mxArray *plhs[])
{
// retrieve the d_index
pd_index = mxGetCell(pdata_index, t);
dd_index = static_cast<double *>(mxGetData(pd_index));
dd_index = mxGetPr(pd_index);
size_d_index = mxGetM(pd_index);
d_index.resize(size_d_index);
for (int i = 0; i < size_d_index; i++)
......
......@@ -64,7 +64,7 @@ mexFunction(int nlhs, mxArray *plhs[],
double *t = mxGetPr(plhs[2]);
double *z = mxGetPr(plhs[3]);
double *sdim = mxGetPr(plhs[4]);
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION >= 0x0904
#if MX_HAS_INTERLEAVED_COMPLEX
mxComplexDouble *gev = mxGetComplexDoubles(plhs[5]);
#else
double *gev_r = mxGetPr(plhs[5]);
......@@ -127,7 +127,7 @@ mexFunction(int nlhs, mxArray *plhs[],
for (size_t i = 0; i < n1; i++)
{
if (std::abs(alpha_r[i]) > zhreshold || std::abs(beta[i]) > zhreshold)
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION >= 0x0904
#if MX_HAS_INTERLEAVED_COMPLEX
gev[i].real = alpha_r[i] / beta[i];
#else
gev_r[i] = alpha_r[i] / beta[i];
......@@ -140,13 +140,13 @@ mexFunction(int nlhs, mxArray *plhs[],
*info = -30;
}
if (alpha_i[i] == 0.0 && beta[i] == 0.0)
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION >= 0x0904
#if MX_HAS_INTERLEAVED_COMPLEX
gev[i].imag = 0.0;
#else
gev_i[i] = 0.0;
#endif
else
#if defined(MATLAB_MEX_FILE) && MATLAB_VERSION >= 0x0904
#if MX_HAS_INTERLEAVED_COMPLEX
gev[i].imag = alpha_i[i] / beta[i];
#else
gev_i[i] = alpha_i[i] / beta[i];
......
......@@ -112,17 +112,29 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (!(mxIsInt32(nzij_pred_mx) && mxGetN(nzij_pred_mx) == 2))
mexErrMsgTxt("nzij_pred should be an int32 matrix with 2 columns");
size_t nnz_pred = mxGetM(nzij_pred_mx);
#if MX_HAS_INTERLEAVED_COMPLEX
const int32_T *nzij_pred = mxGetInt32s(nzij_pred_mx);
#else
const int32_T *nzij_pred = static_cast<const int32_T *>(mxGetData(nzij_pred_mx));
#endif
if (!(mxIsInt32(nzij_current_mx) && mxGetN(nzij_current_mx) == 2))
mexErrMsgTxt("nzij_current should be an int32 matrix with 2 columns");
size_t nnz_current = mxGetM(nzij_current_mx);
#if MX_HAS_INTERLEAVED_COMPLEX
const int32_T *nzij_current = mxGetInt32s(nzij_current_mx);
#else
const int32_T *nzij_current = static_cast<const int32_T *>(mxGetData(nzij_current_mx));
#endif
if (!(mxIsInt32(nzij_fwrd_mx) && mxGetN(nzij_fwrd_mx) == 2))
mexErrMsgTxt("nzij_fwrd should be an int32 matrix with 2 columns");
size_t nnz_fwrd = mxGetM(nzij_fwrd_mx);
#if MX_HAS_INTERLEAVED_COMPLEX
const int32_T *nzij_fwrd = mxGetInt32s(nzij_fwrd_mx);
#else
const int32_T *nzij_fwrd = static_cast<const int32_T *>(mxGetData(nzij_fwrd_mx));
#endif
if (!(mxIsLogicalScalar(has_external_function_mx)))
mexErrMsgTxt("has_external_function should be a logical scalar");
......
......@@ -179,7 +179,11 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (nlhs >= 2)
{
plhs[1] = mxCreateNumericMatrix(1, 1, mxINT64_CLASS, mxREAL);
#if MX_HAS_INTERLEAVED_COMPLEX
*mxGetInt64s(plhs[1]) = seed_out;
#else
*(static_cast<int64_T *>(mxGetData(plhs[1]))) = seed_out;
#endif
}
if (nlhs >= 3)
plhs[2] = mxCreateDoubleScalar(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment