@@ -29,7 +29,7 @@ fn instant_distance_py(_: Python, m: &PyModule) -> PyResult<()> {
29
29
30
30
#[ pyclass]
31
31
struct HnswMap {
32
- inner : instant_distance:: HnswMap < FloatArray , MapValue > ,
32
+ inner : instant_distance:: HnswMap < FloatVector , MapValue > ,
33
33
}
34
34
35
35
#[ pymethods]
@@ -39,7 +39,7 @@ impl HnswMap {
39
39
fn build ( points : & PyList , values : & PyList , config : & Config ) -> PyResult < Self > {
40
40
let points = points
41
41
. into_iter ( )
42
- . map ( FloatArray :: try_from)
42
+ . map ( FloatVector :: try_from)
43
43
. collect :: < Result < Vec < _ > , PyErr > > ( ) ?;
44
44
45
45
let values = values
@@ -55,7 +55,7 @@ impl HnswMap {
55
55
#[ staticmethod]
56
56
fn load ( fname : & str ) -> PyResult < Self > {
57
57
let hnsw_map =
58
- bincode:: deserialize_from :: < _ , instant_distance:: HnswMap < FloatArray , MapValue > > (
58
+ bincode:: deserialize_from :: < _ , instant_distance:: HnswMap < FloatVector , MapValue > > (
59
59
BufReader :: with_capacity ( 32 * 1024 * 1024 , File :: open ( fname) ?) ,
60
60
)
61
61
. map_err ( |e| PyValueError :: new_err ( format ! ( "deserialization error: {e:?}" ) ) ) ?;
@@ -78,7 +78,7 @@ impl HnswMap {
78
78
///
79
79
/// For best performance, reusing `Search` objects is recommended.
80
80
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) ?;
82
82
let _ = slf. try_borrow ( py) ?. inner . search ( & point, & mut search. inner ) ;
83
83
search. cur = Some ( ( HnswType :: Map ( slf. clone_ref ( py) ) , 0 ) ) ;
84
84
Ok ( ( ) )
@@ -90,7 +90,7 @@ impl HnswMap {
90
90
/// For now, this uses a squared Euclidean distance metric.
91
91
#[ pyclass]
92
92
struct Hnsw {
93
- inner : instant_distance:: Hnsw < FloatArray > ,
93
+ inner : instant_distance:: Hnsw < FloatVector > ,
94
94
}
95
95
96
96
#[ pymethods]
@@ -100,7 +100,7 @@ impl Hnsw {
100
100
fn build ( input : & PyList , config : & Config ) -> PyResult < ( Self , Vec < u32 > ) > {
101
101
let points = input
102
102
. into_iter ( )
103
- . map ( FloatArray :: try_from)
103
+ . map ( FloatVector :: try_from)
104
104
. collect :: < Result < Vec < _ > , PyErr > > ( ) ?;
105
105
106
106
let ( inner, ids) = instant_distance:: Builder :: from ( config) . build_hnsw ( points) ;
@@ -111,7 +111,7 @@ impl Hnsw {
111
111
/// Load an index from the given file name
112
112
#[ staticmethod]
113
113
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 > > (
115
115
BufReader :: with_capacity ( 32 * 1024 * 1024 , File :: open ( fname) ?) ,
116
116
)
117
117
. map_err ( |e| PyValueError :: new_err ( format ! ( "deserialization error: {e:?}" ) ) ) ?;
@@ -134,7 +134,7 @@ impl Hnsw {
134
134
///
135
135
/// For best performance, reusing `Search` objects is recommended.
136
136
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) ?;
138
138
let _ = slf. try_borrow ( py) ?. inner . search ( & point, & mut search. inner ) ;
139
139
search. cur = Some ( ( HnswType :: Hnsw ( slf. clone_ref ( py) ) , 0 ) ) ;
140
140
Ok ( ( ) )
@@ -346,21 +346,21 @@ impl Neighbor {
346
346
}
347
347
348
348
#[ derive( Clone , Deserialize , Serialize ) ]
349
- struct FloatArray ( AVec < f32 > ) ;
349
+ struct FloatVector ( AVec < f32 > ) ;
350
350
351
- impl TryFrom < & PyAny > for FloatArray {
351
+ impl TryFrom < & PyAny > for FloatVector {
352
352
type Error = PyErr ;
353
353
354
354
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 ( ) ?) ) ;
356
356
for val in value. iter ( ) ? {
357
357
new. 0 . push ( val?. extract ( ) ?) ;
358
358
}
359
359
Ok ( new)
360
360
}
361
361
}
362
362
363
- impl Point for FloatArray {
363
+ impl Point for FloatVector {
364
364
fn distance ( & self , rhs : & Self ) -> f32 {
365
365
debug_assert_eq ! ( self . 0 . len( ) , rhs. 0 . len( ) ) ;
366
366
0 commit comments