-
Notifications
You must be signed in to change notification settings - Fork 945
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
numbafy #157
Comments
I took a quick cut at cythonizing stft today. A naive, frame-oriented cython implementation gets almost as fast as our current batched (pure-python) implementation. |
Updating: now that #323 is merged, we have optional numba jit decoration. This will be considerably easier to deploy than cythonization. |
Tagging @ejhumphrey if he wants to take a look into this |
Maybe as a subtask, it would help to implement a profiling test suite so we know where the hot spots are. |
Like that one? https://pypi.python.org/pypi/pytest-profiling That would be the output for
Next step could be to run |
Indeed! But that probably requires waiting til after #391 happens to do properly. |
I did some tinkering on this. No benefit to jitting Other functions become difficult to jit because of list comprehensions, so optimization will have to follow some slight refactoring. |
Since 0.5 is already getting pretty bloated, I'm going to put this one off to 0.6. |
More updates: numba now has pip wheels, so we can make a hard dependency going forward. This should simplify a few things. |
Update from the scipy2017 sprint:
OTOH, things like |
Updates:
|
A possible workaround to this is given in the numba faq, which suggests using a jitted closure to compile a separate backend function that depends on |
An example of accelerated import numpy
import cython
import librosa.effects
def remix(
d,
frame_length,
hop_length,
top_db,
margin,
):
'''
Truncate silence in a mono f32 waveform, zeros are aligned
hop_length, frame_length, top_db as in librosa.effects.trim
margin is amount of zeros between consequent intervals
'''
i = librosa.effects.split(
d,
top_db=top_db,
frame_length=frame_length,
hop_length=hop_length,
)
assert isinstance(margin, int) and margin > 0
i2 = numpy.empty_like(i)
cython.inline(
'''
cdef long t1
cdef long t2
cdef long t3
cdef long t4
t4 = d.shape[0]
for t1 in range(i.shape[0]):
t2 = i[t1, 0]
t3 = t2
while t3 > 0 and d[t3] * d[t2] >= 0:
t3 -= 1
i2[t1, 0] = t3
t2 = i[t1, 1]
t3 = t2
while t3 < t4 and d[t3] * d[t2] >= 0:
t3 += 1
i2[t1, 1] = t3
''',
d=d,
i=i,
i2=i2,
)
o = (i2[:, 1] - i2[:, 0])
d2 = numpy.zeros(
o.sum() + 1 + (o.shape[0] - 1) * margin,
dtype=d.dtype
)
cython.inline(
'''
cdef long t1
cdef long t2
cdef long t3
cdef long t4
t3 = 0
t4 = i2.shape[0]
for t1 in range(i2.shape[0]):
t2 = i2[t1, 1] - i2[t1, 0]
d2[t3 :][:t2] = d[
i2[t1, 0] : i2[t1, 1]
]
if t1 > 0:
d2[t3] = 0
if t1 < t4:
d2[t3 + t2] = 0
t3 += t2
if t1 < t4:
t3 += margin
''',
d=d,
d2=d2,
margin=margin,
i2=i2,
)
return d2 |
Wherever it makes sense to accelerate loop code, we should jit-compile.
Specifically,
The text was updated successfully, but these errors were encountered: