[mypy] Add/fix type annotations for similarity search in machine learning (#4088)

* [mypy] Add/fix type annotations for similarity search in machine learning

* fix annotation

* fix annotation (Union)

* isort
This commit is contained in:
Steve Kim 2021-01-22 13:40:21 +09:00 committed by GitHub
parent 7d26ba7075
commit d594f4556c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ returns a list containing two data for each vector:
2. distance between the vector and the nearest vector (float)
"""
import math
from typing import List, Union
import numpy as np
@ -30,7 +31,9 @@ def euclidean(input_a: np.ndarray, input_b: np.ndarray) -> float:
return math.sqrt(sum(pow(a - b, 2) for a, b in zip(input_a, input_b)))
def similarity_search(dataset: np.ndarray, value_array: np.ndarray) -> list:
def similarity_search(
dataset: np.ndarray, value_array: np.ndarray
) -> List[List[Union[List[float], float]]]:
"""
:param dataset: Set containing the vectors. Should be ndarray.
:param value_array: vector/vectors we want to know the nearest vector from dataset.