Skip to content

Commit

Permalink
Make fix_amps_ndarray public.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjordan committed Oct 30, 2023
1 parent 420ffc8 commit f4420da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [0.7.0] - 2023-10-31
### Added
- Expose Rust function `fix_amps_ndarray`
- FFI functions

See the changes below for an explanation.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mwa_hyperbeam"
version = "0.6.1"
version = "0.7.0"
authors = [
"Christopher H. Jordan <christopherjordan87@gmail.com>",
"Jack L. B. Line <jack.line@curtin.edu.au>",
Expand Down
29 changes: 1 addition & 28 deletions src/fee/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use ndarray::prelude::*;

use super::{FEEBeam, FEEBeamError};
use crate::{
fix_amps_ndarray,
gpu::{DevicePointer, GpuError, GpuFloat},
types::CacheKey,
};
Expand Down Expand Up @@ -681,31 +682,3 @@ impl FEEBeamGpu {
self.num_unique_freqs
}
}

/// Ensure that any delays of 32 have an amplitude (dipole gain) of 0. The
/// results are bad otherwise! Also ensure that we have 32 dipole gains (amps)
/// here. Also return a Rust array of delays for convenience.
pub(super) fn fix_amps_ndarray(
amps: ArrayView1<f64>,
delays: ArrayView1<u32>,
) -> ([f64; 32], [u32; 16]) {
let mut full_amps: [f64; 32] = [1.0; 32];
full_amps
.iter_mut()
.zip(amps.iter().cycle())
.zip(delays.iter().cycle())
.for_each(|((out_amp, &in_amp), &delay)| {
if delay == 32 {
*out_amp = 0.0;
} else {
*out_amp = in_amp;
}
});

// So that we don't have to do .as_slice().unwrap() on our ndarrays outside
// of this function, return a Rust array of delays here.
let mut delays_a: [u32; 16] = [0; 16];
delays_a.iter_mut().zip(delays).for_each(|(da, d)| *da = *d);

(full_amps, delays_a)
}
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ cfg_if::cfg_if! {
}

pub use marlu::{AzEl, Jones}; // So that callers can have a different version of Marlu.

use ndarray::ArrayView1;

/// Ensure that any delays of 32 have an amplitude (dipole gain) of 0. The
/// results are bad otherwise! Also ensure that we have 32 dipole gains (amps)
/// here. Also return a Rust array of delays for convenience.
pub fn fix_amps_ndarray(amps: ArrayView1<f64>, delays: ArrayView1<u32>) -> ([f64; 32], [u32; 16]) {
let mut full_amps: [f64; 32] = [1.0; 32];
full_amps
.iter_mut()
.zip(amps.iter().cycle())
.zip(delays.iter().cycle())
.for_each(|((out_amp, &in_amp), &delay)| {
if delay == 32 {
*out_amp = 0.0;
} else {
*out_amp = in_amp;
}
});

// So that we don't have to do .as_slice().unwrap() on our ndarrays outside
// of this function, return a Rust array of delays here.
let mut delays_a: [u32; 16] = [0; 16];
delays_a.iter_mut().zip(delays).for_each(|(da, d)| *da = *d);

(full_amps, delays_a)
}

0 comments on commit f4420da

Please sign in to comment.