Код: Выделить всё
def preprocess_sequence(sequence, word_len):
word_positions = dict()
for i in range(0, len(sequence) - word_len + 1):
word = sequence[i:i+word_len]
if word not in word_positions:
word_positions[word] = [i]
else:
word_positions[word].append(i)
result = list(word_positions.items())
return result
Код: Выделить всё
def preprocess_sequence(sequence, word_len):
word_positions = numba.typed.Dict.empty(
key_type=numba.types.unicode_type,
value_type=numba.types.ListType(numba.types.int64)
)
for i in range(0, len(sequence) - word_len + 1):
word = sequence[i:i+word_len]
if word not in word_positions:
positions = numba.typed.List([i])
word_positions[word] = positions
else:
word_positions[word].append(i)
result = list(word_positions.items())
return result
Код: Выделить всё
File "...\site-packages\numba\core\dispatcher.py", line 468, in _compile_for_args
error_rewrite(e, 'typing')
File "...\site-packages\numba\core\dispatcher.py", line 409, in error_rewrite
raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
List() argument must be iterable
During: resolving callee type: typeref[]
During: typing of call at .\file.py (61)
File "file.py", line 61:
def preprocess_sequence(sequence, word_len):
key_type=numba.types.unicode_type,
value_type=numba.types.ListType(numba.types.int64)
^
During: resolving callee type: type(CPUDispatcher())
During: typing of call at .\file.py (102)
During: resolving callee type: type(CPUDispatcher())
During: typing of call at .\file.py (102)
File "file.py", line 102:
def search_sequence(words, sequence, threshold, scoring_matrix):
word_positions_list = preprocess_sequence(sequence, 3)
Подробнее здесь: https://stackoverflow.com/questions/793 ... e-iterable
Мобильная версия