@@ -41,15 +41,15 @@ def _get_source_indices(shifts, start_shift, end_shift, n_samples):
4141def _get_dest_indices (shifts , start_shift , end_shift , n_samples , output_size ):
4242 """Get indices in the output array."""
4343 start = np .maximum (0 , shifts - start_shift )
44- # Calculate actual source data length for each trace
44+ # Clamp source indices to valid range [0, n_samples]
4545 min_start = - shifts + start_shift
46- source_start = np .where (min_start < 0 , 0 , min_start )
46+ source_start = np .clip (min_start , 0 , n_samples )
4747 max_end = n_samples - shifts + end_shift
48- source_end = np .where (max_end > n_samples , n_samples , max_end )
49- source_length = source_end - source_start
50- # Destination end is start + actual source length
51- max_ends = start + source_length
52- end = np .where ( max_ends > output_size , output_size , max_ends )
48+ source_end = np .clip (max_end , 0 , n_samples )
49+ # Compute source length, ensuring non-negative
50+ source_length = np . maximum ( source_end - source_start , 0 )
51+ # Destination end bounded to [0, output_size]
52+ end = np .clip ( start + source_length , 0 , output_size )
5353 return (start , end )
5454
5555
0 commit comments