-
-
Save geraintluff/c55f9482dce0db6e6a1f4509129e9a2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use like `Hadamard<8>::inPlace(data)` - size must be a power of 2 | |
template<int size> | |
struct Hadamard { | |
static inline void inPlace(double * data) { | |
if (size <= 1) return; | |
constexpr int hSize = size/2; | |
// Two Hadamards of half the size | |
Hadamard<hSize>::inPlace(data); | |
Hadamard<hSize>::inPlace(data + hSize); | |
for (int i = 0; i < hSize; ++i) { | |
double a = data[i]; | |
double b = data[i + hSize]; | |
data[i] = (a + b); | |
data[i + hSize] = (a - b); | |
} | |
} | |
// Scaling factor required to make it orthogonal | |
static Sample normFactor() { | |
return sqrt(1.0/size); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment