Comments (3)
What's happening here is due to the following lines which calculate the shape of the output array:
Lines 106 to 110 in 2ca177f
If you compute the shape directly in python, it reveals a floating point roundoff:
In [1]: 15001 / 12499
Out[1]: 1.2001760140811264
In [2]: 12499 * (15001 / 12499)
Out[2]: 15000.999999999998
which then gets clamped down to 15000 when we cast to int. This is one of those times where the non-associativity of floating point arithmetic can bite you.
Now, we could have used rounding here instead of a floor/integer cast, but that would have caused problems for other input configurations, extrapolating off the end of the input array rather than interpolating.
It's worth noting that behavior with this configuration is not consistent across different resampling engines. Both resampy and samplerate produce 15000 samples in this configuration, probably because they're based on the same calculation. soxr and scipy.signal produce 15001.
Probably your best bet here, if you're really worried about it, is to explicitly construct the time grid you want to sample, and use the resample_nu
function.
I'm not sure there's much else we can do, but it might be possible that a different order of operations in the length calculation here could produce more consistent results. (I'm not sure that it is possible in general, but it's worth looking into.)
from resampy.
Note: I've updated the title here because the issue is the length, not the sampling rate (which is correctly computed).
from resampy.
Confirmed that changing the order of operations here does fix the calculation. It may in turn cause other problems, but I somewhat doubt it. The fix in #113 retains integer multiplication first (which should not produce fp errors) and then divides, so there is only one step that can induce round-off error instead of two.
from resampy.
Related Issues (20)
- v0.3.0 produces other results than v0.2.2 HOT 3
- Resampy 0.3.0 is slow for multi-dimensional input HOT 5
- Issues with Numba 0.55.2 HOT 4
- Resampy 0.3.1 slows down other libraries HOT 43
- Use parallel=True by default can be problematic in multiprocessing applications HOT 8
- Bringing import time back down
- Missing argument in guvectorize decorator ? HOT 2
- Quality issues? HOT 5
- resampling to the same hz HOT 1
- Incompatible with latest numba HOT 3
- Best quality resampling?
- PyPI status HOT 2
- Add linting CI
- Add pypi packaging workflow HOT 1
- Drop legacy python support
- Fix documentation builds HOT 1
- Update README badges
- Improve default filters and make the whole process reproducible HOT 14
- Cache filters on load
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resampy.