Skip to content

Commit afff903

Browse files
committed
Rename FloatArray to FloatVector
1 parent 3b4fde8 commit afff903

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

instant-distance-py/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn instant_distance_py(_: Python, m: &PyModule) -> PyResult<()> {
2929

3030
#[pyclass]
3131
struct HnswMap {
32-
inner: instant_distance::HnswMap<FloatArray, MapValue>,
32+
inner: instant_distance::HnswMap<FloatVector, MapValue>,
3333
}
3434

3535
#[pymethods]
@@ -39,7 +39,7 @@ impl HnswMap {
3939
fn build(points: &PyList, values: &PyList, config: &Config) -> PyResult<Self> {
4040
let points = points
4141
.into_iter()
42-
.map(FloatArray::try_from)
42+
.map(FloatVector::try_from)
4343
.collect::<Result<Vec<_>, PyErr>>()?;
4444

4545
let values = values
@@ -55,7 +55,7 @@ impl HnswMap {
5555
#[staticmethod]
5656
fn load(fname: &str) -> PyResult<Self> {
5757
let hnsw_map =
58-
bincode::deserialize_from::<_, instant_distance::HnswMap<FloatArray, MapValue>>(
58+
bincode::deserialize_from::<_, instant_distance::HnswMap<FloatVector, MapValue>>(
5959
BufReader::with_capacity(32 * 1024 * 1024, File::open(fname)?),
6060
)
6161
.map_err(|e| PyValueError::new_err(format!("deserialization error: {e:?}")))?;
@@ -78,7 +78,7 @@ impl HnswMap {
7878
///
7979
/// For best performance, reusing `Search` objects is recommended.
8080
fn search(slf: Py<Self>, point: &PyAny, search: &mut Search, py: Python<'_>) -> PyResult<()> {
81-
let point = FloatArray::try_from(point)?;
81+
let point = FloatVector::try_from(point)?;
8282
let _ = slf.try_borrow(py)?.inner.search(&point, &mut search.inner);
8383
search.cur = Some((HnswType::Map(slf.clone_ref(py)), 0));
8484
Ok(())
@@ -90,7 +90,7 @@ impl HnswMap {
9090
/// For now, this uses a squared Euclidean distance metric.
9191
#[pyclass]
9292
struct Hnsw {
93-
inner: instant_distance::Hnsw<FloatArray>,
93+
inner: instant_distance::Hnsw<FloatVector>,
9494
}
9595

9696
#[pymethods]
@@ -100,7 +100,7 @@ impl Hnsw {
100100
fn build(input: &PyList, config: &Config) -> PyResult<(Self, Vec<u32>)> {
101101
let points = input
102102
.into_iter()
103-
.map(FloatArray::try_from)
103+
.map(FloatVector::try_from)
104104
.collect::<Result<Vec<_>, PyErr>>()?;
105105

106106
let (inner, ids) = instant_distance::Builder::from(config).build_hnsw(points);
@@ -111,7 +111,7 @@ impl Hnsw {
111111
/// Load an index from the given file name
112112
#[staticmethod]
113113
fn load(fname: &str) -> PyResult<Self> {
114-
let hnsw = bincode::deserialize_from::<_, instant_distance::Hnsw<FloatArray>>(
114+
let hnsw = bincode::deserialize_from::<_, instant_distance::Hnsw<FloatVector>>(
115115
BufReader::with_capacity(32 * 1024 * 1024, File::open(fname)?),
116116
)
117117
.map_err(|e| PyValueError::new_err(format!("deserialization error: {e:?}")))?;
@@ -134,7 +134,7 @@ impl Hnsw {
134134
///
135135
/// For best performance, reusing `Search` objects is recommended.
136136
fn search(slf: Py<Self>, point: &PyAny, search: &mut Search, py: Python<'_>) -> PyResult<()> {
137-
let point = FloatArray::try_from(point)?;
137+
let point = FloatVector::try_from(point)?;
138138
let _ = slf.try_borrow(py)?.inner.search(&point, &mut search.inner);
139139
search.cur = Some((HnswType::Hnsw(slf.clone_ref(py)), 0));
140140
Ok(())
@@ -346,21 +346,21 @@ impl Neighbor {
346346
}
347347

348348
#[derive(Clone, Deserialize, Serialize)]
349-
struct FloatArray(AVec<f32>);
349+
struct FloatVector(AVec<f32>);
350350

351-
impl TryFrom<&PyAny> for FloatArray {
351+
impl TryFrom<&PyAny> for FloatVector {
352352
type Error = PyErr;
353353

354354
fn try_from(value: &PyAny) -> Result<Self, Self::Error> {
355-
let mut new = FloatArray(AVec::with_capacity(32, value.len()?));
355+
let mut new = FloatVector(AVec::with_capacity(32, value.len()?));
356356
for val in value.iter()? {
357357
new.0.push(val?.extract()?);
358358
}
359359
Ok(new)
360360
}
361361
}
362362

363-
impl Point for FloatArray {
363+
impl Point for FloatVector {
364364
fn distance(&self, rhs: &Self) -> f32 {
365365
debug_assert_eq!(self.0.len(), rhs.0.len());
366366

0 commit comments

Comments
 (0)