MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_MixMatrix.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10
11#ifndef MARVIN_MIXMATRIX_H
12#define MARVIN_MIXMATRIX_H
15#include <cmath>
16
17namespace marvin::math {
28 template <FloatType SampleType, int size>
29 requires(size >= 1)
31 static constexpr SampleType multiplier{ -2.0 / size };
32
33 public:
38 static void inPlace(SampleType* arr) {
39 SampleType sum = 0;
40 for (int i = 0; i < size; ++i) {
41 sum += arr[i];
42 }
43 sum *= multiplier;
44 vecops::add(arr, sum, size);
45 }
46 };
47
58 template <FloatType SampleType, int size>
59 requires(isPowerOfTwo<size>())
60 class Hadamard {
61 public:
66 static inline void recursiveUnscaled(SampleType* data) {
67 if constexpr (size <= 1)
68 return;
69 else {
70 constexpr int hSize = size / 2;
71 // Two (unscaled) Hadamards of half the size
74 // Combine the two halves using sum/difference
75 for (int i = 0; i < hSize; ++i) {
76 SampleType a = data[i];
77 SampleType b = data[i + hSize];
78 data[i] = (a + b);
79 data[i + hSize] = (a - b);
80 }
81 }
82 }
83
87 static inline void inPlace(SampleType* data) {
89 auto scalingFactor = static_cast<SampleType>(std::sqrt(1.0 / size));
90 vecops::multiply(data, scalingFactor, size);
91 }
92 };
93} // namespace marvin::math
94#endif
A helper class to apply an NxN Hadamard matrix to a given input array-like.
Definition marvin_MixMatrix.h:60
static void recursiveUnscaled(SampleType *data)
Definition marvin_MixMatrix.h:66
static void inPlace(SampleType *data)
Definition marvin_MixMatrix.h:87
A helper class to apply an NxN Householder matrix to a given input array-like.
Definition marvin_MixMatrix.h:30
static void inPlace(SampleType *arr)
Definition marvin_MixMatrix.h:38
void multiply(T *lhs, const T *rhs, size_t size) noexcept
void add(T *lhs, const T *rhs, size_t size) noexcept
Math helper functions and classes.
Definition marvin_Math.h:22
constexpr bool isPowerOfTwo()
Definition marvin_Concepts.h:92