Skip to content
Open
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## 2026-05-01 - Avoid High-Level Tensor Ops in Scalar Reductions
**Learning:** High-level `Tensor` operations like `sub()` and `mul()` trigger intermediate heap allocations for shape and stride metadata. When computing scalar reductions (like MSE, distances, or loss functions), using these operations introduces severe memory overhead inside hot loops. Attempting to use `.min()` length truncation as a safeguard is an anti-pattern as it masks shape mismatch errors.
**Action:** For scalar reductions, assert shape equality (`assert_eq!(a.shape, b.shape)`) and perform a single-pass iteration directly over the underlying borrowed data arrays (`a.data.borrow()`) to eliminate intermediate allocations and safely compute the result.

## 2026-05-28 - O(N) Nearest Neighbor Selection
**Learning:** `KNNClassifier` uses a manual partial selection sort with $O(K \cdot N)$ complexity to find the $K$ nearest neighbors. This is highly inefficient in hot loops, especially when finding neighbors is a frequent operation. Finding $K$ nearest neighbors does not strictly require full sorting of the elements, only partitioning.
**Action:** Replace manual partial sorts with `select_nth_unstable_by` which provides $O(N)$ average time complexity. Use `partial_cmp().unwrap_or(core::cmp::Ordering::Equal)` to safely compare `f64` distances in the presence of `NaN` values without breaking the total ordering contract.
1 change: 0 additions & 1 deletion crates/aether-core/src/aether.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use libm::sqrt;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/governor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

// use libm::fabs;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "alloc")]
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/manifold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use libm::sqrt;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/autograd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#[cfg(not(feature = "std"))]
extern crate alloc;

Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use crate::ml::convergence::{Answer, BettiNumbers, ConvergenceDetector, ResidualAnalyzer};
Expand Down
14 changes: 6 additions & 8 deletions crates/aether-core/src/ml/classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

// use heapless::Vec as HVec;
Expand Down Expand Up @@ -203,13 +202,12 @@ impl<const D: usize> KNNClassifier<D> {
*dist = (self.distance(x, &self.x_train[i]), self.y_train[i]);
}

// Sort by distance (simple bubble sort for small k)
for i in 0..self.k.min(self.n_train) {
for j in (i + 1)..self.n_train {
if distances[j].0 < distances[i].0 {
distances.swap(i, j);
}
}
// Select k nearest neighbors (O(N) on average)
let k_min = self.k.min(self.n_train);
if k_min > 0 {
distances[..self.n_train].select_nth_unstable_by(k_min - 1, |a, b| {
a.0.partial_cmp(&b.0).unwrap_or(core::cmp::Ordering::Equal)
});
}

// Vote among k nearest
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/clustering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use libm::{fabs, sqrt};
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/convergence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use heapless::Vec as HVec;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/convolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use crate::ml::neural::Activation;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use crate::ml::clustering::{KMeans, KMeansResult};
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

#[cfg(feature = "alloc")]
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

// Core modules
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/neural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

#[cfg(feature = "alloc")]
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/regressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

use heapless::Vec as HVec;
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/ml/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#[cfg(feature = "alloc")]
use alloc::rc::Rc;
#[cfg(feature = "alloc")]
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


/// CPU Register Context
///
/// This structure represents the state of the CPU registers. It is used for:
Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


use core::ops::Sub;
use libm::sqrt;

Expand Down
1 change: 0 additions & 1 deletion crates/aether-core/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// ═══════════════════════════════════════════════════════════════════════════════
//


#![allow(dead_code)]

// use libm::fabs;
Expand Down