Changed some unwraps to expect. Debugged multiplication with weighting broadcast

This commit is contained in:
Anne de Jong 2024-09-29 17:38:59 +02:00
parent 826266b8ee
commit 65df1c82f6
4 changed files with 15 additions and 7 deletions

View File

@ -136,7 +136,9 @@ impl AvPowerSpectra {
// });
// Option 2: broadcasting with an unwrap.
azip!((c in &mut Cpsnew, f in fw_pwr.broadcast(dim).unwrap()) {
let dview_fw = fw_pwr.slice(s![..,NewAxis, NewAxis]);
azip!((c in &mut Cpsnew, f in dview_fw.broadcast(dim).expect("BUG: Cannot broadcast")) {
// Scale with frequency weighting
*c = Cflt::new(c.re * f, c.im * f);
});
}
@ -300,7 +302,8 @@ impl AvPowerSpectra {
let res = res.clone();
return res.to_pyarray_bound(py);
}
panic!("No data!");
let res: Bound<'py, PyArray3<Cflt>> = PyArray3::zeros_bound(py, [0, 0, 0], true);
res
}
}
#[cfg(test)]
@ -333,7 +336,7 @@ mod test {
.fs(1.)
.overlap(overlap.clone())
.build()
.unwrap();
.expect("BUG: Settings cannot be build.");
assert_eq!(settings.get_overlap_keep(), *expected);
}
@ -352,12 +355,12 @@ mod test {
.overlap(Overlap::NoOverlap {})
.mode(ApsMode::ExponentialWeighting { tau })
.build()
.unwrap();
.expect("Settings cannot be empty");
let overlap_keep = settings.get_overlap_keep();
let mut aps = AvPowerSpectra::new(settings);
assert_eq!(aps.overlap_keep, 0);
let distr = Normal::new(1.0, 1.0).unwrap();
let distr = Normal::new(1.0, 1.0).expect("Distribution cannot be built");
let timedata_some = Dmat::random((nfft, 1), distr);
let timedata_zeros = Dmat::zeros((nfft, 1));

View File

@ -1,7 +1,7 @@
//! Compute forward single sided amplitude spectra
use crate::config::*;
use realfft::{RealFftPlanner, RealToComplex};
use std::sync::Arc;
use std::{fmt::Debug, sync::Arc};
#[derive(Clone)]
pub struct FFT {

View File

@ -28,6 +28,9 @@ impl FreqWeighting {
fn __str__(&self) -> String {
format!("{self}-weighting")
}
fn letter(&self) -> String {
format!("{self}")
}
#[staticmethod]
#[pyo3(name = "default")]
fn default_py() -> Self {

View File

@ -141,13 +141,15 @@ impl PowerSpectra {
/// Compute FFTs of input channel data. Stores the scaled FFT data in
/// self.freqdata.
fn compute_ffts(&mut self, timedata: ArrayView2<Flt>) -> ArrayView2<Cflt> {
assert!(timedata.nrows() > 0);
let (n, nch) = timedata.dim();
let nfft = self.nfft();
assert!(n == nfft);
// Make sure enough fft engines are available
while nch > self.ffts.len() {
self.ffts.push(self.ffts.last().unwrap().clone());
self.ffts
.push(self.ffts.last().expect("FFT's should not be empty").clone());
self.freqdata
.push_column(Ccol::from_vec(vec![Cflt::new(0., 0.); nfft / 2 + 1]).view())
.unwrap();