Skip to content

Commit 70abfdd

Browse files
committed
replace manual vector initialization
1 parent 5c2d185 commit 70abfdd

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/viterbi.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ pub fn forward(
2727
Vec<[f64; hmm::State::COUNT]>,
2828
Vec<[Option<hmm::State>; hmm::State::COUNT]>,
2929
) {
30-
let mut alpha: Vec<[f64; hmm::State::COUNT]> = Vec::with_capacity(seq.len());
31-
let mut path: Vec<[Option<hmm::State>; hmm::State::COUNT]> = Vec::with_capacity(seq.len());
30+
let mut alpha: Vec<[f64; hmm::State::COUNT]> = vec![[0.0; hmm::State::COUNT]; seq.len()];
31+
let mut path: Vec<[Option<hmm::State>; hmm::State::COUNT]> =
32+
vec![[Some(hmm::State::S); hmm::State::COUNT]; seq.len()];
3233
let mut temp_i: [usize; hmm::PERIOD] = [0; hmm::PERIOD];
3334
let mut temp_i_1: [usize; hmm::PERIOD] = [0; hmm::PERIOD];
34-
35-
for _ in 0..seq.len() {
36-
alpha.push([0.0; hmm::State::COUNT]);
37-
path.push([Some(hmm::State::S); hmm::State::COUNT]);
38-
}
3935
alpha[0].copy_from_slice(&global.pi);
4036
for i in &mut alpha[0] {
4137
*i *= -1.0

0 commit comments

Comments
 (0)