Skip to content

Commit

Permalink
deal with hyperbeam 0.7.1 api change - oops!
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Jun 26, 2024
1 parent 9018217 commit 2e54cad
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
21 changes: 6 additions & 15 deletions src/beam/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use log::debug;
use marlu::{AzEl, Jones};
use ndarray::prelude::*;

use super::{Beam, BeamError, BeamType, Delays};
use super::{partial_to_full, validate_delays, Beam, BeamError, BeamType, Delays};

#[cfg(any(feature = "cuda", feature = "hip"))]
use super::{BeamGpu, DevicePointer, GpuFloat};
Expand All @@ -33,6 +33,8 @@ impl FEEBeam {
gains: Option<Array2<f64>>,
file: Option<&Path>,
) -> Result<FEEBeam, BeamError> {
validate_delays(&delays, num_tiles)?;

let ideal_delays = delays.get_ideal_delays();
debug!("Ideal dipole delays: {:?}", ideal_delays);

Expand Down Expand Up @@ -350,11 +352,11 @@ impl BeamGpu for FEEBeamGpu {
}

fn get_tile_map(&self) -> *const i32 {
self.hyperbeam_object.get_tile_map()
self.hyperbeam_object.get_device_tile_map()
}

fn get_freq_map(&self) -> *const i32 {
self.hyperbeam_object.get_freq_map()
self.hyperbeam_object.get_device_freq_map()
}

fn get_num_unique_tiles(&self) -> i32 {
Expand All @@ -364,15 +366,4 @@ impl BeamGpu for FEEBeamGpu {
fn get_num_unique_freqs(&self) -> i32 {
self.hyperbeam_object.get_num_unique_freqs()
}
}

/// Assume that the dipole delays for all tiles is the same as the delays for
/// one tile.
fn partial_to_full(delays: Vec<u32>, num_tiles: usize) -> Array2<u32> {
let mut out = Array2::zeros((num_tiles, 16));
let d = Array1::from(delays);
out.outer_iter_mut().for_each(|mut tile_delays| {
tile_delays.assign(&d);
});
out
}
}
55 changes: 36 additions & 19 deletions src/beam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,25 +415,7 @@ pub fn create_beam_object(
debug!("Setting up a FEE beam object");

// Check that the delays are sensible.
match &dipole_delays {
Delays::Partial(v) => {
if v.len() != 16 || v.iter().any(|&v| v > 32) {
return Err(BeamError::BadDelays);
}
}

Delays::Full(a) => {
if a.len_of(Axis(1)) != 16 || a.iter().any(|&v| v > 32) {
return Err(BeamError::BadDelays);
}
if a.len_of(Axis(0)) != num_tiles {
return Err(BeamError::InconsistentDelays {
num_rows: a.len_of(Axis(0)),
num_tiles,
});
}
}
}
validate_delays(&dipole_delays, num_tiles)?;

// Set up the FEE beam struct from the `MWA_BEAM_FILE` environment
// variable.
Expand All @@ -445,3 +427,38 @@ pub fn create_beam_object(
}
}
}

/// Assume that the dipole delays for all tiles is the same as the delays for
/// one tile.
fn partial_to_full(delays: Vec<u32>, num_tiles: usize) -> Array2<u32> {
let mut out = Array2::zeros((num_tiles, 16));
let d = Array1::from(delays);
out.outer_iter_mut().for_each(|mut tile_delays| {
tile_delays.assign(&d);
});
out
}

fn validate_delays(delays: &Delays, num_tiles: usize) -> Result<(), BeamError> {
match delays {
Delays::Partial(v) => {
if v.len() != 16 || v.iter().any(|&v| v > 32) {
return Err(BeamError::BadDelays);
}
}

Delays::Full(a) => {
if a.len_of(Axis(1)) != 16 || a.iter().any(|&v| v > 32) {
return Err(BeamError::BadDelays);
}
if a.len_of(Axis(0)) != num_tiles {
return Err(BeamError::InconsistentDelays {
num_rows: a.len_of(Axis(0)),
num_tiles,
});
}
}
}

Ok(())
}
3 changes: 3 additions & 0 deletions src/beam/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use serial_test::serial;

use super::*;

#[cfg(any(feature = "cuda", feature = "hip"))]
use approx::abs_diff_eq;

#[test]
fn no_beam_means_no_beam() {
let azels = [
Expand Down

0 comments on commit 2e54cad

Please sign in to comment.