pub struct BinaryVector {
pub data: Vec<u8>,
pub dims: usize,
pub norm: f32,
}Expand description
Unstable: binary quantization format and struct layout are under active design.
Binary quantized vector with packed bit storage.
Fields§
§data: Vec<u8>Unstable: packed bit data; bit layout may change with format revision.
dims: usizeUnstable: number of original dimensions.
norm: f32Unstable: L2 norm of the original float vector; field may be removed.
Implementations§
Source§impl BinaryVector
impl BinaryVector
Sourcepub fn from_f32(vector: &[f32]) -> Self
pub fn from_f32(vector: &[f32]) -> Self
Unstable: quantization API; threshold default may change.
Values >= threshold map to 1, values < threshold map to 0. Default threshold is 0.0 (sign bit).
Sourcepub fn from_f32_with_threshold(vector: &[f32], threshold: f32) -> Self
pub fn from_f32_with_threshold(vector: &[f32], threshold: f32) -> Self
Unstable: custom-threshold variant; may be merged into a config struct.
Sourcepub fn to_f32(&self) -> Vec<f32>
pub fn to_f32(&self) -> Vec<f32>
Unstable: dequantize to float32; output semantics may change.
Binary quantization is lossy: 1 -> +1.0, 0 -> -1.0.
Sourcepub fn hamming_distance(&self, other: &BinaryVector) -> u32
pub fn hamming_distance(&self, other: &BinaryVector) -> u32
Unstable: Hamming dispatch; delegates to NEON or scalar based on runtime detection.
Returns the number of differing bits (dimensions with different signs).
Sourcepub fn cosine_distance_approx(&self, other: &BinaryVector) -> f32
pub fn cosine_distance_approx(&self, other: &BinaryVector) -> f32
Unstable: approximation formula may be revised; do not use in latency-sensitive production paths.
The relationship between Hamming distance and angular distance:
cos_approx = 1.0 - 2.0 * hamming / dims
cosine_distance_approx = 2.0 * hamming / dims
Sourcepub fn cosine_similarity_approx(&self, other: &BinaryVector) -> f32
pub fn cosine_similarity_approx(&self, other: &BinaryVector) -> f32
Unstable: approximation formula may be revised; complement of cosine_distance_approx.
Trait Implementations§
Source§impl Clone for BinaryVector
impl Clone for BinaryVector
Source§fn clone(&self) -> BinaryVector
fn clone(&self) -> BinaryVector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more