aboutsummaryrefslogtreecommitdiff
path: root/tests/aux/dsysvtest.m
diff options
context:
space:
mode:
authorGertjan van den Burg <burg@ese.eur.nl>2016-09-22 11:50:58 +0200
committerGertjan van den Burg <burg@ese.eur.nl>2016-09-22 11:50:58 +0200
commit55a628da1e04e41d6dab8cbda9b8ed946970e13e (patch)
tree8093f1507542bf9c2d04b0d9102b81e5c207614e /tests/aux/dsysvtest.m
parentRemove commented out code (diff)
downloadgensvm-55a628da1e04e41d6dab8cbda9b8ed946970e13e.tar.gz
gensvm-55a628da1e04e41d6dab8cbda9b8ed946970e13e.zip
More unit tests for optimize
Also added auxiliary Octave files used to construct the unit tests
Diffstat (limited to 'tests/aux/dsysvtest.m')
-rw-r--r--tests/aux/dsysvtest.m37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/aux/dsysvtest.m b/tests/aux/dsysvtest.m
new file mode 100644
index 0000000..fb22f5c
--- /dev/null
+++ b/tests/aux/dsysvtest.m
@@ -0,0 +1,37 @@
+more off;
+clear;
+
+rand('state', 891716);
+
+n = 6;
+m = 5;
+
+
+tmp = rand(n);
+% A is symmetric, but not necessarily p.s.d.
+A = tmp + tmp';
+clear tmp;
+
+for i=1:size(A, 1)
+ for j=1:size(A, 2)
+ if j >= i % only print the upper part
+ fprintf('matrix_set(A, n, %i, %i, %.16f);\n', i-1, j-1, A(i, j));
+ end
+ end
+end
+fprintf('\n\n');
+
+B = rand(n, m);
+b = vec(B); % this gives B in column-major order
+for i=1:numel(b)
+ fprintf('B[%i] = %.16f;\n', i-1, b(i));
+end
+
+X = A \ B;
+
+x = vec(X);
+for i=1:numel(x)
+ fprintf('mu_assert(fabs(B[%i] - %.16f) < 1e-14,\n"Incorrect value of B at %i");\n', i-1, x(i), i-1);
+end
+
+fprintf('\n\n');