Repository: metric-space-ai/metric (language: python)

Issue:
Wrong wavelet matrix construction in ring padding
```
(     0.332671     0.806891     0.459877    -0.135011   -0.0854413    0.0352263            0            0            0            0            0            0 )
(            0            0     0.332671     0.806891     0.459877    -0.135011   -0.0854413    0.0352263            0            0            0            0 )
(            0            0            0            0     0.332671     0.806891     0.459877    -0.135011   -0.0854413    0.0352263            0            0 )
(            0            0            0            0            0            0     0.332671     0.806891     0.459877    -0.135011   -0.0854413    0.0352263 )
(            0            0            0            0            0            0            0            0     0.332671     0.806891     0.459877    -0.135011 )
(            0            0   -0.0854413    0.0352263            0            0            0            0            0            0            0            0 )
(    0.0352263    0.0854413    -0.135011    -0.459877     0.806891    -0.332671            0            0            0            0            0            0 )
(            0            0    0.0352263    0.0854413    -0.135011    -0.459877     0.806891    -0.332671            0            0            0            0 )
(            0            0            0            0    0.0352263    0.0854413    -0.135011    -0.459877     0.806891    -0.332671            0            0 )
(            0            0            0            0            0            0    0.0352263    0.0854413    -0.135011    -0.459877     0.806891    -0.332671 )
(            0            0            0            0            0            0            0            0    0.0352263    0.0854413    -0.135011    -0.459877 )
(            0            0     0.806891    -0.332671            0            0            0            0            0            0            0            0 )
```

**location:**
`transform/wavelet.cpp`
`DaubechiesMat(size_t size, int order = 4)`


Discussion / hints:

Fix patch:
diff --git a/modules/transform/wavelet.cpp b/modules/transform/wavelet.cpp
index 34d38b09..70dc013d 100644
--- a/modules/transform/wavelet.cpp
+++ b/modules/transform/wavelet.cpp
@@ -147,9 +147,9 @@ Container dbwavf(int const wnum, types::index_value_type_t<Container> returnType
             return F5;
         },
         []() {
-            Container F6 = { 0.07887121600143, 0.34975190703757, 0.53113187994121, 0.22291566146505, -0.02233187416548,
-                0.00039162557603, 0.00337803118151, -0.00076176690258, -0.15999329944587, -0.09175903203003,
-                0.06894404648720, 0.01946160485396 };
+            Container F6 = { 0.07887121600145072, 0.3497519070376178, 0.5311318799408691, 0.22291566146501776, 
+				-0.15999329944606142, -0.09175903203014758, 0.0689440464873723, 0.019461604854164663, 
+				-0.022331874165094537, 0.0003916255761485779, 0.003378031181463938, -0.0007617669028012533 };
             return F6;
         },
         []() {


Test patch:
diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml
index ddd6a1e4..b918484f 100644
--- a/.github/workflows/test-coverage.yml
+++ b/.github/workflows/test-coverage.yml
@@ -6,6 +6,11 @@ on:
     paths-ignore:
       - 'python/**'
       - '.github/workflows/cmake.yml'
+  pull_request:
+    branches:
+      - master
+    paths-ignore:
+      - 'python/**'
 jobs:
   deploy:
     runs-on: ubuntu-latest
diff --git a/tests/transform_test/dwt_tests.cpp b/tests/transform_test/dwt_tests.cpp
index 5ab21e14..53ff186c 100644
--- a/tests/transform_test/dwt_tests.cpp
+++ b/tests/transform_test/dwt_tests.cpp
@@ -2,6 +2,8 @@
 
 #include "modules/transform/wavelet.hpp"
 
+#include <random>
+
 
 
 using DM = blaze::DynamicMatrix<double>;
@@ -103,3 +105,49 @@ TEMPLATE_TEST_CASE("dwt_d", "[transform]", BV/*, SV*/)
     }
     REQUIRE( maxdiff <= std::numeric_limits<double>::epsilon()*1e6 );
 }
+
+TEST_CASE("Wavelet reconstruction")
+{
+  std::random_device rd;
+  std::mt19937 me{rd()};
+  std::uniform_real_distribution<double> d(-10, 10);
+
+  using Data = blaze::DynamicVector<double>;
+
+  auto l = GENERATE(100, 1000, 10000, 100000);
+  Data v(l);
+  for (size_t i = 0; i < l; ++i) {
+    v[i] = d(me);
+  }
+
+
+  std::tuple<Data, Data> splitted;
+  Data restored;
+  int wavelet = GENERATE(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+  REQUIRE_NOTHROW(splitted = wavelet::dwt(v, wavelet));
+  REQUIRE_NOTHROW(restored = wavelet::idwt(std::get<0>(splitted),
+                                          std::get<1>(splitted),
+                                                  wavelet, v.size()));
+
+  double maxdiff = 0;
+  for (size_t i = 0; i < restored.size(); ++i) {
+      double diff = std::abs(restored[i] - v[i]);
+      if (diff > maxdiff)
+          maxdiff = diff;
+  }
+  REQUIRE( maxdiff <= std::numeric_limits<double>::epsilon()*1e7 );
+
+}
+
+//TEST_CASE("1d")
+//{
+//  using V = blaze::DynamicVector<double>;
+//
+//  V data = {1, 2, 3, 4};
+//  auto [cA, cD] = wavelet::dwt(data, 1);
+//
+//  std::cout << cA << std::endl;
+//  std::cout << cD << std::endl;
+//
+//}
diff --git a/tests/transform_test/wavelet_tests.cpp b/tests/transform_test/wavelet_tests.cpp
index a4cf42e2..cdc3f65b 100644
--- a/tests/transform_test/wavelet_tests.cpp
+++ b/tests/transform_test/wavelet_tests.cpp
@@ -17,3 +17,25 @@ TEMPLATE_TEST_CASE("DaubechiesMat", "[transform][wavelet]", float)
     REQUIRE(Approx(sumHigh) == blaze::sum(blaze::row(dmat, i)));
   }
 }
+
+TEMPLATE_TEST_CASE("dbwavf", "[transform][wavelet]", float, double)
+{
+	using Vector = blaze::DynamicVector<TestType>;
+
+	std::array<Vector, 11> coeffs;
+	coeffs[1] = {0.5000000000000001, 0.5000000000000001};
+	coeffs[2] = {0.3415063509461097, 0.5915063509461097, 0.15849364905389035, -0.09150635094610966};
+	coeffs[3] = {0.23523360389208187, 0.5705584579157218, 0.3251825002631163, -0.09546720778416369, -0.06041610415519811, 0.024908749868441868};
+	coeffs[4] = {0.16290171402564918, 0.5054728575459145, 0.44610006912337985, -0.019787513117822324, -0.13225358368451987, 0.02180815023708863, 0.02325180053549088, -0.007493494665180737};
+	coeffs[5] = {0.1132094912917792, 0.4269717713525142, 0.5121634721295986, 0.09788348067390469, -0.17132835769146745, -0.02280056594177365, 0.05485132932106683, -0.004413400054179128, -0.008895935050977096, 0.002358713969533936};
+	coeffs[6] = {0.07887121600145072, 0.3497519070376178, 0.5311318799408691, 0.22291566146501776, -0.15999329944606142, -0.09175903203014758, 0.0689440464873723, 0.019461604854164663, -0.022331874165094537, 0.0003916255761485779, 0.003378031181463938, -0.0007617669028012533};
+	coeffs[7] = {0.05504971537281186, 0.28039564181276255, 0.5155742458180986, 0.3321862411055397, -0.10175691123134625, -0.15841750564033286, 0.050423232504694084, 0.057001722579871586, -0.02689122629484544, -0.01171997078210329, 0.008874896189680764, 0.00030375749770106936, -0.0012739523590936867, 0.00025011342656124536};
+	coeffs[8] = {0.03847781105407624, 0.22123362357612492, 0.4777430752138737, 0.4139082662111959, -0.011192867666880218, -0.20082931639048904, 0.0003340970462201188, 0.09103817842365776, -0.01228195052284841, -0.031175103325139432, 0.009886079648350761, 0.006184422409815923, -0.003443859628441809, -0.00027700227447938935, 0.00047761485564962614, -8.30686306866127e-05};
+	coeffs[9] = {0.0269251747946628, 0.17241715190697796, 0.42767453217970763, 0.46477285718314737, 0.09418477475318378, -0.2073758809009385, -0.0684767745123831, 0.1050341711395062, 0.021726337730614546, -0.04782363206009703, 0.00017744640661651893, 0.015812082926255862, -0.0033398101131385774, -0.0030274802875450662, 0.0013064836402472458, 0.00016290733567609223, -0.00017816487951077768, 2.7822757017154863e-05};
+	coeffs[10] = {0.01885857879612069, 0.1330610913969209, 0.3727875357432334, 0.48681405536682, 0.19881887088450872, -0.1766681008970563, -0.13855493936048316, 0.09006372426669666, 0.06580149355053501, -0.050483285598389716, -0.020829624043800808, 0.023484907048698562, 0.002550218483907239, -0.00758950116792825, 0.0009866626824816026, 0.0014088432950973382, -0.00048497391992820553, -8.235450304538899e-05, 6.617718342555339e-05, -9.379207813750205e-06};
+
+	const int wnum = GENERATE(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+	const auto r = wavelet::dbwavf<Vector>(wnum, 1);
+	REQUIRE(r == coeffs[wnum]);
+}