Skip to content

Commit 3eeab5a

Browse files
author
Alexandre Marquet
committed
Import improvements from gr-lazyviterbi.
1 parent 8541f32 commit 3eeab5a

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

log_bcjr_base.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
log_bcjr_base::log_bcjr_base(int I, int S, int O,
2424
const std::vector<int> &NS,
2525
const std::vector<int> &OS)
26-
: d_I(I), d_S(S), d_O(O)
26+
: d_I(I), d_S(S), d_O(O), d_ordered_OS(S*I)
2727
{
2828
if (NS.size() != S*I) {
2929
throw std::runtime_error("Invalid size for NS.");
@@ -36,6 +36,14 @@ log_bcjr_base::log_bcjr_base(int I, int S, int O,
3636
d_OS = OS;
3737

3838
generate_PS_PI();
39+
40+
//Compute ordered_OS
41+
std::vector<int>::iterator ordered_OS_it = d_ordered_OS.begin();
42+
for(int s=0 ; s < S ; ++s) {
43+
for(size_t i=0 ; i<(d_PS[s]).size() ; ++i) {
44+
*(ordered_OS_it++) = OS[d_PS[s][i]*I + d_PI[s][i]];
45+
}
46+
}
3947
}
4048

4149
void
@@ -69,7 +77,7 @@ log_bcjr_base::compute_fw_metrics(const std::vector<float> &G,
6977

7078
float norm_A = -std::numeric_limits<float>::max();
7179
std::vector<float>::iterator A_prev, A_curr;
72-
std::vector<int>::iterator PS_it, PI_it;
80+
std::vector<int>::iterator PS_it, ordered_OS_it;
7381

7482
//Integrate initial forward metrics
7583
std::copy(A0.begin(), A0.end(), A.begin());
@@ -80,19 +88,18 @@ log_bcjr_base::compute_fw_metrics(const std::vector<float> &G,
8088
for(std::vector<float>::const_iterator G_k = G.begin() ;
8189
G_k != G.end() ; G_k += d_O) {
8290

91+
ordered_OS_it = d_ordered_OS.begin();
8392
for(int s=0 ; s < d_S ; ++s) {
8493
//Iterators for previous state and previous input lists
8594
PS_it=d_PS[s].begin();
86-
PI_it=d_PI[s].begin();
8795

8896
//Loop
8997
for(size_t i=0 ; i<(d_PS[s]).size() ; ++i) {
98+
// Equivalent to:
99+
// *A_curr = _max_star(*A_curr,
100+
// A_prev[PS[s][i]] + G_k[d_OS[PS[s][i]*I + PI[s][i]]);
90101
*A_curr = _max_star(*A_curr,
91-
A_prev[*PS_it] + G_k[d_OS[(*PS_it)*d_I + (*PI_it)]]);
92-
93-
//Update PS/PI iterators
94-
++PS_it;
95-
++PI_it;
102+
A_prev[*(PS_it++)] + G_k[*(ordered_OS_it++)]);
96103
}
97104

98105
//Update iterators
@@ -135,11 +142,7 @@ log_bcjr_base::compute_bw_metrics(const std::vector<float> &G,
135142
//Loop
136143
for(size_t i=0 ; i < d_I ; ++i) {
137144
*B_curr = _max_star(*B_curr,
138-
B_next[(d_S-1)-*NS_it] + G_k[(d_O-1)-*OS_it]);
139-
140-
//Update PS/PI iterators
141-
++NS_it;
142-
++OS_it;
145+
B_next[(d_S-1)-*(NS_it++)] + G_k[(d_O-1)-*(OS_it++)]);
143146
}
144147

145148
//Update iterators

log_bcjr_base.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,32 @@ class log_bcjr_base
4242
int d_S;
4343
//! The number of possible output sequences.
4444
int d_O;
45+
4546
/* Gives the next state ns of a branch defined by its
4647
* initial state s and its input symbol i : NS[s*I+i]=ns.
4748
*/
4849
std::vector<int> d_NS;
50+
4951
/* Gives the output symbol of of a branch defined by its
5052
* initial state s and its input symbol i : OS[s*I+i]=os.
5153
*/
5254
std::vector<int> d_OS;
55+
56+
/* Same as d_FSM.OS(), but re-ordered in the following way:
57+
* d_ordered_OS[s*I+i] = d_OS()[d_PS()[s][i]*I + d_PI()[s][i]]
58+
*/
59+
std::vector<int> d_ordered_OS;
60+
5361
/* Defined such that d_PS[s] contains all the previous states having a
5462
* branch with state s.
5563
* Such a previous state may appear multiple time if there are multiple
5664
* transistions between two states.
5765
*/
5866
std::vector<std::vector<int> > d_PS;
67+
5968
//! Defined such that d_PI[s] contains all the inputs yielding to state s.
6069
std::vector<std::vector<int> > d_PI;
70+
6171
//! Generates PS, PI and T tables.
6272
void generate_PS_PI();
6373

0 commit comments

Comments
 (0)