fix: renames FloatExt to RealNumber
This commit is contained in:
@@ -2,17 +2,17 @@ use std::fmt::Debug;
|
||||
|
||||
use crate::linalg::Matrix;
|
||||
use crate::math::distance::euclidian::*;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BBDTree<T: FloatExt> {
|
||||
pub struct BBDTree<T: RealNumber> {
|
||||
nodes: Vec<BBDTreeNode<T>>,
|
||||
index: Vec<usize>,
|
||||
root: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BBDTreeNode<T: FloatExt> {
|
||||
struct BBDTreeNode<T: RealNumber> {
|
||||
count: usize,
|
||||
index: usize,
|
||||
center: Vec<T>,
|
||||
@@ -23,7 +23,7 @@ struct BBDTreeNode<T: FloatExt> {
|
||||
upper: Option<usize>,
|
||||
}
|
||||
|
||||
impl<T: FloatExt> BBDTreeNode<T> {
|
||||
impl<T: RealNumber> BBDTreeNode<T> {
|
||||
fn new(d: usize) -> BBDTreeNode<T> {
|
||||
BBDTreeNode {
|
||||
count: 0,
|
||||
@@ -38,7 +38,7 @@ impl<T: FloatExt> BBDTreeNode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt> BBDTree<T> {
|
||||
impl<T: RealNumber> BBDTree<T> {
|
||||
pub fn new<M: Matrix<T>>(data: &M) -> BBDTree<T> {
|
||||
let nodes = Vec::new();
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::algorithm::sort::heap_select::HeapSelect;
|
||||
use crate::math::distance::Distance;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
|
||||
/// Implements Cover Tree algorithm
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CoverTree<T, F: FloatExt, D: Distance<T, F>> {
|
||||
pub struct CoverTree<T, F: RealNumber, D: Distance<T, F>> {
|
||||
base: F,
|
||||
max_level: i8,
|
||||
min_level: i8,
|
||||
@@ -42,7 +42,7 @@ pub struct CoverTree<T, F: FloatExt, D: Distance<T, F>> {
|
||||
nodes: Vec<Node<T>>,
|
||||
}
|
||||
|
||||
impl<T: Debug, F: FloatExt, D: Distance<T, F>> CoverTree<T, F, D> {
|
||||
impl<T: Debug, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D> {
|
||||
/// Construct a cover tree.
|
||||
/// * `data` - vector of data points to search for.
|
||||
/// * `distance` - distance metric to use for searching. This function should extend [`Distance`](../algorithm/neighbour/index.html) interface.
|
||||
|
||||
@@ -27,17 +27,17 @@ use std::marker::PhantomData;
|
||||
|
||||
use crate::algorithm::sort::heap_select::HeapSelect;
|
||||
use crate::math::distance::Distance;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
|
||||
/// Implements Linear Search algorithm, see [KNN algorithms](../index.html)
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LinearKNNSearch<T, F: FloatExt, D: Distance<T, F>> {
|
||||
pub struct LinearKNNSearch<T, F: RealNumber, D: Distance<T, F>> {
|
||||
distance: D,
|
||||
data: Vec<T>,
|
||||
f: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<T, F: FloatExt, D: Distance<T, F>> LinearKNNSearch<T, F, D> {
|
||||
impl<T, F: RealNumber, D: Distance<T, F>> LinearKNNSearch<T, F, D> {
|
||||
/// Initializes algorithm.
|
||||
/// * `data` - vector of data points to search for.
|
||||
/// * `distance` - distance metric to use for searching. This function should extend [`Distance`](../algorithm/neighbour/index.html) interface.
|
||||
@@ -86,24 +86,24 @@ impl<T, F: FloatExt, D: Distance<T, F>> LinearKNNSearch<T, F, D> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct KNNPoint<F: FloatExt> {
|
||||
struct KNNPoint<F: RealNumber> {
|
||||
distance: F,
|
||||
index: Option<usize>,
|
||||
}
|
||||
|
||||
impl<F: FloatExt> PartialOrd for KNNPoint<F> {
|
||||
impl<F: RealNumber> PartialOrd for KNNPoint<F> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.distance.partial_cmp(&other.distance)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FloatExt> PartialEq for KNNPoint<F> {
|
||||
impl<F: RealNumber> PartialEq for KNNPoint<F> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.distance == other.distance
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FloatExt> Eq for KNNPoint<F> {}
|
||||
impl<F: RealNumber> Eq for KNNPoint<F> {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
Reference in New Issue
Block a user