Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BadBaselineIdx selection error #30

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ jobs:
sudo ldconfig
fi

- name: Minimum-specified Rust version works
run: |
MIN_RUST=$(grep -m1 "rust-version" Cargo.toml | sed 's|.*\"\(.*\)\"|\1|')
~/.cargo/bin/rustup install $MIN_RUST --profile minimal
cargo +${MIN_RUST} test --no-default-features
cargo +${MIN_RUST} test --all-features

- name: Run tests
run: cargo test

Expand Down Expand Up @@ -87,10 +94,3 @@ jobs:

- name: Run tests, no default features but serde
run: cargo test --no-default-features --features=serde

- name: Minimum-specified Rust version works
run: |
MIN_RUST=$(grep -m1 "rust-version" Cargo.toml | sed 's|.*\"\(.*\)\"|\1|')
~/.cargo/bin/rustup install $MIN_RUST --profile minimal
cargo +${MIN_RUST} test --no-default-features
cargo +${MIN_RUST} test --all-features
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ serde = { version = "1.0.100", features = ["derive"], optional = true }

[dev-dependencies]
approx = { version = "0.5.0", features = ["num-complex"] }
criterion = "0.4.0"
criterion = "~0.4.0"
csv = "1.1.0"
glob = "0.3.0"
lexical = "6.0.0"
Expand All @@ -91,3 +91,11 @@ harness = false
[[bench]]
name = "bench_io"
harness = false

[patch.crates-io]
# TODO: get rid of this once MSRV >= 1.65
dashmap = { git = "https://github.com/xacrimon/dashmap", tag = "v5.5.2" } # v5.5.3 msrv is 1.65
regex = { git = "https://github.com/rust-lang/regex", tag = "regex-syntax-0.7.5" } # regex-syntax > 0.8 msrv is 1.65
regex-syntax = { git = "https://github.com/rust-lang/regex", tag = "regex-syntax-0.7.5" }
# TODO: get rid of this once MSRV >= 1.70
ciborium = { git = "https://github.com/enarx/ciborium", tag = "v0.2.1" } # ciborium-ll v > 0.2.1 needs half ^2.2, half v > 2.3.x msrv is 1.70
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ impl MwaObsContext {
delays: meta_ctx.delays.clone(),
};

for (ant, mut input, number, receiver, mut slot, mut length) in izip!(
#[allow(unused_mut)]
for (ant, mut input, mut number, mut receiver, mut slot, mut length) in izip!(
ants,
result.ant_inputs.outer_iter_mut(),
result.ant_numbers.iter_mut(),
Expand Down
4 changes: 2 additions & 2 deletions src/pos/xyz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ mod tests {
y: -568.5399780273752,
z: -398.80394537420943,
};
assert_abs_diff_eq!(result, expected);
assert_abs_diff_eq!(result, expected, epsilon = 1e-6);

// Do everything automatically.
let result = geocentric.to_geodetic(LatLngHeight {
longitude_rad: COTTER_MWA_LONGITUDE_RADIANS,
latitude_rad: COTTER_MWA_LATITUDE_RADIANS,
height_metres: COTTER_MWA_HEIGHT_METRES,
});
assert_abs_diff_eq!(result, expected);
assert_abs_diff_eq!(result, expected, epsilon = 1e-6);
}

#[test]
Expand Down
33 changes: 33 additions & 0 deletions src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ pub enum SelectionError {
received: String,
},

#[error("bad baseline index supplied to function {function}. expected {expected}, received {received}")]
BadBaselineIdx {
/// The function name
function: String,
/// Predicate on bl_idxs
expected: String,
/// The baseline index that was received instead
received: String,
},

#[cfg(feature = "mwalib")]
#[error(transparent)]
Mwalib(#[from] mwalib::GpuboxError),
Expand Down Expand Up @@ -327,6 +337,16 @@ impl VisSelection {
});
};

let max_bl_idx = corr_ctx.metafits_context.baselines.len();
// check all selected baseline idxs are < max_bl_idx
if self.baseline_idxs.iter().any(|&idx| idx >= max_bl_idx) {
return Err(SelectionError::BadBaselineIdx {
function: "VisSelection::read_mwalib".to_string(),
expected: format!(" < {max_bl_idx}"),
received: format!("{:?}", self.baseline_idxs.clone()),
});
}

// since we are using read_by_baseline_into_buffer, the visibilities are read in order:
// baseline,frequency,pol,r,i

Expand Down Expand Up @@ -640,6 +660,19 @@ mod tests {
);
}

#[test]
fn test_read_mwalib_bad_baseline_idxs() {
let corr_ctx = get_mwax_context();
let mut vis_sel = VisSelection::from_mwalib(&corr_ctx).unwrap();
vis_sel.baseline_idxs = vec![99999999];
// Create a blank array to store flags and visibilities
let fine_chans_per_coarse = corr_ctx.metafits_context.num_corr_fine_chans_per_coarse;
let mut flag_array = vis_sel.allocate_flags(fine_chans_per_coarse).unwrap();
let mut jones_array = vis_sel.allocate_jones(fine_chans_per_coarse).unwrap();
// read visibilities out of the gpubox files
assert!(vis_sel.read_mwalib(&corr_ctx, jones_array.view_mut(), flag_array.view_mut()).is_err());
}

#[test]
#[allow(clippy::unnecessary_cast)]
fn test_read_mwalib_mwa_legacy() {
Expand Down
Loading