Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace max value, group imports by StdExternalCrate #72

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
rust-version: stable
- uses: actions/checkout@master
- name: Check formatting
run: cargo fmt -- --check
run: cargo fmt -- --check --config group_imports=StdExternalCrate
- name: Clippy
run: cargo clippy -- -D warnings -W clippy::pedantic
- name: markdownlint
Expand Down
3 changes: 2 additions & 1 deletion benches/tests/dbscan.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::setup::{make_blobs, CenterConfig};
use criterion::{black_box, Criterion};
use ndarray::{arr2, ArrayView};
use ndarray_rand::rand::{rngs::StdRng, Rng, SeedableRng};
use petal_clustering::{Dbscan, Fit};
use petal_neighbors::distance::Euclidean;

use super::setup::{make_blobs, CenterConfig};

pub fn build(c: &mut Criterion) {
let n = black_box(5000);
let dim = black_box(3);
Expand Down
3 changes: 2 additions & 1 deletion benches/tests/hdbscan.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::setup::{make_blobs, CenterConfig};
use criterion::{black_box, Criterion};
use ndarray::{arr2, ArrayView};
use ndarray_rand::rand::{rngs::StdRng, Rng, SeedableRng};
use petal_clustering::{Fit, HDbscan};

use super::setup::{make_blobs, CenterConfig};

pub fn build(c: &mut Criterion) {
let n = black_box(5000);
let dim = black_box(3);
Expand Down
2 changes: 0 additions & 2 deletions benches/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ pub use dbscan::{
build as dbscan_build, fixed_clusters as dbscan_fixed_clusters,
uniform_clusters as dbscan_uniform_clusters,
};

pub use hdbscan::{
build as hdbscan_build, fixed_clusters as hdbscan_fixed_clusters,
uniform_clusters as hdbscan_uniform_clusters,
};

pub use optics::{
build as optics_build, fixed_clusters as optics_fixed_clusters,
uniform_clusters as optics_uniform_clusters,
Expand Down
3 changes: 2 additions & 1 deletion benches/tests/optics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::setup::{make_blobs, CenterConfig};
use criterion::{black_box, Criterion};
use ndarray::{arr2, ArrayView};
use ndarray_rand::rand::{rngs::StdRng, Rng, SeedableRng};
use petal_clustering::{Fit, Optics};
use petal_neighbors::distance::Euclidean;

use super::setup::{make_blobs, CenterConfig};

pub fn build(c: &mut Criterion) {
let n = black_box(5000);
let dim = black_box(3);
Expand Down
3 changes: 2 additions & 1 deletion examples/hdbscan.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{env, fs::File, process::exit};

use csv::ReaderBuilder;
use ndarray::Array2;
use petal_clustering::{Fit, HDbscan};
use petal_neighbors::distance::Euclidean;
use std::{env, fs::File, process::exit};

fn main() {
let (file, min_cluster_size, min_samples) = parse();
Expand Down
8 changes: 5 additions & 3 deletions src/dbscan.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::ops::{AddAssign, DivAssign};

use ndarray::{ArrayBase, Data, Ix2};
use num_traits::{float::FloatCore, FromPrimitive};
use petal_neighbors::{
Expand All @@ -6,8 +9,6 @@ use petal_neighbors::{
};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::ops::{AddAssign, DivAssign};

use super::Fit;

Expand Down Expand Up @@ -148,10 +149,11 @@ fn expand_cluster(

#[cfg(test)]
mod test {
use super::*;
use maplit::hashmap;
use ndarray::{array, aview2};

use super::*;

#[test]
fn default() {
let dbscan = Dbscan::<f32, Euclidean>::default();
Expand Down
29 changes: 16 additions & 13 deletions src/hdbscan.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use ndarray::{Array1, ArrayBase, ArrayView1, ArrayView2, Data, Ix2};
use num_traits::{float::FloatCore, FromPrimitive};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::fmt::Debug;
use std::mem::MaybeUninit;
use std::ops::{AddAssign, Div, DivAssign, Sub};
use succinct::{BitVecMut, BitVector};

use super::Fit;
use ndarray::{Array1, ArrayBase, ArrayView1, ArrayView2, Data, Ix2};
use num_traits::{float::FloatCore, FromPrimitive};
use petal_neighbors::distance::{Euclidean, Metric};
use petal_neighbors::BallTree;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use succinct::{BitVecMut, BitVector};

use super::Fit;

#[derive(Debug, Deserialize, Serialize)]
pub struct HDbscan<A, M> {
Expand Down Expand Up @@ -831,9 +832,9 @@ struct Candidates<A> {
impl<A: FloatCore> Candidates<A> {
fn new(n: usize) -> Self {
// define max_value as NULL
let neighbors = vec![u32::max_value(); n];
let neighbors = vec![u32::MAX; n];
// define max_value as NULL
let points = vec![u32::max_value(); n];
let points = vec![u32::MAX; n];
// define max_value as infinite far
let distances = vec![A::max_value(); n];
Self {
Expand Down Expand Up @@ -862,13 +863,13 @@ impl<A: FloatCore> Candidates<A> {
}

fn reset(&mut self, i: usize) {
self.points[i] = u32::max_value();
self.neighbors[i] = u32::max_value();
self.points[i] = u32::MAX;
self.neighbors[i] = u32::MAX;
self.distances[i] = A::max_value();
}

fn is_undefined(&self, i: usize) -> bool {
self.points[i] == u32::max_value() || self.neighbors[i] == u32::max_value()
self.points[i] == u32::MAX || self.neighbors[i] == u32::MAX
}
}

Expand Down Expand Up @@ -920,10 +921,11 @@ mod test {

#[test]
fn hdbscan() {
use crate::Fit;
use ndarray::array;
use petal_neighbors::distance::Euclidean;

use crate::Fit;

let data = array![
[1.0, 2.0],
[1.1, 2.2],
Expand Down Expand Up @@ -1147,9 +1149,10 @@ mod test {

#[test]
fn get_stability() {
use ndarray::arr1;
use std::collections::HashMap;

use ndarray::arr1;

let condensed = arr1(&[
(7, 6, 1. / 9., 1),
(7, 4, 1. / 7., 1),
Expand Down
8 changes: 5 additions & 3 deletions src/optics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::HashMap;
use std::ops::{AddAssign, DivAssign};

use ndarray::{Array, ArrayBase, Data, Ix2};
use num_traits::{float::FloatCore, FromPrimitive};
use petal_neighbors::{
Expand All @@ -6,8 +9,6 @@ use petal_neighbors::{
};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::ops::{AddAssign, DivAssign};

use super::Fit;

Expand Down Expand Up @@ -299,10 +300,11 @@ where

#[cfg(test)]
mod test {
use super::*;
use maplit::hashmap;
use ndarray::{array, aview2};

use super::*;

#[test]
fn default() {
let optics = Optics::<f32, Euclidean>::default();
Expand Down
Loading