From 6f2286de604f437cd392814c97533c57b963d256 Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 29 Mar 2025 14:41:02 +0100 Subject: [PATCH] unit test is working --- lab02/fib/src/compute.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lab02/fib/src/compute.cpp diff --git a/lab02/fib/src/compute.cpp b/lab02/fib/src/compute.cpp new file mode 100644 index 0000000..1127181 --- /dev/null +++ b/lab02/fib/src/compute.cpp @@ -0,0 +1,46 @@ + +#include "matrix.h" +#include +#include +#include + +int fib(int n) { + if (n < 2) + return n; + + int a = 0; + int b = 1; + + for (int i = 2; i <= n; ++i) { + int temp = a + b; + a = b; + b = temp; + } + + return b; +} + +std::vector get_lookup(const std::vector &v) { + std::vector lookup = std::vector(256); + + for (int i = 0; i < 256; i++) { + lookup[i] = fib(i); + } + + return lookup; +} + +Matrix compute(const Matrix &s, const std::vector &v) { + std::vector lookup = get_lookup(v); + + Matrix m(s.dim()); + const int n = v.size(); + for (int j = 0; j < n; ++j) { + double val = static_cast(lookup[v[j] % 256]); + double val2 = (sin(val) * tan(val) / sqrt(cos(val) + 2)); + for (int i = 0; i < n; ++i) { + m(j, i) = s(j, i) * val2; + } + } + return m; +}