|
accompany_new = np.zeros_like(np.empty((track_length, 128))) |
Hi π I found several lines in the code like this:
rhythm_new = np.zeros_like(np.empty((track_length, 128)))
bass_new = np.zeros_like(np.empty((track_length, 128)))
accompany_new = np.zeros_like(np.empty((track_length, 128)))
melody_new = np.zeros_like(np.empty((track_length, 128)))
These can be simplified and optimized as:
rhythm_new = np.zeros((track_length, 128)) bass_new = np.zeros((track_length, 128)) accompany_new = np.zeros((track_length, 128)) melody_new = np.zeros((track_length, 128))
- np.empty(...) creates an uninitialized array that is immediately discarded.
- np.zeros_like(...) then allocates a second array β introducing unnecessary memory and computation overhead.
- np.zeros(...) is more direct, efficient, and improves readability.
hitloop_project_backend/midi_functions.py
Line 760 in 2bf523a
Hi π I found several lines in the code like this:
These can be simplified and optimized as:
rhythm_new = np.zeros((track_length, 128)) bass_new = np.zeros((track_length, 128)) accompany_new = np.zeros((track_length, 128)) melody_new = np.zeros((track_length, 128))