-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add f16 support, example and docs to show usage with half crate
- Loading branch information
Showing
9 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[cfg(feature = "half")] | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
use half::f16; | ||
use kiddo::{KdTree, SquaredEuclidean}; | ||
use num_traits::real::Real; | ||
|
||
// build and serialize small tree for ArchivedKdTree doctests | ||
let mut tree: KdTree<f16, 3> = KdTree::new(); | ||
tree.add( | ||
&[f16::from_f32(1.0), f16::from_f32(2.0), f16::from_f32(5.0)], | ||
100, | ||
); | ||
tree.add( | ||
&[f16::from_f32(2.0), f16::from_f32(3.0), f16::from_f32(6.0)], | ||
101, | ||
); | ||
|
||
let nearest = tree.nearest_one::<SquaredEuclidean>(&[ | ||
f16::from_f32(1.0), | ||
f16::from_f32(2.0), | ||
f16::from_f32(5.1), | ||
]); | ||
|
||
println!("Nearest: {:?}", &nearest); | ||
|
||
assert!((nearest.distance - f16::from_f32(0.01)).abs() < f16::EPSILON); | ||
assert_eq!(nearest.item, 100); | ||
Ok(()) | ||
} | ||
|
||
#[cfg(not(feature = "half"))] | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
println!("Activate the 'half' feature to run this example properly"); | ||
println!("Try this: cargo run --example half --features=half"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters