Refactor while True loops (#5952)

This commit is contained in:
Dmitry Pigasin authored and GitHub committed 2021-06-02 18:51:32 +03:00
1 parent 09c2cbf5aa
commit ac4dd6cda7
2 files changed
+10 -12

No files matched your search

@@ -13,12 +13,11 @@ def read_ark_file(file_name: str) -> dict:
def read_key(input_file: IO[Any]) -> str:
"""Read a identifier of utterance matrix"""
key = ''
while True:
char = input_file.read(1).decode()
while char not in ('', ' '):
key += char
char = input_file.read(1).decode()
if char in ('', ' '):
break
else:
key += char
return key
@@ -44,11 +43,11 @@ def read_ark_file(file_name: str) -> dict:
utterances = {}
with open(file_name, 'rb') as input_file:
while True:
key = read_key(input_file)
if not key:
break
key = read_key(input_file)
while key:
utterances[key] = read_matrix(input_file)
key = read_key(input_file)
return utterances
@@ -36,7 +36,7 @@ def infer_data(data: dict, exec_net: ExecutableNetwork, input_blobs: list, outpu
slice_begin = 0
slice_end = batch_size
while True:
while slice_begin < matrix_shape[0]:
vectors = {blob_name: data[blob_name][slice_begin:slice_end] for blob_name in input_blobs}
num_of_vectors = next(iter(vectors.values())).shape[0]
@@ -56,8 +56,7 @@ def infer_data(data: dict, exec_net: ExecutableNetwork, input_blobs: list, outpu
slice_begin += batch_size
slice_end += batch_size
if slice_begin >= matrix_shape[0]:
return result
return result
def compare_with_reference(result: np.ndarray, reference: np.ndarray):