refactored
This commit is contained in:
+36
-18
@@ -4,13 +4,13 @@
|
||||
#include <cmath>
|
||||
|
||||
// Use like `Householder<double, 8>::inPlace(data)` - size must be ≥ 1
|
||||
template<typename Sample, int size>
|
||||
template<typename T, int size>
|
||||
class Householder
|
||||
{
|
||||
static constexpr Sample multiplier{-2.0/size};
|
||||
static constexpr T multiplier{-2.0/size};
|
||||
|
||||
public:
|
||||
static void inPlace(Sample *arr)
|
||||
static void inPlace(T *arr)
|
||||
{
|
||||
double sum = 0;
|
||||
for (int i = 0; i < size; ++i)
|
||||
@@ -28,11 +28,11 @@ class Householder
|
||||
};
|
||||
|
||||
// Use like `Hadamard<double, 8>::inPlace(data)` - size must be a power of 2
|
||||
template<typename Sample, int size>
|
||||
template<typename T, int size>
|
||||
class Hadamard
|
||||
{
|
||||
public:
|
||||
static inline void recursiveUnscaled(Sample * data)
|
||||
static inline void recursiveUnscaled(T * data)
|
||||
{
|
||||
if (size <= 1)
|
||||
{
|
||||
@@ -41,8 +41,8 @@ class Hadamard
|
||||
constexpr int hSize = size/2;
|
||||
|
||||
// Two (unscaled) Hadamards of half the size
|
||||
Hadamard<Sample, hSize>::recursiveUnscaled(data);
|
||||
Hadamard<Sample, hSize>::recursiveUnscaled(data + hSize);
|
||||
Hadamard<T, hSize>::recursiveUnscaled(data);
|
||||
Hadamard<T, hSize>::recursiveUnscaled(data + hSize);
|
||||
|
||||
// Combine the two halves using sum/difference
|
||||
for (int i = 0; i < hSize; ++i)
|
||||
@@ -54,11 +54,11 @@ class Hadamard
|
||||
}
|
||||
}
|
||||
|
||||
static inline void inPlace(Sample * data)
|
||||
static inline void inPlace(T * data)
|
||||
{
|
||||
recursiveUnscaled(data);
|
||||
|
||||
Sample scalingFactor = std::sqrt(1.0/size);
|
||||
T scalingFactor = std::sqrt(1.0/size);
|
||||
for (int c = 0; c < size; ++c)
|
||||
{
|
||||
data[c] *= scalingFactor;
|
||||
@@ -66,13 +66,13 @@ class Hadamard
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, uint numCh>
|
||||
template<typename T, uint size>
|
||||
class Shuffle
|
||||
{
|
||||
public:
|
||||
static inline void outOfPlace(T *in, T *out, const int *shuffle_spec)
|
||||
static inline void outOfPlace(T in[size], T out[size], const int shuffle_spec[size])
|
||||
{
|
||||
for (int c=0; c < numCh; c++)
|
||||
for (int c=0; c < size; c++)
|
||||
{
|
||||
T sign = 1;
|
||||
int s = shuffle_spec[c];
|
||||
@@ -81,7 +81,7 @@ class Shuffle
|
||||
sign = -1;
|
||||
s *= -1;
|
||||
}
|
||||
if (s >= numCh)
|
||||
if (s >= size)
|
||||
{
|
||||
s = 0;
|
||||
}
|
||||
@@ -90,15 +90,33 @@ class Shuffle
|
||||
}
|
||||
};
|
||||
|
||||
static inline void inPlace(T *data, const int *shuffle_spec)
|
||||
static inline void inPlace(T in_out[size], const int shuffle_spec[size])
|
||||
{
|
||||
T temp[numCh];
|
||||
for (int c=0; c < numCh; c++)
|
||||
T temp[size];
|
||||
for (int c=0; c < size; c++)
|
||||
{
|
||||
temp[c] = data[c];
|
||||
temp[c] = in_out[c];
|
||||
}
|
||||
Shuffle<T, numCh>::outOfPlace(temp, data, shuffle_spec);
|
||||
Shuffle<T, size>::outOfPlace(temp, in_out, shuffle_spec);
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T, uint size>
|
||||
class Mix
|
||||
{
|
||||
public:
|
||||
static inline void split(T in, T out[size])
|
||||
{
|
||||
for (uint c=0; c < size; c++)
|
||||
{
|
||||
out[c] = in;
|
||||
}
|
||||
}
|
||||
|
||||
static inline T combine(T in_out[size])
|
||||
{
|
||||
Householder<T, size>::inPlace(in_out);
|
||||
return in_out[0];
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user