From 55a628da1e04e41d6dab8cbda9b8ed946970e13e Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Thu, 22 Sep 2016 11:50:58 +0200 Subject: More unit tests for optimize Also added auxiliary Octave files used to construct the unit tests --- tests/aux/dsysvtest.m | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/aux/dsysvtest.m (limited to 'tests/aux/dsysvtest.m') 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'); -- cgit v1.2.3