diff --git a/Cargo.toml b/Cargo.toml index b37398b..6bfc932 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["ann", "knn", "nearest-neighbors"] categories = ["algorithms", "data-structures"] [dependencies] -num-traits = "0.2.14" +num-traits = { version = "0.2.14", default-features = false } [dev-dependencies] criterion = "0.3.5" diff --git a/src/coords.rs b/src/coords.rs index cee89ee..7d31513 100644 --- a/src/coords.rs +++ b/src/coords.rs @@ -1,5 +1,6 @@ //! [Coordinate spaces](https://en.wikipedia.org/wiki/Cartesian_coordinate_system). +use alloc::vec::Vec; use crate::distance::Value; /// A coordinate space. diff --git a/src/cos.rs b/src/cos.rs index 97b6416..d35b77e 100644 --- a/src/cos.rs +++ b/src/cos.rs @@ -6,7 +6,7 @@ use crate::distance::{Distance, Metric, Proximity, Value}; use num_traits::real::Real; use num_traits::{one, zero}; -use std::cmp::Ordering; +use core::cmp::Ordering; /// Compute the [cosine *similarity*] between two points. /// @@ -436,7 +436,7 @@ macro_rules! impl_distance { #[inline] fn try_from(value: $f) -> Result { - if value >= 0.0 && value <= std::$f::consts::PI { + if value >= 0.0 && value <= core::$f::consts::PI { Ok(Self(value.cos())) } else { Err(InvalidAngleError) @@ -492,7 +492,7 @@ impl_distance!(f64); mod tests { use super::*; - use std::f64::consts::{FRAC_PI_2, FRAC_PI_4, PI, SQRT_2}; + use core::f64::consts::{FRAC_PI_2, FRAC_PI_4, PI, SQRT_2}; #[test] fn test_cosine() { diff --git a/src/euclid.rs b/src/euclid.rs index 2268a0c..5dc32ae 100644 --- a/src/euclid.rs +++ b/src/euclid.rs @@ -4,9 +4,10 @@ use crate::coords::Coordinates; use crate::distance::{Distance, Metric, Proximity, Value}; use crate::lp::Minkowski; +use num_traits::real::Real; use num_traits::zero; -use std::cmp::Ordering; +use core::cmp::Ordering; /// A point in Euclidean space. /// diff --git a/src/exhaustive.rs b/src/exhaustive.rs index 7b63ef7..d9eafbf 100644 --- a/src/exhaustive.rs +++ b/src/exhaustive.rs @@ -2,6 +2,7 @@ use crate::distance::Proximity; use crate::knn::{ExactNeighbors, NearestNeighbors, Neighborhood}; +use alloc::vec::Vec; /// A [`NearestNeighbors`] implementation that does exhaustive search. #[derive(Clone, Debug)] @@ -48,7 +49,7 @@ impl FromIterator for ExhaustiveSearch { /// An iterator that moves values out of an exhaustive index. #[derive(Debug)] -pub struct IntoIter(std::vec::IntoIter); +pub struct IntoIter(alloc::vec::IntoIter); impl Iterator for IntoIter { type Item = T; @@ -69,7 +70,7 @@ impl IntoIterator for ExhaustiveSearch { /// An iterator over the values in an exhaustive index. #[derive(Debug)] -pub struct Iter<'a, T>(std::slice::Iter<'a, T>); +pub struct Iter<'a, T>(core::slice::Iter<'a, T>); impl<'a, T> Iterator for Iter<'a, T> { type Item = &'a T; diff --git a/src/kd.rs b/src/kd.rs index d9bed6a..738491c 100644 --- a/src/kd.rs +++ b/src/kd.rs @@ -6,6 +6,10 @@ use crate::lp::Minkowski; use crate::knn::{ExactNeighbors, NearestNeighbors, Neighborhood}; use crate::util::Ordered; +use alloc::vec; +use alloc::vec::Vec; +use alloc::boxed::Box; + use num_traits::Signed; /// A node in a k-d tree. @@ -467,7 +471,7 @@ impl FromIterator for FlatKdTree { /// An iterator that moves values out of a flat k-d tree. #[derive(Debug)] -pub struct FlatIntoIter(std::vec::IntoIter>); +pub struct FlatIntoIter(vec::IntoIter>); impl Iterator for FlatIntoIter { type Item = T; @@ -488,7 +492,7 @@ impl IntoIterator for FlatKdTree { /// An iterator over the values in a flat k-d tree. #[derive(Debug)] -pub struct FlatIter<'a, T>(std::slice::Iter<'a, FlatKdNode>); +pub struct FlatIter<'a, T>(core::slice::Iter<'a, FlatKdNode>); impl<'a, T> Iterator for FlatIter<'a, T> { type Item = &'a T; diff --git a/src/knn.rs b/src/knn.rs index 444c9a7..231f6ba 100644 --- a/src/knn.rs +++ b/src/knn.rs @@ -1,5 +1,6 @@ //! [Nearest neighbor search](https://en.wikipedia.org/wiki/Nearest_neighbor_search) interfaces. +use alloc::vec::Vec; use crate::distance::{Distance, Proximity}; /// A nearest neighbor. diff --git a/src/lib.rs b/src/lib.rs index 29d351a..4ad4431 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,10 @@ //! [`k_nearest_within()`]: knn::NearestNeighbors#method.k_nearest_within //! [`ExactNeighbors`]: knn::ExactNeighbors -#![warn(rust_2018_idioms)] +#![no_std] + +#[macro_use] +extern crate alloc; pub mod chebyshev; pub mod coords; diff --git a/src/util.rs b/src/util.rs index 6a969de..662fbc0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,6 +1,6 @@ //! Internal utilities. -use std::cmp::Ordering; +use core::cmp::Ordering; /// A wrapper that converts a partial ordering into a total one by panicking. #[derive(Clone, Copy, Debug, PartialOrd)] diff --git a/src/vp.rs b/src/vp.rs index a761cbf..f6e4e2a 100644 --- a/src/vp.rs +++ b/src/vp.rs @@ -4,9 +4,13 @@ use crate::distance::{Distance, DistanceValue, Metric, Proximity}; use crate::knn::{ExactNeighbors, NearestNeighbors, Neighborhood}; use crate::util::Ordered; +use alloc::boxed::Box; +use alloc::vec; +use alloc::vec::Vec; + use num_traits::zero; -use std::fmt::{self, Debug, Formatter}; +use core::fmt::{self, Debug, Formatter}; /// A node in a VP tree. #[derive(Debug)] @@ -527,7 +531,7 @@ impl FromIterator for FlatVpTree { } /// An iterator that moves values out of a flat VP tree. -pub struct FlatIntoIter(std::vec::IntoIter>); +pub struct FlatIntoIter(vec::IntoIter>); impl Debug for FlatIntoIter where @@ -559,7 +563,7 @@ impl IntoIterator for FlatVpTree { } /// An iterator over the values in a flat VP tree. -pub struct FlatIter<'a, T: Proximity>(std::slice::Iter<'a, FlatVpNode>); +pub struct FlatIter<'a, T: Proximity>(core::slice::Iter<'a, FlatVpNode>); impl<'a, T> Debug for FlatIter<'a, T> where