chiark / gitweb /
Add octave test
authorJulien Schueller <schueller@phimeca.com>
Wed, 13 Jul 2016 16:39:22 +0000 (18:39 +0200)
committerJulien Schueller <schueller@phimeca.com>
Thu, 14 Jul 2016 06:11:10 +0000 (08:11 +0200)
.travis.yml
test/CMakeLists.txt
test/t_octave.m [new file with mode: 0644]

index 92021c4cecc4fdf56ebe15d0c462351619c5d579..a0ccf61dd7cfba4037f9ff51507df987e41c3649 100644 (file)
@@ -33,8 +33,10 @@ matrix:
     - os: osx
       install:
         - brew tap homebrew/python
-        - brew install swig python
+        - brew tap homebrew/science
+        - brew update
+        - brew install swig python octave
       script:
         - mkdir build && pushd build
         - cmake -DCMAKE_INSTALL_PREFIX=~/.local  -DWITH_CXX=ON ..
-        - make install && make tests && ctest --output-on-failure
\ No newline at end of file
+        - make install && make tests && ctest --output-on-failure
index 4b5ae239b6f239d547fd607f5437d20dfbfdfd6f..353d98a57638916d1f813a6142ae05c3c0ea640d 100644 (file)
@@ -31,3 +31,7 @@ if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${CMAKE_SOURCE_D
   add_test (NAME test_std_python COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_std.py)
   set_tests_properties (test_std_python PROPERTIES ENVIRONMENT "${PYINSTALLCHECK_ENVIRONMENT}")
 endif ()
+
+if (OCTAVE_FOUND)
+  add_test (NAME test_octave COMMAND ${OCTAVE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_octave.m ${CMAKE_SOURCE_DIR}/octave ${CMAKE_BINARY_DIR}/octave)
+endif ()
\ No newline at end of file
diff --git a/test/t_octave.m b/test/t_octave.m
new file mode 100644 (file)
index 0000000..8beac50
--- /dev/null
@@ -0,0 +1,31 @@
+
+arg_list = argv ();
+for i = 1:nargin
+    loadpath = arg_list{i};
+    printf ("-- adding path: %s\n", loadpath);
+    addpath (loadpath);
+endfor
+
+function [val, gradient] = myfunc(x)
+    val = sqrt(x(2));
+    if (nargout > 1)
+        gradient = [0, 0.5 / val];
+    end
+endfunction
+
+function [val, gradient] = myconstraint(x,a,b)
+    val = (a*x(1) + b)^3 - x(2);
+    if (nargout > 1)
+        gradient = [3*a*(a*x(1) + b)^2, -1];
+    end
+endfunction
+
+
+opt.algorithm = NLOPT_LD_MMA
+%  opt.algorithm = NLOPT_LN_COBYLA
+opt.lower_bounds = [-inf, 0]
+opt.min_objective = @myfunc
+opt.fc = { (@(x) myconstraint(x,2,0)), (@(x) myconstraint(x,-1,1)) }
+opt.fc_tol = [1e-8, 1e-8];
+opt.xtol_rel = 1e-4
+[xopt, fmin, retcode] = nlopt_optimize(opt, [1.234 5.678])