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

Function convert_to_numpy

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

Source from the content-addressed store, hash-verified

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

Callers 1

set_query_vectorMethod · 0.85

Calls 1

typeFunction · 0.50

Tested by

no test coverage detected