File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -612,11 +612,21 @@ pub fn mask_diag_sparse_except_index(
612
612
except_index : u16 ,
613
613
) -> Vec < Vec < ( u16 , I32F32 ) > > {
614
614
// 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 ( ) ;
616
619
// Mask out the diagonal
617
620
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
+
620
630
result
621
631
}
622
632
Original file line number Diff line number Diff line change @@ -736,11 +736,9 @@ impl<T: Config> Pallet<T> {
736
736
737
737
// Get the uid of the Owner Hotkey for a subnet.
738
738
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 ,
744
742
}
745
743
}
746
744
}
You can’t perform that action at this time.
0 commit comments