Skip to content

Commit c276ede

Browse files
author
Eduardo Soares
committed
Reduce iterations on _where_c
Instead of iterate all rows and cols, iterate only over the matching values.
1 parent a9d3aa7 commit c276ede

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

commpy/channelcoding/convcode.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,13 @@ def conv_encode(message_bits, trellis, termination = 'term', puncture_matrix=Non
561561
def _where_c(inarray, rows, cols, search_value, index_array):
562562

563563
number_found = 0
564-
for i in range(rows):
565-
for j in range(cols):
566-
if inarray[i, j] == search_value:
567-
index_array[number_found, 0] = i
568-
index_array[number_found, 1] = j
569-
number_found += 1
564+
res = np.where(inarray == search_value)
565+
i_s, j_s = res
566+
for i, j in zip(i_s, j_s):
567+
if inarray[i, j] == search_value:
568+
index_array[number_found, 0] = i
569+
index_array[number_found, 1] = j
570+
number_found += 1
570571

571572
return number_found
572573

0 commit comments

Comments
 (0)