Hi, I'm new to Rust and still try to how ownership and lifetime work.
I have a simple function that filters a ML model output, a vector of probabilities, with a threshold and returns the values and their indices in the output vector.
fn filterOutput(output: Vec<f32>, threshold: f32) -> Vec<(f32, usize)>{
let size = output.len();
let indices: Vec<usize> = (0..size).collect();
let outputWithIndices: Vec<(&f32, &usize)> = output.iter().zip(indices.iter()).filter(|(&p,&n)| p > threshold).collect();
let r: Vec<(f32, usize)> = outputWithIndices.cloned().collect();
r
}
outputWithIndices.cloned().
doesn't work.
Are there more efficient ways to return the filtered result without unnecessary copies of data?