Skip to main content

cuvs/
elements.rs

1use crate::device::DeviceElement;
2
3mod sealed {
4    pub trait Cagra {}
5    pub trait Ivf {}
6    pub trait Pairwise {}
7    pub trait KMeans {}
8
9    impl Cagra for f32 {}
10    impl Cagra for i8 {}
11    impl Cagra for u8 {}
12    impl Ivf for f32 {}
13    impl Ivf for i8 {}
14    impl Ivf for u8 {}
15    impl Pairwise for f32 {}
16    impl Pairwise for f64 {}
17    impl KMeans for f32 {}
18    impl KMeans for f64 {}
19}
20
21pub trait CagraElement: DeviceElement + sealed::Cagra {}
22impl<T: DeviceElement + sealed::Cagra> CagraElement for T {}
23
24pub trait IvfElement: DeviceElement + sealed::Ivf {}
25impl<T: DeviceElement + sealed::Ivf> IvfElement for T {}
26
27pub trait PairwiseElement: DeviceElement + sealed::Pairwise {
28    type Distance: DeviceElement;
29}
30impl PairwiseElement for f32 {
31    type Distance = f32;
32}
33impl PairwiseElement for f64 {
34    type Distance = f64;
35}
36
37pub trait KMeansElement: DeviceElement + sealed::KMeans {}
38impl<T: DeviceElement + sealed::KMeans> KMeansElement for T {}