Closed skewballfox closed 2 years ago
Hi,
thanks for the report!
Unfortunately, I can't reproduce the error. The following code runs fine on my machine:
use ndarray::{concatenate, Array2, Axis};
use ndrustfft::{ndfft_r2c, Complex, R2cFftHandler};
fn fft_spectrum(frames: Array2<f64>, fft_points: usize /*=512*/) -> Array2<f64> {
println!("starting fft points");
let row_size = frames.shape()[0];
let col_size = frames.shape()[1];
let mut handler = R2cFftHandler::<f64>::new(fft_points);
let frames = if col_size < fft_points {
concatenate![
Axis(1),
frames,
Array2::<f64>::zeros((row_size, fft_points - col_size))
]
} else {
frames
};
println!("declaring spectrum vector");
let mut spectrum_vector = Array2::<Complex<f64>>::zeros((row_size, fft_points / 2 + 1));
println!("starting ndfft_r2c");
ndfft_r2c(
&frames.view(),
&mut spectrum_vector.view_mut(),
&mut handler,
1,
);
println!("finished ndfft");
spectrum_vector.map(|v: &Complex<f64>| -> f64 { (v.re.powf(2.) + v.im.powf(2.)).sqrt() as f64 })
}
fn main() {
let frames: Array2<f64> = Array2::ones((6248, 512));
fft_spectrum(frames, 512);
}
So I think the reason lies in the frames array. Are there maybe NaN values in frames? Can you give me a full example, where you also call the fft_spectrum function? Then I try to investigate further!
Best regards
sure, this is currently being called inside test_mfcc
inside mfcc-rust.
A couple of notes:
f64
s around 0.
fft_spectrum
frames shouldn't have any NaNs, otherwise wouldn't that generate an error somewhere earlier in the call stack as the type is explicitly f64
?
Thx, the error is probably caused by calling ndfft_r2c with an array that does not conform to the standard layout, i.e. row major (C). In your case, the frames array has a column major layout (F). This should be handled somehow in ndrustfft. I am thinking of a solution, maybe tomorrow or next week.
so after checking the method is_standard_layout
for frames a few times, concat seems to be changing the order in a way I wasn't expecting, frames was row major before the zero padding, and column major after.
definitely changing that. I'm not sure if I should close this issue or not, if that makes the problem disappear on my end.
Lets leave it open and I think about a fix for v0.4. I was planning an update either way, to add the option for different normalizations.
Branch v0.4 works with different array layouts. I will update it on crates.io shortly.
I'm running into an issue where
ndfft_r2c
panics when called with parameters that seem valid. the size of the input(frames
) in this instance is[6248,512]
, the size of output(spectrum_vector
) is[6248,257]
. handler was fed the value512
, and the transformation is happening upon the second axis(1
).here's the code:
the code throws the following error:
when running a traceback, this seems to originate from the zip function at line 97 inside lib.rs. The full traceback is attached below