Skip to content

Commit 4b9a620

Browse files
Improve handling of empty prediction stacks in _fate function
- Added checks to ensure that the function handles cases where the prediction stack or time stack is empty, preventing potential errors during calculations. - Maintained original behavior when stacks are empty, allowing for graceful handling of failed integrations.
1 parent 4a86711 commit 4b9a620

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

dynamo/prediction/fate.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,18 @@ def _fate(
253253
t_stack, prediction_stack = np.hstack(t), np.hstack(prediction)
254254
n_cell, n_feature = init_states.shape
255255

256-
t_len = int(len(t_stack) / n_cell)
257-
avg = np.zeros((n_feature, t_len))
256+
if len(t_stack) > 0 and len(prediction_stack) > 0:
257+
t_len = int(len(t_stack) / n_cell)
258+
avg = np.zeros((n_feature, t_len))
258259

259-
for i in range(t_len):
260-
avg[:, i] = np.mean(prediction_stack[:, np.arange(n_cell) * t_len + i], 1)
260+
for i in range(t_len):
261+
avg[:, i] = np.mean(prediction_stack[:, np.arange(n_cell) * t_len + i], 1)
261262

262-
prediction = [avg]
263-
t = [np.sort(np.unique(t))]
263+
prediction = [avg]
264+
t = [np.sort(np.unique(t))]
265+
else:
266+
# If stack is empty (e.g. failed integrations), keep original or handle as needed
267+
pass
264268

265269
return t, prediction
266270

0 commit comments

Comments
 (0)