Skip to content

Commit a0cb0d0

Browse files
committed
fix indexing
1 parent 05f0631 commit a0cb0d0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pallets/subtensor/src/epoch/math.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,21 @@ pub fn mask_diag_sparse_except_index(
612612
except_index: u16,
613613
) -> Vec<Vec<(u16, I32F32)>> {
614614
// Store the diagonal entry at except_index
615-
let diag_at_index = sparse_matrix[except_index as usize][except_index as usize].clone();
615+
let diag_at_index = sparse_matrix
616+
.get(except_index as usize)
617+
.and_then(|row| row.get(except_index as usize))
618+
.cloned();
616619
// Mask out the diagonal
617620
let mut result = mask_diag_sparse(sparse_matrix);
618-
// Replace the diagonal entry at except_index
619-
result[except_index as usize][except_index as usize] = diag_at_index;
621+
// Replace the diagonal entry at except_index using only get_mut or map
622+
result.get_mut(except_index as usize).map(|row| {
623+
row.get_mut(except_index as usize).map(|value| {
624+
if let Some(diag_at_index) = diag_at_index {
625+
*value = diag_at_index;
626+
}
627+
})
628+
});
629+
620630
result
621631
}
622632

pallets/subtensor/src/utils/misc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,9 @@ impl<T: Config> Pallet<T> {
736736

737737
// Get the uid of the Owner Hotkey for a subnet.
738738
pub fn get_owner_uid(netuid: u16) -> Option<u16> {
739-
let owner_hotkey = SubnetOwnerHotkey::<T>::get(netuid);
740-
if Uids::<T>::contains_key(netuid, &owner_hotkey) {
741-
Some(Uids::<T>::get(netuid, &owner_hotkey))
742-
} else {
743-
None
739+
match SubnetOwnerHotkey::<T>::try_get(netuid) {
740+
Ok(owner_hotkey) => Uids::<T>::get(netuid, &owner_hotkey),
741+
Err(_) => None,
744742
}
745743
}
746744
}

0 commit comments

Comments
 (0)