File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,10 @@ def update_one_by_one(
2525) -> None :
2626 for i in range (len (update_values )):
2727 if update_tags [i ]:
28+ # Access a single value from numpy array
2829 start_idx = num_tokens_no_spec_np [i ]
2930 end_idx = start_idx + update_values [i ]
31+ # Update a single value to 2 numpy arrays
3032 num_tokens_no_spec_np [i ] = end_idx
3133 num_tokens_np [i ] = end_idx
3234
@@ -37,6 +39,7 @@ def update_by_batch(
3739 update_tags : list [bool ],
3840 update_values : list [int ],
3941) -> None :
42+ # Convert numpy array to list once before for loop
4043 num_tokens_no_spec = num_tokens_no_spec_np .tolist ()
4144 num_tokens_indices_to_update : list [int ] = []
4245 num_tokens_values_to_update : list [int ] = []
@@ -46,6 +49,7 @@ def update_by_batch(
4649 end_idx = start_idx + update_values [i ]
4750 num_tokens_indices_to_update .append (i )
4851 num_tokens_values_to_update .append (end_idx )
52+ # Batch update numpy arrays after for loop
4953 if num_tokens_indices_to_update :
5054 num_tokens_no_spec_np [num_tokens_indices_to_update ] = (
5155 num_tokens_values_to_update
You can’t perform that action at this time.
0 commit comments