Skip to content
This repository was archived by the owner on Oct 20, 2020. It is now read-only.

Commit 791411b

Browse files
committed
de-eigen
1 parent 246f859 commit 791411b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

NLMS/nlms.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <algorithm>
1313
#include <limits>
1414

15-
#include <Eigen/Eigen>
16-
1715
#include <atfa_api.h>
1816

1917
using sample_t = float;
@@ -24,34 +22,38 @@ constexpr sample_t delta = std::sqrt(std::numeric_limits<sample_t>::epsilon());
2422

2523
struct AdapfData {
2624

27-
sample_t x_array[N];
28-
Eigen::Map<Eigen::Matrix<sample_t, N, 1>> x;
29-
30-
sample_t w_array[N];
31-
Eigen::Map<Eigen::Matrix<sample_t, N, 1>> w;
25+
sample_t x[N];
26+
sample_t w[N];
3227

3328
AdapfData()
34-
: x(x_array), w(w_array)
3529
{
3630
reset();
3731
}
3832

3933
void reset() {
40-
std::fill(x_array, x_array+N, 0);
41-
std::fill(w_array, w_array+N, 0);
34+
std::fill(x, x+N, 0);
35+
std::fill(w, w+N, 0);
4236
}
4337

4438
void push(sample_t sample) {
45-
std::copy_backward(x_array, x_array+(N-1), x_array+N); // shift down
46-
x_array[0] = sample; // push at top
39+
std::copy_backward(x, x+(N-1), x+N); // shift down
40+
x[0] = sample; // push at top
4741
}
4842

4943
sample_t dot_product() const {
50-
return x.dot(w);
44+
sample_t result = 0;
45+
for (int i=0; i<N; ++i)
46+
result += x[i]*w[i];
47+
return result;
5148
}
5249

5350
void update(sample_t err) {
54-
w += mu * err * x / (delta + x.squaredNorm());
51+
sample_t x_normsquared = delta;
52+
for (int i=0; i<N; ++i)
53+
x_normsquared += x[i]*x[i];
54+
sample_t factor = mu*err/x_normsquared;
55+
for (int i=0; i<N; ++i)
56+
w[i] += factor * x[i];
5557
}
5658

5759
};
@@ -91,7 +93,7 @@ float adapf_run(AdapfData *data, float sample, float y, int update,
9193

9294
void adapf_getw(const AdapfData *data, const float **begin, unsigned *n)
9395
{
94-
*begin = data->w_array;
96+
*begin = data->w;
9597
*n = N;
9698
}
9799
}

build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,12 @@ def safename_from_path(path):
580580
logmsg(vbs,1, "No source file will be autogenerated.")
581581

582582
### Compile other sources
583+
583584
for k in sources:
584585
if k == autogen_name:
585586
continue
586-
gen_obj(k, sources[k], [dist_dir, default_eigen_path])
587+
gen_obj(k, sources[k], # [dist_dir, default_eigen_path]
588+
[dist_dir])
587589

588590
### Link
589591

0 commit comments

Comments
 (0)