Skip to content

Commit 52fb0c1

Browse files
committed
fix i32 mistyping
1 parent cbfb91e commit 52fb0c1

20 files changed

Lines changed: 669 additions & 317 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
- name: Stable Build without features
4040
run: cargo build --target ${{ matrix.platform.target }}
4141
- name: Tests
42-
run: cargo test --release --all-features
42+
run: cargo test --package surfface-core --release --all-features

Cargo.lock

Lines changed: 66 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# surfface: Graph Wiring for any vector space
22

3-
(`/ˈsɝː.ffɪs/`) Enabling graph application at scale from any embeddings or from any generic vector space.
3+
(`/ˈsɝː.ffɪs/`) Enabling graph applications at scale from any embeddings or from any generic vector space.
44

55
Inspired by [surface wiring of physical networks](https://www.nature.com/articles/s41586-025-09784-4) and [dark matter structural patterns as spotted by JWST](https://www.nature.com/articles/s41550-025-02763-9).
66

surfface-core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

surfface-core/src/centroid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// surfface-core/src/centroid.rs
1+
//! Basic step of the pipeline: Spot centroids using Kalman Clustering
2+
23
use burn::prelude::*;
34
use kalman_clustering::KalmanClusterer;
45

@@ -20,11 +21,10 @@ impl<B: Backend> CentroidState<B> {
2021
let [c, _] = centroids.dims();
2122

2223
// Compute counts per centroid
23-
let mut counts_vec = vec![0i64; c];
24-
let assignments_data = assignments.to_data();
25-
let assignments_cpu: Vec<i64> = assignments_data.to_vec().unwrap();
24+
let mut counts_vec = vec![0i32; c];
25+
let assignments: Vec<i32> = assignments.to_data().convert::<i32>().to_vec().unwrap();
2626

27-
for &c_id in &assignments_cpu {
27+
for &c_id in &assignments {
2828
if c_id >= 0 && (c_id as usize) < c {
2929
counts_vec[c_id as usize] += 1;
3030
}

surfface-core/src/clustering.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! Based on ArrowSpace's start_clustering_dim_reduce algorithm [file:6]
1010
1111
use crate::centroid::CentroidState;
12+
use crate::reduction::{ImplicitProjection, compute_jl_dimension};
1213
use burn::prelude::*;
1314
use rayon::prelude::*;
1415

@@ -66,62 +67,6 @@ impl ClusteringConfig {
6667
}
6768
}
6869

69-
/// JL Projection matrix (implicit, seed-based) [file:6]
70-
pub struct ImplicitProjection {
71-
pub original_dim: usize,
72-
pub target_dim: usize,
73-
pub seed: u64,
74-
}
75-
76-
impl ImplicitProjection {
77-
pub(crate) fn new(original_dim: usize, target_dim: usize, seed: Option<u64>) -> Self {
78-
Self {
79-
original_dim,
80-
target_dim,
81-
seed: seed.unwrap_or(42),
82-
}
83-
}
84-
85-
/// Project a single row: x (F) -> y (R)
86-
pub(crate) fn project(&self, row: &[f32]) -> Vec<f32> {
87-
use rand::{Rng, SeedableRng};
88-
use rand_chacha::ChaCha8Rng;
89-
90-
assert_eq!(row.len(), self.original_dim);
91-
92-
let scale = 1.0 / (self.target_dim as f32).sqrt();
93-
let mut result = vec![0.0f32; self.target_dim];
94-
95-
// Generate random Gaussian projection on-the-fly (memory efficient)
96-
let mut rng = ChaCha8Rng::seed_from_u64(self.seed);
97-
98-
for j in 0..self.target_dim {
99-
let mut sum = 0.0f32;
100-
for i in 0..self.original_dim {
101-
// Sample from N(0, 1)
102-
let rand_val: f32 = rng.sample(rand_distr::StandardNormal);
103-
sum += row[i] * rand_val;
104-
}
105-
result[j] = sum * scale;
106-
}
107-
108-
result
109-
}
110-
}
111-
112-
/// Compute JL target dimension [file:6]
113-
pub(crate) fn compute_jl_dimension(n_points: usize, original_dim: usize, epsilon: f32) -> usize {
114-
if original_dim < 32 {
115-
return original_dim;
116-
}
117-
118-
let log_n = (n_points as f32).ln();
119-
let eps_sq = epsilon.powi(2);
120-
let jl_bound = (8.0 * log_n / eps_sq).ceil() as usize;
121-
122-
jl_bound.clamp(32, original_dim)
123-
}
124-
12570
/// Output of the clustering stage
12671
pub struct ClusteringOutput<B: Backend> {
12772
pub state: CentroidState<B>,

surfface-core/src/data.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

surfface-core/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
pub mod backend;
1414
pub mod centroid;
1515
pub mod clustering;
16-
pub mod data;
1716
pub mod distance;
1817
pub mod matrix;
1918
pub mod mst;
@@ -33,7 +32,7 @@ static INIT: Once = Once::new();
3332
pub fn init() {
3433
INIT.call_once(|| {
3534
// Read RUST_LOG env variable, default to "info" if not set
36-
let env = env_logger::Env::default().default_filter_or("debug");
35+
let env = env_logger::Env::default().default_filter_or("info");
3736

3837
// don't panic if called multiple times across binaries
3938
let _ = env_logger::Builder::from_env(env)

0 commit comments

Comments
 (0)