-
Notifications
You must be signed in to change notification settings - Fork 109
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
Got "BoundsError" while trying to use resample
function.
#317
Comments
@JayKickliter It looks like you wrote this code originally. I'd have to spend a bit of time reading it to understand why the indexing logic doesn't work in this instance. Do you have time to take a look at it? |
My first guess is that it’s floating point rounding problem, but I’ll take a closer look. I haven’t written a single line of Julia in several years, so it’ll take me little time to get back up to speed. |
Thanks! I'll also take a look. |
#262 is the same bug. |
Another MWE, if it helps: using DSP
x = randn(1822)
resample(x, 0.9802414928649834) # works
resample(x, 0.9802414928649835) # fails |
I'm also hitting this problem on Julia 1.9 beta and DSP v0.7.8:
|
I have hit this multiple times now. My own reproducer is import DSP
DSP.resample(zeros(1000), 0.012) It does appear that somewhere with the Given that For what it's worth, this version of function filt(self::FIRFilter{FIRArbitrary{Th}}, x::AbstractVector{Tx}) where {Th,Tx}
bufLen = DSP.outputlength(self, length(x)) + 1 # Note extra element here
buffer = Vector{promote_type(Th,Tx)}(undef, bufLen)
samplesWritten = filt!(buffer, self, x)
samplesWritten == bufLen || resize!(buffer, samplesWritten)
return buffer
end |
@anowacki It's been years since I wrote this code, and I'd do a lot differently now. I also barely remember any Julia, let alone anything post 0.5. I do think your findings are correct and suggest opening a PR. |
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, the buffer is actually one sample too short and a `BoundsError` is thrown in `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)`. Add one extra sample to the calculated buffer length to catch these exceptional cases, which mostly arise when resampling with particular resampling ratios. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes JuliaDSP#317.
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, the buffer is actually one sample too short and a `BoundsError` is thrown in `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)`. Add one extra sample to the calculated buffer length to catch these exceptional cases, which mostly arise when resampling with particular resampling ratios. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes JuliaDSP#317.
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)` tries to write one sample too many to the buffer and a `BoundsError` is thrown. Add one extra sample to the buffer to catch these exceptional cases. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes JuliaDSP#317.
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)` tries to write one sample too many to the buffer and a `BoundsError` is thrown. Add one extra sample to the buffer to catch these exceptional cases. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes #317.
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)` tries to write one sample too many to the buffer and a `BoundsError` is thrown. Add one extra sample to the buffer to catch these exceptional cases. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes #317. (cherry picked from commit 73d3214)
In some cases when `filt(::FIRFilter{FIRArbitrary}, x)` is called with certain values of `x`, `filt!(buffer, ::FIRFilter{FIRArbitrary}, x)` tries to write one sample too many to the buffer and a `BoundsError` is thrown. Add one extra sample to the buffer to catch these exceptional cases. (This code is really a hack and simply works around the deeper problem of calculating the correct output buffer length; this should instead be addressed properly in a future change.) Closes #317. (cherry picked from commit 73d3214)
And we will get:
The text was updated successfully, but these errors were encountered: