22 T1* casadi_from_mex(
const mxArray* p, T1* y,
const casadi_int* sp, T1* w) {
23 casadi_int nrow, ncol, is_sparse, c, k, p_nrow, p_ncol;
24 const casadi_int *colind, *row;
27 if (!mxIsDouble(p) || mxGetNumberOfDimensions(p)!=2)
28 mexErrMsgIdAndTxt(
"Casadi:RuntimeError",
29 "\"from_mex\" failed: Not a two-dimensional matrix of double precision.");
36 is_sparse = mxIsSparse(p);
43 p_data = (
const double*)mxGetData(p);
44 if (p_nrow==1 && p_ncol==1) {
46 double v = is_sparse && Jc[1]==0 ? 0 : *p_data;
48 casadi_fill(y, nnz, v);
51 if (nrow!=p_nrow || ncol!=p_ncol) {
52 tr = nrow==p_ncol && ncol==p_nrow && (nrow==1 || ncol==1);
53 if (!tr) mexErrMsgIdAndTxt(
"Casadi:RuntimeError",
54 "\"from_mex\" failed: Dimension mismatch. "
55 "Expected %d-by-%d, got %d-by-%d instead.",
56 nrow, ncol, p_nrow, p_ncol);
60 for (c=0; c<ncol; ++c)
61 for (k=colind[c]; k<colind[c+1]; ++k) w[row[k]+c*nrow]=0;
62 for (c=0; c<p_ncol; ++c)
63 for (k=Jc[c]; k<(casadi_int) Jc[c+1]; ++k) w[c+Ir[k]*p_ncol] = p_data[k];
64 for (c=0; c<ncol; ++c)
65 for (k=colind[c]; k<colind[c+1]; ++k) y[k] = w[row[k]+c*nrow];
67 for (c=0; c<ncol; ++c) {
68 for (k=colind[c]; k<colind[c+1]; ++k) w[row[k]]=0;
69 for (k=Jc[c]; k<(casadi_int) Jc[c+1]; ++k) w[Ir[k]]=p_data[k];
70 for (k=colind[c]; k<colind[c+1]; ++k) y[k]=w[row[k]];
74 for (c=0; c<ncol; ++c) {
75 for (k=colind[c]; k<colind[c+1]; ++k) {
76 y[k] = p_data[row[k]+c*nrow];