MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / BinaryVector

Class BinaryVector

bson/binary.py:233–270  ·  view source on GitHub ↗

Vector of numbers along with metadata for binary interoperability. .. versionadded:: 4.10

Source from the content-addressed store, hash-verified

231
232
233class BinaryVector:
234 """Vector of numbers along with metadata for binary interoperability.
235 .. versionadded:: 4.10
236 """
237
238 __slots__ = ("data", "dtype", "padding")
239
240 def __init__(
241 self,
242 data: Union[Sequence[float | int], npt.NDArray[np.number]],
243 dtype: BinaryVectorDtype,
244 padding: int = 0,
245 ):
246 """
247 :param data: Sequence of numbers representing the mathematical vector.
248 :param dtype: The data type stored in binary
249 :param padding: The number of bits in the final byte that are to be ignored
250 when a vector element's size is less than a byte
251 and the length of the vector is not a multiple of 8.
252 (Padding is equivalent to a negative value of `count` in
253 `numpy.unpackbits <https://numpy.org/doc/stable/reference/generated/numpy.unpackbits.html>`_)
254 """
255 self.data = data
256 self.dtype = dtype
257 self.padding = padding
258
259 def __repr__(self) -> str:
260 return f"BinaryVector(dtype={self.dtype}, padding={self.padding}, data={self.data})"
261
262 def __eq__(self, other: Any) -> bool:
263 if not isinstance(other, BinaryVector):
264 return False
265 return (
266 self.dtype == other.dtype and self.padding == other.padding and self.data == other.data
267 )
268
269 def __len__(self) -> int:
270 return len(self.data)
271
272
273class Binary(bytes):

Callers 5

test_vectorMethod · 0.90
as_vectorMethod · 0.85

Calls

no outgoing calls

Tested by 4

test_vectorMethod · 0.72