MCPcopy Create free account
hub / github.com/alibaba/zvec / convert_to_numpy

Function convert_to_numpy

python/zvec/executor/query_executor.py:43–57  ·  view source on GitHub ↗
(vec: Union[list, np.ndarray], dtype: np.dtype)

Source from the content-addressed store, hash-verified

41
42
43def convert_to_numpy(vec: Union[list, np.ndarray], dtype: np.dtype) -> np.ndarray:
44 if isinstance(vec, np.ndarray):
45 if vec.dtype == dtype and vec.ndim == 1:
46 return vec
47 return np.asarray(vec, dtype=dtype).flatten()
48
49 try:
50 arr = np.asarray(vec, dtype=dtype)
51 if arr.ndim != 1:
52 arr = arr.flatten()
53 return arr
54 except (ValueError, TypeError) as e:
55 raise TypeError(
56 f"Cannot convert input to 1D numpy array with dtype={dtype}: {type(vec)}"
57 ) from e
58
59
60class QueryContext:

Callers 1

set_query_vectorMethod · 0.85

Calls 1

typeFunction · 0.50

Tested by

no test coverage detected