Commits

Ruben Martinez-Cantin committed b2349a0

Returning errors in mex functions. Matlab has categorical variables.

  • Participants
  • Parent commits 27b67b3

Comments (0)

Files changed (4)

matlab/bayesoptdiscmex.c

   double* xset;
   bopt_params parameters;
   double fmin = 0.0;
+  int error_code;
     
   /* Check correct number of parameters */
   CHECK0(nlhs != 2 || nrhs != 3, "wrong number of arguments");
 #endif
   else
     {
-      mexErrMsgTxt("First term should be a function name (Matlab/Octave) or function handle (Matlab)");
+      mexErrMsgTxt("First term should be a function name "
+		   "(Matlab/Octave) or function handle (Matlab)");
     }
 
   /* Second parameter. Set of values. */
 
   parameters = load_parameters(params);
   
-  bayes_optimization_disc(nDim,user_function,&udata,xset,nPoints,
-			  xptr,&fmin,parameters);
+  error_code = bayes_optimization_disc(nDim,user_function,&udata,xset,nPoints,
+				       xptr,&fmin,parameters);
 
   mxDestroyArray(udata.prhs[udata.xrhs]);
   plhs[0] = xopt;
       *(mxGetPr(plhs[1])) = fmin;
     }
     
+  if (nlhs > 2)
+    {
+      plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
+      *(mxGetPr(plhs[2])) = (double)(error_code);
+    }
+    
+
 }

matlab/bayesoptmex.c

   bopt_params parameters;
   double *ub, *lb;    /* Upper and lower bound */
   double fmin;
+  int error_code;
      
   /* Check correct number of parameters */
   CHECK0(nlhs != 2 || nrhs != 3 || nrhs != 5, 
 	}
     }
 
-  bayes_optimization(nDim,user_function,&udata,lb,ub,xptr,
-		     &fmin,parameters);
+  error_code = bayes_optimization(nDim,user_function,&udata,lb,ub,xptr,
+				  &fmin,parameters);
 
   if(nrhs != 5)
     {
       plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
       *(mxGetPr(plhs[1])) = fmin;
     }
-    
+  if (nlhs > 2)
+    {
+      plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
+      *(mxGetPr(plhs[2])) = (double)(error_code);
+    }
+
 }

matlab/compile_matlab.m

         mex -DBAYESOPT_DLL -output bayesoptdisc bayesoptdiscmex.c ...
             -L..\lib\Release -L. -lbayesopt ...
             -I..\include -I..\wrappers
+        mex -DBAYESOPT_DLL -output bayesoptcat bayesoptcatmex.c ...
+            -L..\lib\Release -L. -lbayesopt ...
+            -I..\include -I..\wrappers
     else
         disp('Compiling static library');
         mex -output bayesoptcont bayesoptmex.c  ...
         mex -output bayesoptdisc bayesoptdiscmex.c  ...
             -L../lib/Release -lbayesopt -lnlopt ...
             -I../include -I../wrappers
+
+        mex -output bayesoptcat bayesoptcatmex.c  ...
+            -L../lib/Release -lbayesopt -lnlopt ...
+            -I../include -I../wrappers
     end
 else
     mex -output bayesoptcont bayesoptmex.c -L../lib -lbayesopt ...
 
     mex -output bayesoptdisc bayesoptdiscmex.c -L../lib -lbayesopt ...
         -lnlopt -I../include -I../wrappers -I../nlopt/api 
+
+    mex -output bayesoptcat bayesoptcatmex.c -L../lib -lbayesopt ...
+        -lnlopt -I../include -I../wrappers -I../nlopt/api 
 end

matlab/compile_octave.m

 mkoctfile -L../lib -lbayesopt -lnlopt -I../include -I../wrappers ...
     --mex --output bayesoptdisc.mex bayesoptdiscmex.c
 
+mkoctfile -L../lib -lbayesopt -lnlopt -I../include -I../wrappers ...
+    --mex --output bayesoptcat.mex bayesoptcatmex.c