diff --git a/src/convert/mod.rs b/src/convert/mod.rs index 73c7fbf..a7d00fa 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -226,22 +226,22 @@ fn generate_full_matrix(mwax_order: Vec) -> Vec { ///LegacyConversionBaseline`s which tell us, for a specific output baseline, where in the input HDU /// to get data from (and whether it needs to be conjugated). /// -pub(crate) fn generate_conversion_array( - rf_inputs: &mut [Rfinput], -) -> Vec { - // Sort the rf_inputs by "Input / metafits" order - rf_inputs.sort_by(|a, b| a.input.cmp(&b.input)); - +pub(crate) fn generate_conversion_array(rf_inputs: &[Rfinput]) -> Vec { // Ensure we have a 256 element array of rf_inputs // This is an OK assumption since we only use this for Legacy and OldLegacy MWA data which always must have 128 tiles // which is 256 rf inputs. assert_eq!(rf_inputs.len(), 256); // Create a vector which contains all the mwax_orders, sorted by "input" from the metafits - let mut mwax_order: Vec = vec![0; 256]; - for index in 0..256 { - mwax_order[index] = rf_inputs[index].subfile_order as usize; - } + let mut map = rf_inputs + .iter() + .map(|rf| (rf.input, rf.subfile_order)) + .collect::>(); + map.sort_unstable(); + let mwax_order = map + .into_iter() + .map(|(_, subfile_order)| subfile_order as usize) + .collect(); // Generate the full matrix let full_matrix: Vec = generate_full_matrix(mwax_order); diff --git a/src/correlator_context/mod.rs b/src/correlator_context/mod.rs index c2c7278..63dcba9 100644 --- a/src/correlator_context/mod.rs +++ b/src/correlator_context/mod.rs @@ -334,7 +334,7 @@ impl CorrelatorContext { // or just leave it empty if we're in any other format let legacy_conversion_table: Vec = match gpubox_info.mwa_version { MWAVersion::CorrOldLegacy | MWAVersion::CorrLegacy => { - convert::generate_conversion_array(&mut metafits_context.rf_inputs.clone()) + convert::generate_conversion_array(&metafits_context.rf_inputs) } _ => Vec::new(), };