Skip to content

Commit 1eabc66

Browse files
committed
refactor of index
1 parent 4e94a2b commit 1eabc66

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

rust/src/algorithms/transform.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ pub fn mixture_discrete(
144144

145145
for (&function_value, &support_value) in function.iter().zip(support.iter()) {
146146
let partial_probability = function_value * mix_weight;
147-
if raw_mixture_support.contains(&support_value) {
147+
if let Some(support_index) =
148+
raw_mixture_support.iter().position(|&x| x == support_value)
149+
{
150+
raw_mixture_function[support_index] += partial_probability;
151+
} else {
148152
raw_mixture_support.push(support_value);
149153
raw_mixture_function.push(partial_probability);
150-
} else {
151-
let support_index = support
152-
.iter()
153-
.position(|&x| x == support_value)
154-
.expect("support value not found in mixture support");
155-
raw_mixture_function[support_index] += partial_probability;
156154
}
157155
}
158156
}

0 commit comments

Comments
 (0)