Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ARMA_USE_MKL_ALLOC
- #include <armadillo>
- #include "mex.h"
- using namespace arma;
- void armaSetPr(mxArray *matlabMatrix, const Mat<double>& armaMatrix)
- {
- double *dst_pointer = mxGetPr(matlabMatrix);
- const double *src_pointer = armaMatrix.memptr();
- std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaMatrix.n_elem);
- }
- void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
- {
- uword tnum = (uword) mxGetScalar(prhs[0]);
- uword a = (uword) mxGetScalar(prhs[1]);
- uword b = (uword) mxGetScalar(prhs[2]);
- uword c = (uword) mxGetScalar(prhs[3]);
- uword d = (uword) mxGetScalar(prhs[4]);
- mat Ez = Mat<double>(mxGetPr(prhs[5]), (uword) mxGetM(prhs[5]),
- (uword) mxGetN(prhs[5]), true, true);
- mat Hx = Mat<double>(mxGetPr(prhs[6]), (uword) mxGetM(prhs[6]),
- (uword) mxGetN(prhs[6]), true, true);
- mat A = Mat<double>(mxGetPr(prhs[7]), (uword) mxGetM(prhs[7]),
- (uword) mxGetN(prhs[7]), true, true);
- mat B = Mat<double>(mxGetPr(prhs[8]), (uword) mxGetM(prhs[8]),
- (uword) mxGetN(prhs[8]), true, true);
- mat C = Mat<double>(mxGetPr(prhs[9]), (uword) mxGetM(prhs[9]),
- (uword) mxGetN(prhs[9]), true, true);
- mat D = Mat<double>(mxGetPr(prhs[10]), (uword) mxGetM(prhs[10]),
- (uword) mxGetN(prhs[10]), true, true);
- for (uword t = 0; t < tnum; t++)
- {
- Ez.submat(a-1, c-1, b-1, d-1) = A % Ez.submat(a-1, c-1, b-1, d-1) +
- B % (Hx.submat(a, c-1, b, d-1) - Hx.submat(a-1, c-1, b-1, d-1));
- Hx.submat(a-1, c-1, b-1, d-1) = C % Hx.submat(a-1, c-1, b-1, d-1) +
- D % (Ez.submat(a, c-1, b, d-1) - Ez.submat(a-1, c-1, b-1, d-1));
- }
- plhs[0] = mxCreateDoubleMatrix(Ez.n_rows, Ez.n_cols, mxREAL);
- armaSetPr(plhs[0], Ez);
- plhs[1] = mxCreateDoubleMatrix(Hx.n_rows, Hx.n_cols, mxREAL);
- armaSetPr(plhs[1], Ez);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement