Skip to content

Instantly share code, notes, and snippets.

@geraintluff
Last active Aug 15, 2021
Embed
What would you like to do?
// 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