From 24869218f3a2150739b8a5e5159c6e7c19afbd24 Mon Sep 17 00:00:00 2001 From: Dylan Uys Date: Thu, 6 Jun 2024 21:52:35 +0000 Subject: [PATCH] reshaping non_zero_weight_idx to (1,) in case of single non-zero weight this avoids an error wherein len() is called on an array scalar --- template/base/utils/weight_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/template/base/utils/weight_utils.py b/template/base/utils/weight_utils.py index 06fc0d4d..ab1484fa 100644 --- a/template/base/utils/weight_utils.py +++ b/template/base/utils/weight_utils.py @@ -140,6 +140,9 @@ def process_weights_for_netuid( # Find all non zero weights. non_zero_weight_idx = np.argwhere(weights > 0).squeeze() + if non_zero_weight_idx.ndim == 0: + non_zero_weight_idx = non_zero_weight_idx.reshape((1,)) + non_zero_weight_uids = uids[non_zero_weight_idx] non_zero_weights = weights[non_zero_weight_idx] if non_zero_weights.size == 0 or metagraph.n < min_allowed_weights: