Source

nlopt-ocaml / src / nlopt.ml

Diff from to

src/nlopt.ml

   | NLOPT_MAXEVAL_REACHED 
   | NLOPT_MAXTIME_REACHED
       
-exception Failure
-exception Invalid_args
-exception Out_of_memory
 exception Roundoff_limited
 exception Forced_stop
 
 let check_result = function
-    NLOPT_FAILURE -> raise Failure
-  | NLOPT_INVALID_ARGS -> raise Invalid_args
+    NLOPT_FAILURE -> raise (Failure "NLOPT_FAILURE")
+  | NLOPT_INVALID_ARGS -> raise (Invalid_argument "NLOPT_INVALID_ARGS")
   | NLOPT_OUT_OF_MEMORY -> raise Out_of_memory
   | NLOPT_ROUNDOFF_LIMITED -> raise Roundoff_limited
   | NLOPT_FORCED_STOP -> raise Forced_stop
 
 let optimize opt x =
   if get_dimension opt <> Array.length x then
-    raise Invalid_args
+    raise (Invalid_argument "Nlopt.optimize: dimension of initial guess different from algorithm dimension")
   else
     let (result, xopt, fopt) = ml_optimize opt x in
       (check_result result, xopt, fopt)
 external ml_set_lower_bounds: t -> float array -> result = "ml_nlopt_set_lower_bounds"
 let set_lower_bounds opt lb = 
   if get_dimension opt <> Array.length lb then
-    raise Invalid_args
+    raise (Invalid_argument "Nlopt.set_lower_bounds: dimension of bounds different from algorithm dimension")
   else
     let _ = check_result (ml_set_lower_bounds opt lb) in ()
 
 external ml_set_upper_bounds: t -> float array -> result = "ml_nlopt_set_upper_bounds"
 let set_upper_bounds opt ub = 
   if get_dimension opt <> Array.length ub then
-    raise Invalid_args 
+    raise (Invalid_argument "Nlopt.set_upper_bounds: dimension of bounds different from algorithm dimension")
   else
     let _ = check_result (ml_set_upper_bounds opt ub) in ()
 
 external ml_set_initial_step: t -> float array -> result = "ml_nlopt_set_initial_step" 
 let set_initial_step opt dx = 
   if get_dimension opt <> Array.length dx then
-    raise Invalid_args
+    raise (Invalid_argument "Nlopt.set_initial_step: dimension of initial step different from algorithm dimension")
   else
     let _ = check_result (ml_set_initial_step opt dx) in ();;
 
 external ml_get_initial_step: t -> float array -> float array -> result = "ml_nlopt_get_initial_step"
 let get_initial_step opt x = 
   if get_dimension opt <> Array.length x then
-    raise Invalid_args
+    raise (Invalid_argument "Nlopt.get_initial_step: dimension of initial step different from algorithm dimension") 
   else
     let dx = Array.create (get_dimension opt) nan in
     let _ = check_result (ml_get_initial_step opt x dx) in dx
 external ml_set_population: t -> int -> result = "ml_nlopt_set_population"
 let set_population opt pop = 
   if pop < 0 then
-    raise Invalid_args 
+    raise (Invalid_argument "Nlopt.set_population: population negative")
   else
     let _ = check_result (ml_set_population opt pop) in ()
 ;;
 external ml_set_vector_storage: t -> int -> result = "ml_nlopt_set_vector_storage"
 let set_vector_storage opt m = 
   if m < 0 then
-    raise Invalid_args 
+    raise (Invalid_argument "Nlopt.set_vector_storage: number of stored vectors negative")
   else
     let _ = check_result (ml_set_vector_storage opt m) in ()
 ;;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.